Advertisement
vmars316

benghaziGame

Feb 29th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2.  
  3.     "use strict";
  4.      // http://www.w3schools.com/js/tryit.asp?filename=tryjs_object_function
  5.     var red = 153;
  6.     var green = 45;
  7.     var blue = 45;
  8.     var truth01Trips = 0; // max 6
  9.     var truth02Trips = 0; // max 4
  10.     var truth03Trips = 0; // max 7
  11.     var truth04Trips = 0; // max 5
  12.     var compound, manufacturer, thrower;
  13.     var truth01, truth02, truth03, truth04;
  14.     var lies01, lies02, lies03, lies04;
  15.     var totalScore, totalShots, goodHits, oops, Cursor, cursorPoint, cursorPos;    
  16.     var getXx , getYy, countLogs =1;
  17. //  var mousePos = [20,570];
  18.     var mousePos1stTimeIn = 1;
  19.     // imports
  20.     var CommandEnum = com.dgsprb.quick.CommandEnum;
  21.     var Quick = com.dgsprb.quick.Quick;
  22.     var GameObject = com.dgsprb.quick.GameObject;
  23.     var Rect = com.dgsprb.quick.Rect;
  24.     var ImageFactory = com.dgsprb.quick.ImageFactory;
  25.     var Scene = com.dgsprb.quick.Scene;
  26.     var Text = com.dgsprb.quick.Text;  
  27.  
  28.     // static
  29.     function main() {
  30.         Quick.setAutoScale(false);
  31.         Quick.setName("Lies&Cowpies");
  32.         Quick.init(function () { return new FirstScene() });
  33.     }
  34.  
  35.     var Background = (function () {
  36.  
  37.         function Background() {
  38.             GameObject.call(this);
  39.             this.setColor("rgb(" + red + "," + green + "," + blue + ")");
  40.             this.setWidth(Quick.getWidth());
  41.             this.setHeight(Quick.getHeight());
  42.         };
  43.         Background.prototype = Object.create(GameObject.prototype);
  44.  
  45.         return Background;
  46.     })();
  47.  
  48.     var Cursor = (function () {
  49.         function Cursor() {
  50.             GameObject.call(this);
  51.             this.addTag("pointerSprite");
  52.             this.controller = Quick.getController();
  53.             this.setBoundary(new Rect(0, 600, Quick.getWidth(), 30)); // a method of Sprite,set Boundary
  54.             this.pointer = Quick.getPointer();
  55.             this.setImageId("pointerSprite");
  56.             this.setEssential();           
  57.             this.setBottom(600); this.setLeft(50); this.setTop(570);    
  58.         };
  59.         Cursor.prototype = Object.create(GameObject.prototype);
  60.        
  61.         Cursor.prototype.fire = function () {
  62.             var spark = new Spark(); // create a brand new spark to be thrown
  63.             var scene = this.getScene(); // ask for the scene the avatar is
  64.             scene.add(spark); // add the spark to the same scene I am
  65.             if (spark) {spark.setX(this.getX()) };     
  66.             spark.setSpeedY(1);
  67.         };
  68.        
  69.         Cursor.prototype.update = function () {
  70.                 var mousePos = this.pointer.getPosition();
  71.                 alert("mousePos ");
  72.                 this.setPosition(mousePos);
  73.             if (this.controller.keyPush(CommandEnum.UP) || this.controller.keyPush(CommandEnum.A))
  74.                {  
  75.                 this.fire(); // call the method we defined above
  76.                 };
  77.         Cursor.prototype.offBoundary = function (gameObject) {
  78.             this.setCenterY(585);
  79.               };   
  80. //
  81. function simulateClick() {
  82.   var event = new MouseEvent('click', {
  83.     'view': window,
  84.     'bubbles': true,
  85.     'cancelable': true
  86.   });
  87. };
  88. //           
  89.         };           
  90.         return Cursor;
  91.     })();
  92.  
  93.     var Spark = (function () { // Spark class namespace
  94.     function Spark() { // Spark class constructor method
  95.         GameObject.call(this); // call the constructor from the superclass
  96.         this.setImageId("sparkSprite"); // setImageId,a method inherited from Sprite
  97.         this.pointer = Quick.getPointer(); // pointer is a member property of Spark
  98.         this.setBoundary(new Rect(0, 600, Quick.getWidth(), 30)); // a method of Sprite,set
  99.         this.setSolid(); // a method of GameObject , so Spark can collide with other solid objects    
  100.         this.setBottom(600); this.setLeft(50); this.setTop(570);    
  101.         this.controller = Quick.getController();
  102.     };
  103.     Spark.prototype = Object.create(GameObject.prototype);
  104.     Spark.prototype.onCollision = function (gameObject) {        
  105.     var collision = this.getCollision(gameObject); // get direction at collision
  106.           if (gameObject.hasTag("restartBtn")) { // returns true if object contains given tag
  107.               Quick.play("pongSound"); // calls a static method from Quick class
  108.             };
  109.           if (gameObject.hasTag("pauseBtn")) { // returns true if object contains given tag
  110.               Quick.play("pongSound"); // calls a static method from Quick class
  111.             };
  112.           if (gameObject.hasTag("playBtn")) { // returns true if object contains given tag
  113.               Quick.play("pongSound"); // calls a static method from Quick class
  114.             };
  115.           if (gameObject.hasTag("quitBtn")) { // returns true if object contains given tag
  116.               Quick.play("pongSound"); // calls a static method from Quick class
  117.             };
  118.     };
  119.                 return Spark; // finally publishes the class to the outer scope
  120. })();
  121.  
  122.     var RestartBtn = (function () { // RestartBtn class namespace
  123.     function RestartBtn() { // RestartBtn class constructor method
  124.         GameObject.call(this); // call the constructor from the superclass
  125.         this.setImageId("restartBtn"); // setImageId, a method inherited from Sprite
  126.         this.pointer = Quick.getPointer(); // pointer is a member property of RestartBtn
  127.         this.setBoundary(new Rect(100, 570, 100, 30)); // a method of Sprite, to set this boundaries
  128.         this.setSolid();
  129.         this.setEssential();  
  130.         this.setBottom(600); this.setLeft(100) ;  this.setTop(572);
  131.         }  
  132.         RestartBtn.prototype = Object.create(GameObject.prototype);
  133.             return RestartBtn; // finally publishes the class to the outer scope
  134. })();  
  135.     var PauseBtn = (function () { // PauseBtn class namespace
  136.     function PauseBtn() { // PauseBtn class constructor method
  137.         GameObject.call(this); // call the constructor from the superclass
  138.         this.setImageId("pauseBtn"); // setImageId, a method inherited from Sprite
  139.         this.pointer = Quick.getPointer(); // pointer is a member property of PauseBtn
  140.         this.setBoundary(new Rect(210, 570, 100, 30)); // a method of Sprite, to set the boundaries of PauseBtn
  141.         this.setSolid();
  142.         this.setEssential();  // a method of GameObject, sets the PauseBtn object as essential to its Scene,  that if this object expires,  the scene will expire too.  
  143.         this.setBottom(600); this.setLeft(210);  this.setTop(572);
  144.         }  
  145.         PauseBtn.prototype = Object.create(GameObject.prototype);
  146.             return PauseBtn; // finally publishes the class to the outer scope
  147. })();  
  148.     var PlayBtn = (function () { // PlayBtn class namespace
  149.     function PlayBtn() { // PlayBtn class constructor method
  150.         GameObject.call(this); // call the constructor from the superclass
  151.         this.setImageId("playBtn"); // setImageId, a method inherited from Sprite
  152.         this.pointer = Quick.getPointer(); // pointer is a member property of PlayBtn
  153.         // getPointer is a static method of Quick
  154.         this.setBoundary(new Rect(320, 570, 100, 30)); // a method of Sprite, to set the boundaries of PlayBtn
  155.         this.setSolid();
  156.         this.setEssential();  // a method of GameObject, sets the PlayBtn object as essential to its Scene,  that if this object expires,  the scene will expire too.  
  157.         this.setBottom(600); this.setLeft(320);  this.setTop(572);
  158.         }  
  159.         PlayBtn.prototype = Object.create(GameObject.prototype);
  160.             return PlayBtn; // finally publishes the class to the outer scope
  161. })();  
  162.     var QuitBtn = (function () { // QuitBtn class namespace
  163.     function QuitBtn() { // QuitBtn class constructor method
  164.         GameObject.call(this); // call the constructor from the superclass
  165.         this.setImageId("quitBtn"); // setImageId, a method inherited from Sprite
  166.         this.pointer = Quick.getPointer(); // pointer is a member property of QuitBtn
  167.         // getPointer is a static method of Quick
  168.         this.setBoundary(new Rect(430, 570, 100, 30)); // a method of Sprite, to set the boundaries of QuitBtn
  169.         this.setSolid();
  170.         this.setEssential();  // a method of GameObject, sets the QuitBtn object as essential to its Scene,  that if this object expires,  the scene will expire too.  
  171.         this.setBottom(600); this.setLeft(430);  this.setTop(572);
  172.         }  
  173.         QuitBtn.prototype = Object.create(GameObject.prototype);
  174.             return QuitBtn; // finally publishes the class to the outer scope
  175. })();  
  176.  
  177.     var Compound = (function () { // Compound class namespace
  178.     function Compound() { // Compound class constructor method
  179.         GameObject.call(this); // call the constructor from the superclass
  180.         this.setImageId("bgCompound"); // setImageId, a method inherited from Sprite
  181.         this.pointer = Quick.getPointer(); // pointer is a member property of Compound
  182.         // getPointer is a static method of Quick
  183.         this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight())); // a method of Sprite, to set the boundaries of Compound
  184.         this.setEssential();  // a method of GameObject, sets the Compound object as essential to its Scene,  that if this object expires,  the scene will expire too.  
  185.         this.setBottom(Quick.getHeight() - this.getHeight());
  186.         this.setLeft(0);  this.setTop(378);
  187.         }  
  188.         Compound.prototype = Object.create(GameObject.prototype);
  189.             return Compound; // finally publishes the class to the outer scope
  190. })();  
  191.     var Manufacturer = (function () { // Manufacturer class namespace
  192.     function Manufacturer() { // Manufacturer class constructor method
  193.         GameObject.call(this); // call the constructor from the superclass
  194.         this.setImageId("manufacturer"); //setImageId, a method inherited from Sprite
  195.         this.pointer = Quick.getPointer(); // pointer is a member property of Manufacturer
  196.         // getPointer is a static method of Quick
  197.         this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight())); // a method of Sprite, to set the boundaries of Manufacturer
  198.         this.setEssential();  // a method of GameObject, sets the Manufacturer object as essential to its Scene,  that if this object expires,  the scene will expire too.  
  199.         this.setBottom(Quick.getHeight() - this.getHeight());
  200.         this.setLeft(618);  this.setTop(468);
  201.         }  
  202.         Manufacturer.prototype = Object.create(GameObject.prototype); // this says the Ball class
  203.             return Manufacturer; // finally publishes the class to the outer scope
  204. })();  
  205. //
  206.     var Ball = (function () { // Ball class namespace
  207.     function Ball() { // Ball class constructor method
  208.         GameObject.call(this); // call the constructor from the superclass
  209.         this.setImageId("cowpieSprite"); // setImageId,a method inherited from Sprite
  210.         this.pointer = Quick.getPointer(); // pointer is a member property of Ball
  211.         // getPointer is a static method of Quick, whose public members are accessible without creating an instance of that class.
  212.         this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight())); // a method of Sprite, to set the boundaries of Ball
  213.         this.setSolid(); // a method of GameObject , so Ball can collide with other solid objects - correct!
  214.         this.setBottom(Quick.getHeight() - this.getHeight());
  215.         this.setTop(500);
  216. //      this.controller = Quick.getController();
  217.     };
  218.     Ball.prototype = Object.create(GameObject.prototype); // this says the Ball class inherits from GameObject
  219.     // override - this comment means the following method overrides (rewrites) the method with the same name defined in the super class (in this case, GameObject)
  220.     Ball.prototype.onCollision = function (gameObject) { // still no instance of Ball here, just class method definition - no instance of this class is created until "new Ball()" is issued
  221.         var collision = this.getCollision(gameObject); // get direction at collision
  222.           if (gameObject.hasTag("lies02")) { // returns true if object contains given tag
  223.               lies02.setLeft(0); lies02.setVisible(false); lies02.setSpeedX(0);
  224.               truth02.setVisible(true); truth02.setSpeedX(4); goodHits += 1;
  225.              
  226.               Quick.play("pingSound"); // calls a static method from Quick class
  227.             };
  228.     };
  229.                 return Ball; // finally publishes the class to the outer scope
  230. })();
  231.  
  232.     var Truth = (function () {
  233.         function Truth() {
  234.             GameObject.call(this);
  235.             this.setImageId("");
  236.             this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight()));
  237. //          this.setEssential();
  238.             this.setSolid();
  239.             this.setLeft(0);
  240.             this.setTop(120);
  241.             this.setSpeedX(4);
  242.         };
  243.         Truth.prototype = Object.create(GameObject.prototype);
  244.  
  245.         Truth.prototype.offBoundary = function (gameObject) {
  246.            if (this.hasTag("truth02")) {
  247.                 truth02Trips += 1; // increment by 1
  248.                 if(truth02Trips > 2) { truth02Trips = 0;
  249.                     truth02.setLeft(0); truth02.setVisible(false); truth02.setSpeedX(0);       
  250.                 };
  251.                 Quick.play("pingSound"); // calls a static method from Quick class
  252.                 if(truth02.getVisible() ) { this.bounceX(); // for the horizontal axis
  253.                 this.setImage(ImageFactory.mirror(this.getImage())); // flip image horiz
  254.                 };
  255.                 if(!truth02.getVisible() ) {
  256.                 lies02.setLeft(0); lies02.setVisible(true); lies02.setSpeedX(4); //  
  257.                 };
  258.                 };
  259.         };         
  260.         return Truth;
  261.     })();
  262. // 
  263.     var Lies = (function () {
  264.  
  265.         function Lies() {
  266.             GameObject.call(this);
  267.             this.setImageId("");
  268.             this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight()));
  269. //          this.setEssential();
  270.             this.setSolid();
  271.             this.setLeft(0);
  272.             this.setTop(120);
  273.             this.setSpeedX(5);
  274.         };
  275.         Lies.prototype = Object.create(GameObject.prototype);
  276.  
  277.         Lies.prototype.offBoundary = function (gameObject) {
  278.             this.bounceX(); // for the horizontal axis
  279.             this.setImage(ImageFactory.mirror(this.getImage()));
  280. //            alert("Lies.prototype.offBoundary");
  281.         };
  282.         return Lies;
  283.  
  284.     })();  
  285. //
  286.     var FirstScene = (function () {
  287.  
  288.         function FirstScene() {
  289.             Scene.call(this);
  290.             this.add(new Background());
  291.             var compound = new Compound();
  292.             this.add(compound);        
  293.             var cursorPoint = new Cursor();
  294.             this.add(cursorPoint);
  295.             var spark = new Spark();
  296. //          this.add(spark);
  297.             var restartBtn = new RestartBtn();
  298.             this.add(restartBtn);
  299.             restartBtn.addTag("restartBtn");
  300.             var pauseBtn = new PauseBtn();
  301.             this.add(pauseBtn);
  302.             pauseBtn.addTag("pauseBtn");
  303.             var playBtn = new PlayBtn();
  304.             this.add(playBtn);
  305.             playBtn.addTag("playBtn");
  306.             var quitBtn = new QuitBtn();
  307.             this.add(quitBtn);
  308.             quitBtn.addTag("quitBtn");         
  309.             manufacturer = new Manufacturer();
  310.             this.add(manufacturer);        
  311.             var ball = new Ball();
  312.             thrower = new Thrower();
  313.             this.add(thrower);
  314.             truth01 = new Truth();
  315.             this.add(truth01);
  316.             truth01.addTag("truth01");
  317.             truth01.setImageId("truth01Sprite");
  318.             truth01.setLeft(0);
  319.             truth01.setTop(50);
  320.             truth01.setSpeedX(4);          
  321.             lies01 = new Lies();
  322.             this.add(lies01);
  323.             lies01.addTag("lies01");
  324.             lies01.setImageId("lies01Sprite");
  325.             lies01.setVisible(false);
  326.             lies01.setLeft(0)    //  (-64);
  327.             lies01.setTop(50);
  328.             lies01.setSpeedX(0);
  329.             truth02 = new Truth();
  330.             this.add(truth02);
  331.             truth02.addTag("truth02");
  332.             truth02.setImageId("truth02Sprite");
  333.             truth02.setLeft(0);
  334.             truth02.setTop(120);
  335.             truth02.setSpeedX(6);          
  336.             lies02 = new Lies();
  337.             this.add(lies02);
  338.             lies02.addTag("lies02");
  339.             lies02.setImageId("lies02Sprite");
  340.             lies02.setVisible(false);
  341.             lies02.setLeft(0)    //  (-64);
  342.             lies02.setTop(120);
  343.             lies02.setSpeedX(0);
  344.             truth03 = new Truth();
  345.             this.add(truth03);
  346.             truth03.addTag("truth03");
  347.             truth03.setImageId("truth03Sprite");
  348.             truth03.setLeft(0);
  349.             truth03.setTop(190);
  350.             truth03.setSpeedX(3);          
  351.             lies03 = new Lies();
  352.             this.add(lies03);
  353.             lies03.addTag("lies03");
  354.             lies03.setImageId("lies03Sprite");
  355.             lies03.setVisible(false);
  356.             lies03.setLeft(0)    //  (-64);
  357.             lies03.setTop(190);
  358.             lies03.setSpeedX(0);
  359.             truth04 = new Truth();
  360.             this.add(truth04);
  361.             truth04.addTag("truth04");
  362.             truth04.setImageId("truth04Sprite");
  363.             truth04.setLeft(0);
  364.             truth04.setTop(260);
  365.             truth04.setSpeedX(5);          
  366.             lies04 = new Lies();
  367.             this.add(lies04);
  368.             lies04.addTag("lies04");
  369.             lies04.setImageId("lies04Sprite");
  370.             lies04.setVisible(false);
  371.             lies04.setLeft(0)    //  (-64);
  372.             lies04.setTop(260);
  373.             lies04.setSpeedX(0);
  374.         };
  375.         FirstScene.prototype = Object.create(Scene.prototype);
  376.  
  377.         // override
  378.         FirstScene.prototype.getNext = function () {
  379.             return new FirstScene();
  380.         };
  381.  
  382.         return FirstScene;
  383.  
  384.     })();
  385.  
  386.     var Thrower = (function () {
  387.         function Thrower() {
  388.             GameObject.call(this);
  389.             this.addTag("thrower");
  390.             this.controller = Quick.getController();
  391.             this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight()));
  392.             this.pointer = Quick.getPointer();
  393.             this.setImageId("throwerSprite");
  394.             this.setEssential();           
  395.             this.setCenterX(Quick.getWidth() / 2);
  396.             this.setBottom(Quick.getHeight() - this.getHeight());
  397.             this.setTop(506);    
  398.         };
  399.         Thrower.prototype = Object.create(GameObject.prototype);
  400.        
  401.         Thrower.prototype.fire = function () {
  402.             var ball = new Ball(); // create a brand new ball to be thrown
  403.             var scene = this.getScene(); // ask for the scene the avatar is
  404.             scene.add(ball); // add the ball to the same scene I am
  405.             if (ball) {ball.setX(this.getX()) }; // within your Thrower update method      
  406. //          if(ball ) { this.ball.setCenterX(this.getCenterX()) } ;
  407.             ball.setSpeedY(-9);
  408.         };
  409.        
  410.         Thrower.prototype.update = function () {
  411.             if (this.controller.keyDown(CommandEnum.LEFT) && this.getLeft() > 0) {
  412.                 this.moveX(-8);
  413.                 }
  414.             if (this.controller.keyDown(CommandEnum.RIGHT) && this.getRight() < Quick.getWidth()) {
  415.                 this.moveX(8);
  416.                 }              
  417.             if (this.controller.keyPush(CommandEnum.UP) || this.controller.keyPush(CommandEnum.A))
  418.                { totalShots += 1;  
  419.                 this.fire(); // call the method we defined above
  420.                 }
  421.                 }
  422.         Thrower.prototype.offBoundary = function (gameObject) {
  423.             this.setCenterX(Quick.getWidth() / 2);
  424.               };               
  425.        
  426.         return Thrower;
  427.     })();
  428.  
  429.     main();
  430.  
  431. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement