Advertisement
vmars316

BenghaziGame.js

Mar 18th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2. // programName: BenghaziGame.js here:  http://pastebin.com/xLcM9G4n    
  3. //                          .html here: http://pastebin.com/jPaFjcWk         Quick.js here:  http://pastebin.com/Gzqef5fu
  4. /*  Quick (top dog)
  5.          Point (inherits from Quick)
  6.              Rect (inherits from Point)
  7.                  Sprite (inherits from Rect)
  8.                      GameObject (inherits from Sprite)
  9. Still: Where does Pointer inherit from ?                     ck  ~paddle-main-NOW.js  for score headings
  10. */                   
  11.     "use strict";
  12.      // http://www.w3schools.com/js/tryit.asp?filename=tryjs_object_function
  13.     var red = 153;
  14.     var green = 45;
  15.     var blue = 45;
  16.     var truth01Trips = 0;   var truth01SVspeed ; var lies01Hits = 0;  
  17.           // max trips 6  SaVe speeds
  18.     var truth02Trips = 0;   var truth02SVspeed ; var lies02Hits = 0;     // max trips 4
  19.     var truth03Trips = 0;   var truth03SVspeed ; var lies03Hits = 0;     // max trips 7
  20.     var truth04Trips = 0;   var truth04SVspeed ; var lies04Hits = 0;    // max trips 5
  21.     var lies01STspeed, lies02STspeed, lies03STspeed, lies04STspeed ;  //  STart speeds
  22.     var lies01SVspeed, lies02SVspeed, lies03SVspeed, lies04SVspeed ;  //  save Speeds
  23.     var allPaused = false;
  24.     var compound, manufacturer, thrower;
  25.     var truth01, truth02, truth03, truth04;
  26.     var lies01, lies02, lies03, lies04;
  27.     var totalScore = 0; var oopsScore = 0; var goodHits = 0; var totalShots = 0;
  28.     var buttonsCenter = 0;  
  29.     var Cursor, cursorPoint, cursorPos;    
  30.     var getXx , getYy, countLogs =1;
  31. //  var mousePos = [20,570];
  32.     var mousePos1stTimeIn = 1;
  33.     // imports
  34.     var CommandEnum = com.dgsprb.quick.CommandEnum;
  35.     var Quick = com.dgsprb.quick.Quick;
  36.     var GameObject = com.dgsprb.quick.GameObject;
  37.     var Rect = com.dgsprb.quick.Rect;
  38.     var ImageFactory = com.dgsprb.quick.ImageFactory;
  39.     var Scene = com.dgsprb.quick.Scene;
  40.     var Text = com.dgsprb.quick.Text;  
  41.     var Point = com.dgsprb.quick.Point;
  42.  
  43.     // static
  44.     function main() {
  45.         Quick.setAutoScale(false);
  46.         Quick.setKeepAspect(true);
  47.         Quick.setName("Lies&Cowpies");
  48.         Quick.init(function () { return new FirstScene() });
  49.     }
  50.  
  51.     var Background = (function () {
  52.  
  53.         function Background() {
  54.             GameObject.call(this);
  55.             this.setColor("rgb(" + red + "," + green + "," + blue + ")");
  56.             this.setWidth(Quick.getWidth());
  57.             this.setHeight(Quick.getHeight());
  58.         };
  59.         Background.prototype = Object.create(GameObject.prototype);
  60.  
  61.         return Background;
  62.     })();
  63.  
  64.     var PlayBtn = (function () { // PlayBtn class namespace
  65.     function PlayBtn() { // PlayBtn class constructor method
  66.         GameObject.call(this); // call the constructor from the superclass
  67.         this.setImageId("playBtn"); // setImageId, a method inherited from Sprite
  68. //        this.pointer = Quick.getPointer(); // pointer is a member property of PlayBtn
  69.         // getPointer is a static method of Quick
  70.         this.setBoundary(new Rect(Quick.getCenterX() +10, 570, 100, 30)); // a method of Sprite, to set the boundaries of PlayBtn
  71.         this.setSolid();
  72.         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.  
  73.         this.setBottom(600); this.setLeft(Quick.getCenterX() +10);  this.setTop(572);  // this.setLeft(320);
  74.         buttonsCenter = (Quick.getCenterX() +10);
  75. //      alert('buttonsCenter = ' + buttonsCenter);
  76.         }  
  77.         PlayBtn.prototype = Object.create(GameObject.prototype);
  78.             return PlayBtn; // finally publishes the class to the outer scope
  79. })();  
  80.  
  81.     var RestartBtn = (function () { // RestartBtn class namespace
  82.     function RestartBtn() { // RestartBtn class constructor method
  83.         GameObject.call(this); // call the constructor from the superclass
  84.         this.setImageId("restartBtn"); // setImageId, a method inherited from Sprite
  85. //        this.pointer = Quick.getPointer(); // pointer is a member property of RestartBtn
  86.         this.setBoundary(new Rect(buttonsCenter -250, 570, 100, 30)); // a method of Sprite, to set this boundaries
  87.         this.setSolid();
  88.         this.setEssential();  
  89.         this.setBottom(600); this.setLeft(buttonsCenter -250) ;  this.setTop(572);
  90.         }  
  91.         RestartBtn.prototype = Object.create(GameObject.prototype);
  92.             return RestartBtn; // finally publishes the class to the outer scope
  93. })();  
  94.     var PauseBtn = (function () { // PauseBtn class namespace
  95.     function PauseBtn() { // PauseBtn class constructor method
  96.         GameObject.call(this); // call the constructor from the superclass
  97.         this.setImageId("pauseBtn"); // setImageId, a method inherited from Sprite
  98. //        this.pointer = Quick.getPointer(); // pointer is a member property of PauseBtn
  99.         this.setBoundary(new Rect(buttonsCenter -125, 570, 100, 30)); // a method of Sprite, to set the boundaries of PauseBtn
  100.         this.setSolid();
  101.         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.  
  102.         this.setBottom(600); this.setLeft(buttonsCenter -125);  this.setTop(572);
  103.         }  
  104.         PauseBtn.prototype = Object.create(GameObject.prototype);
  105.             return PauseBtn; // finally publishes the class to the outer scope
  106. })();  
  107.     var QuitBtn = (function () { // QuitBtn class namespace
  108.     function QuitBtn() { // QuitBtn class constructor method
  109.         GameObject.call(this); // call the constructor from the superclass
  110.         this.setImageId("quitBtn"); // setImageId, a method inherited from Sprite
  111. //        this.pointer = Quick.getPointer(); // pointer is a member property of QuitBtn
  112.         // getPointer is a static method of Quick
  113.         this.setBoundary(new Rect(buttonsCenter +125, 570, 100, 30)); // a method of Sprite, to set the boundaries of QuitBtn
  114.         this.setSolid();
  115.         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.  
  116.         this.setBottom(600); this.setLeft(buttonsCenter + 125);  this.setTop(572);
  117.         }  
  118.         QuitBtn.prototype = Object.create(GameObject.prototype);
  119.             return QuitBtn; // finally publishes the class to the outer scope
  120. })();  
  121.  
  122.     var Compound = (function () { // Compound class namespace
  123.     function Compound() { // Compound class constructor method
  124.         GameObject.call(this); // call the constructor from the superclass
  125.         this.setImageId("bgCompound"); // setImageId, a method inherited from Sprite
  126.  //       this.pointer = Quick.getPointer(); // pointer is a member property of Compound
  127.         // getPointer is a static method of Quick
  128.         this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight())); // a method of Sprite, to set the boundaries of Compound
  129.         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.  
  130.         this.setBottom(Quick.getHeight() - this.getHeight());
  131.         this.setLeft(0);  this.setTop(378);
  132.         }  
  133.         Compound.prototype = Object.create(GameObject.prototype);
  134.             return Compound; // finally publishes the class to the outer scope
  135. })();  
  136.     var Manufacturer = (function () { // Manufacturer class namespace
  137.     function Manufacturer() { // Manufacturer class constructor method
  138.         GameObject.call(this); // call the constructor from the superclass
  139.         this.setImageId("manufacturer"); //setImageId, a method inherited from Sprite
  140. //        this.pointer = Quick.getPointer(); // pointer is a member property of Manufacturer
  141.         // getPointer is a static method of Quick
  142.         this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight())); // a method of Sprite, to set the boundaries of Manufacturer
  143.         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.  
  144.         this.setBottom(Quick.getHeight() - this.getHeight());
  145.         this.setLeft(618);  this.setTop(468);
  146.         }  
  147.         Manufacturer.prototype = Object.create(GameObject.prototype); // this says the Ball class
  148.             return Manufacturer; // finally publishes the class to the outer scope
  149. })();  
  150. //
  151.     var Ball = (function () { // Ball class namespace
  152.     function Ball() { // Ball class constructor method
  153.         GameObject.call(this); // call the constructor from the superclass
  154.         this.setImageId("cowpieSprite"); // setImageId,a method inherited from Sprite
  155. //        this.pointer = Quick.getPointer(); // pointer is a member property of Ball
  156.         // getPointer is a static method of Quick, whose public members are accessible without creating an instance of that class.
  157.         this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight())); // a method of Sprite, to set the boundaries of Ball
  158.         this.setSolid(); // a method of GameObject , so Ball can collide with other solid objects - correct!
  159.         this.setBottom(Quick.getHeight() - this.getHeight());
  160.         this.setTop(500);
  161. //      this.controller = Quick.getController();
  162.     };
  163.     Ball.prototype = Object.create(GameObject.prototype); // this says the Ball class inherits from GameObject
  164.     // override - this comment means the following method overrides (rewrites) the method with the same name defined in the super class (in this case, GameObject)
  165.     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
  166.         this.expire() ;  // remove ball from screne to prevent multi hits per initial colllision
  167.         var collision = this.getCollision(gameObject); // get direction at collision
  168. //
  169.             if (gameObject.hasTag("truth01")) { // returns true if object contains given tag
  170.                 oopsScore ++ ; totalScore = ((goodHits * 4) - (oopsScore * 2));
  171.                 truth01.setWidth(32); truth01.setHeight(32);
  172.             };
  173.         if (gameObject.hasTag("lies01")) { // returns true if object contains given tag
  174.               lies01.setLeft(0); lies01.setVisible(false); lies01.setSpeedX(0);
  175.               truth01.setVisible(true); truth01.setSpeedX(4);
  176.               goodHits ++ ; totalScore = ((goodHits * 4) - (oopsScore * 2));  // each goodHit = 3 points , each
  177.               lies01Hits ++;
  178.              if (lies01Hits % 3 === 0) {
  179.                   Quick.play('obamaVideo'); // calls a static method from Quick class
  180.                 }  
  181.                  else {  Quick.play("cowMoo"); // calls a static method from Quick class
  182.                 };           
  183.         };
  184. //
  185.         if (gameObject.hasTag("truth02")) { // returns true if object contains given tag
  186.                 oopsScore ++ ; totalScore = ((goodHits * 4) - (oopsScore * 2));
  187.                 truth02.setWidth(32); truth02.setHeight(32);
  188.                 Quick.play("oops"); // calls a static method from Quick class
  189.             };
  190.         if (gameObject.hasTag("lies02")) { // returns true if object contains given tag
  191.               lies02.setLeft(0); lies02.setVisible(false); lies02.setSpeedX(0);
  192.               truth02.setVisible(true); truth02.setSpeedX(4);
  193.               goodHits ++ ; totalScore = ((goodHits * 4) - (oopsScore * 2));  // each goodHit = 3 points , each
  194.               lies02Hits ++;
  195.              if (lies02Hits % 3 === 0) {
  196.                   Quick.play('Hillary-WhatDiff'); // calls a static method from Quick class
  197.                 }  
  198.                  else {  Quick.play("cowMoo");
  199.                 };           
  200.             };
  201. //
  202.             if (gameObject.hasTag("truth03")) { // returns true if object contains given tag
  203.                 oopsScore ++ ; totalScore = ((goodHits * 4) - (oopsScore * 2));
  204.                 truth03.setWidth(32); truth03.setHeight(32);
  205.                 Quick.play("oops"); // calls a static method from Quick class
  206.             };
  207.         if (gameObject.hasTag("lies03")) { // returns true if object contains given tag
  208.               lies03.setLeft(0); lies03.setVisible(false); lies03.setSpeedX(0);
  209.               truth03.setVisible(true); truth03.setSpeedX(4);
  210.               goodHits ++ ; totalScore = ((goodHits * 4) - (oopsScore * 2));  // each goodHit = 3 points , each
  211.               lies03Hits ++;
  212.              if (lies03Hits % 3 === 0) {
  213.                   Quick.play('eHolderVideo'); // calls a static method from Quick class
  214.                 }  
  215.                  else {  Quick.play("cowMoo");
  216.                 };           
  217.         };
  218. //
  219.             if (gameObject.hasTag("truth04")) { // returns true if object contains given tag
  220.                 oopsScore ++ ; totalScore = ((goodHits * 4) - (oopsScore * 2));
  221.                 truth04.setWidth(32); truth04.setHeight(32);
  222.                 Quick.play("oops"); // calls a static method from Quick class
  223.             };
  224.         if (gameObject.hasTag("lies04")) { // returns true if object contains given tag
  225.               lies04.setLeft(0); lies04.setVisible(false); lies04.setSpeedX(0);
  226.               truth04.setVisible(true); truth04.setSpeedX(4);
  227.               goodHits ++ ; totalScore = ((goodHits * 4) - (oopsScore * 2));  // each goodHit = 3 points , each
  228.               lies04Hits ++;
  229.              if (lies04Hits % 3 === 0) {
  230.                   Quick.play('sRiceVideo'); // calls a static method from Quick class
  231.                 }  
  232.                  else {  Quick.play("cowMoo");
  233.                 };           
  234.         };
  235. //         
  236.         updateScores();
  237.     };
  238.                 return Ball; // finally publishes the class to the outer scope
  239. })();
  240.  
  241.     function updateScores () {
  242.         document.getElementById('totalScore').innerHTML = totalScore;
  243.         document.getElementById('oopsScore').innerHTML = oopsScore;
  244.         document.getElementById('goodHits').innerHTML = goodHits;
  245.         document.getElementById('totalShots').innerHTML = totalShots;
  246.         if(goodHits === 100) { Quick.play('cheering'); };
  247.     }
  248. //
  249. /* window.addEventListener('resize', resizeCanvas, false);
  250. function resizeCanvas () {
  251. var myCanvas = document.getElementById('canvas');
  252. // canvasDiv = canvasDiv.align = 'center';
  253. // myCanvas.width = document.documentElement.innerWidth;
  254. myCanvas.width = 800; // document.documentElement.clientWidth;
  255. // myCanvas.height = document.documentElement.clientHeight;
  256. myCanvas.height = 600; // document.documentElement.innerHeight;
  257.       Quick.setAutoScale(false);
  258.       Quick.setKeepAspect(true);
  259. }   */
  260. // 
  261. window.addEventListener("resize", function(){
  262.     location.reload();  //  867x661  1027x773   if (i % 3 == 0) {};  
  263.         Quick.setAutoScale(false);
  264.         Quick.setKeepAspect(true);
  265. //      truth02.setWidth(64); truth02.setHeight(64);
  266. /*
  267. var myCanvas = document.getElementById(“canvas”);
  268. myCanvas.width = 800;
  269. myCanvas.height = 600;  */
  270.         } );
  271.  
  272.     var Truth = (function () {
  273.         function Truth() {
  274.             GameObject.call(this);
  275.             this.setImageId("");
  276.             this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight()));
  277. //          this.setEssential();
  278.             this.setSolid();
  279.             this.setLeft(0);
  280.             this.setTop(120);
  281.             this.setSpeedX(4);
  282.         };
  283.         Truth.prototype = Object.create(GameObject.prototype);
  284.  
  285.         Truth.prototype.offBoundary = function (gameObject) {
  286.            if (this.hasTag("truth02")) {
  287.                 truth02Trips += 1; // increment by 1
  288.                 if(truth02Trips > 2) { truth02Trips = 0;
  289.                     truth02.setLeft(0); truth02.setVisible(false); truth02.setSpeedX(0);       
  290.                 };
  291. //                Quick.play("oops"); // calls a static method from Quick class
  292.                 if(truth02.getVisible() ) { this.bounceX(); // for the horizontal axis
  293.                 this.setImage(ImageFactory.mirror(this.getImage())); // flip image horiz
  294.                 };
  295.                 if(!truth02.getVisible() ) {   // if not visible
  296.                 lies02.setLeft(0); lies02.setVisible(true); lies02.setSpeedX(4); //  
  297.                 };
  298.                 };
  299. //
  300.            if (this.hasTag("truth01")) {
  301.                 truth01Trips += 1; // increment by 1
  302.                 if(truth01Trips > 2) { truth01Trips = 0;
  303.                     truth01.setLeft(0); truth01.setVisible(false); truth01.setSpeedX(0);       
  304.                 };
  305. //                Quick.play("obamaVideo.ogg"); // calls a static method from Quick class
  306.                 if(truth01.getVisible() ) { this.bounceX(); // for the horizontal axis
  307.                 this.setImage(ImageFactory.mirror(this.getImage())); // flip image horiz
  308.                 };
  309.                 if(!truth01.getVisible() ) {
  310.                 lies01.setLeft(0); lies01.setVisible(true); lies01.setSpeedX(4); //  
  311.                 };
  312.                 };
  313. //             
  314.            if (this.hasTag("truth03")) {
  315.                 truth03Trips += 1; // increment by 1
  316.                 if(truth03Trips > 2) { truth03Trips = 0;
  317.                     truth03.setLeft(0); truth03.setVisible(false); truth03.setSpeedX(0);       
  318.                 };
  319. //                Quick.play("oops"); // calls a static method from Quick class
  320.                 if(truth03.getVisible() ) { this.bounceX(); // for the horizontal axis
  321.                 this.setImage(ImageFactory.mirror(this.getImage())); // flip image horiz
  322.                 };
  323.                 if(!truth03.getVisible() ) {
  324.                 lies03.setLeft(0); lies03.setVisible(true); lies03.setSpeedX(4); //  
  325.                 };
  326.                 };
  327. //
  328.            if (this.hasTag("truth04")) {
  329.                 truth04Trips += 1; // increment by 1
  330.                 if(truth04Trips > 2) { truth04Trips = 0;
  331.                     truth04.setLeft(0); truth04.setVisible(false); truth04.setSpeedX(0);       
  332.                 };
  333. //                Quick.play("oops"); // calls a static method from Quick class
  334.                 if(truth04.getVisible() ) { this.bounceX(); // for the horizontal axis
  335.                 this.setImage(ImageFactory.mirror(this.getImage())); // flip image horiz
  336.                 };
  337.                 if(!truth04.getVisible() ) {
  338.                 lies04.setLeft(0); lies04.setVisible(true); lies04.setSpeedX(4); //  
  339.                 };
  340.                 };
  341. //
  342.         };         
  343.         return Truth;
  344.     })();
  345. // 
  346.     var Lies = (function () {
  347.  
  348.         function Lies() {
  349.             GameObject.call(this);
  350.             this.setImageId("");
  351.             this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight()));
  352. //          this.setEssential();
  353.             this.setSolid();
  354.             this.setLeft(0);
  355.             this.setTop(120);
  356.             this.setSpeedX(5);
  357.         };
  358.         Lies.prototype = Object.create(GameObject.prototype);
  359.  
  360.         Lies.prototype.offBoundary = function (gameObject) {
  361.             this.bounceX(); // for the horizontal axis
  362.             this.setImage(ImageFactory.mirror(this.getImage()));
  363. //            alert("Lies.prototype.offBoundary");
  364.         };
  365.         return Lies;
  366.  
  367.     })();  
  368. //
  369.     var FirstScene = (function () {
  370.  
  371.         function FirstScene() {
  372.             Scene.call(this);
  373.             this.add(new Background());
  374.             var compound = new Compound();
  375.             this.add(compound);        
  376.             var playBtn = new PlayBtn();
  377.             this.add(playBtn);
  378.             playBtn.addTag("playBtn");
  379.             var restartBtn = new RestartBtn();
  380.             this.add(restartBtn);
  381.             restartBtn.addTag("restartBtn");
  382.             var pauseBtn = new PauseBtn();
  383.             this.add(pauseBtn);
  384.             pauseBtn.addTag("pauseBtn");
  385.             var quitBtn = new QuitBtn();
  386.             this.add(quitBtn);
  387.             quitBtn.addTag("quitBtn");         
  388.             manufacturer = new Manufacturer();
  389.             this.add(manufacturer);        
  390.             var ball = new Ball();
  391.             truth01 = new Truth();
  392.             this.add(truth01);
  393.             truth01.addTag("truth01");
  394.             truth01.setImageId("truth01Sprite");
  395.             truth01.setLeft(0);
  396.             truth01.setTop(0);
  397.             truth01.setSpeedX(4);          
  398.             lies01 = new Lies();
  399.             this.add(lies01);
  400.             lies01.addTag("lies01");
  401.             lies01.setImageId("lies01Sprite");
  402.             lies01.setVisible(false);
  403.             lies01.setLeft(0)    //  (-64);
  404.             lies01.setTop(0);
  405.             lies01.setSpeedX(0);
  406.             truth02 = new Truth();
  407.             this.add(truth02);
  408.             truth02.addTag("truth02");
  409.             truth02.setImageId("truth02Sprite");
  410.             truth02.setLeft(0);
  411.             truth02.setTop(70);
  412.             truth02.setVisible(false);
  413.             truth02.setSpeedX(0);          
  414.             lies02 = new Lies();
  415.             this.add(lies02);
  416.             lies02.addTag("lies02");
  417.             lies02.setImageId("lies02Sprite");
  418.             lies02.setLeft(0)    //  (-64);
  419.             lies02.setTop(70);
  420.             lies02.setSpeedX(6);
  421.             truth03 = new Truth();
  422.             this.add(truth03);
  423.             truth03.addTag("truth03");
  424.             truth03.setImageId("truth03Sprite");
  425.             truth03.setLeft(0);
  426.             truth03.setTop(140);
  427.             truth03.setSpeedX(3);          
  428.             lies03 = new Lies();
  429.             this.add(lies03);
  430.             lies03.addTag("lies03");
  431.             lies03.setImageId("lies03Sprite");
  432.             lies03.setVisible(false);
  433.             lies03.setLeft(0)    //  (-64);
  434.             lies03.setTop(140);
  435.             lies03.setSpeedX(0);
  436.             truth04 = new Truth();
  437.             this.add(truth04);
  438.             truth04.addTag("truth04");
  439.             truth04.setImageId("truth04Sprite");
  440.             truth04.setLeft(-64);
  441.             truth04.setTop(210);
  442.             truth04.setSpeedX(5);          
  443.             lies04 = new Lies();
  444.             this.add(lies04);
  445.             lies04.addTag("lies04");
  446.             lies04.setImageId("lies04Sprite");
  447.             lies04.setVisible(false);
  448.             lies04.setLeft(-64)    //  (-64);
  449.             lies04.setTop(210);
  450.             lies04.setSpeedX(0);
  451.             thrower = new Thrower();
  452.             this.add(thrower);
  453.             var cursorPoint = new Cursor();
  454.             this.add(cursorPoint);
  455.             var spark = new Spark();
  456.             this.add(spark);
  457.             alert( '<--- Arrow = move Left .\n' + '---> Arrow = move Right .\n' + ' Up Arrow = Throw Cowpie \n ' + '\n Best Screen size: Width = >840 , Height = > 640 .\n' +
  458.                      '\n Cheering after every 100 goodHits . \n' +
  459.                      '\n Click  anywhere on screen  to  ACTIVATE BUTTONS  .\n');
  460.             Quick.play("battleFire"); // calls a static method from Quick class
  461.         };
  462.         FirstScene.prototype = Object.create(Scene.prototype);
  463.  
  464.         // override
  465.         FirstScene.prototype.getNext = function () {
  466.             return new FirstScene();
  467.         };
  468.  
  469.         return FirstScene;
  470.  
  471.     })();
  472. //
  473.  
  474.     var Cursor = (function () {
  475.         function Cursor() {
  476.             GameObject.call(this);
  477.             this.addTag("pointerSprite");
  478.             this.controller = Quick.getController();
  479.             this.setBoundary(new Rect(0, 600, Quick.getWidth(), 30)); // a method of Sprite,set Boundary
  480.             this.pointer = Quick.getPointer();
  481.             this.setImageId("pointerSprite");
  482.             this.setSolid();
  483.             this.setEssential();           
  484.             this.setBottom(600); this.setLeft(50); this.setTop(572);    
  485.         };
  486.         Cursor.prototype = Object.create(GameObject.prototype);
  487.        
  488.         Cursor.prototype.fire = function () {
  489.             var spark = new Spark(); // create a brand new spark to be thrown
  490.             var scene = this.getScene(); // ask for the scene the avatar is
  491.             scene.add(spark); // add the spark to the same scene I am
  492.             if (spark) {spark.setX(this.getX()) };     
  493.             spark.setSpeedY(10);
  494.         };
  495.        
  496.         Cursor.prototype.update = function () {
  497.  
  498.             if (this.pointer.getPush()) {   // getpush is a method of Pointer as in Mouse pointer
  499.                 this.fire(); // call the  Cursor.prototype.fire  method we defined above
  500.                 var position = this.pointer.getPosition();
  501.             };
  502.             var mousePos = this.pointer.getPosition();
  503.             this.setPosition(mousePos);
  504.             }
  505.         Cursor.prototype.offBoundary = function (gameObject) {
  506. //          alert('Cursor.prototype.offBoundary');
  507. //          this.setCenterY(587);
  508.         };  
  509. //      this.setCenterY(587);
  510.        
  511.         return Cursor;
  512.     })();
  513.  
  514.     var Spark = (function () { // Spark class namespace
  515.     function Spark() { // Spark class constructor method
  516.         GameObject.call(this); // call the constructor from the superclass
  517.         this.setImageId("sparkSprite"); // setImageId,a method inherited from Sprite
  518. //        this.pointer = Quick.getPointer(); // pointer is a member property of Spark
  519.         this.setBoundary(new Rect(0, 600, Quick.getWidth(), 30)); // a method of Sprite,set
  520.         this.setSolid(); // a method of GameObject , so Spark can collide with other solid objects    
  521.         this.setBottom(600); this.setLeft(50); this.setTop(578);    
  522.         this.controller = Quick.getController();
  523.     };
  524.         Spark.prototype = Object.create(GameObject.prototype);
  525.         Spark.prototype.onCollision = function (gameObject) {        
  526.     var collision = this.getCollision(gameObject); // get direction at collision
  527.  
  528.         if (gameObject.hasTag("restartBtn")) { // returns true if object contains given tag
  529.               Quick.play("closeDoor"); // calls a static method from Quick class
  530.                totalScore = 0; oopsScore = 0; goodHits = 0; totalShots = 0;
  531.                updateScores();
  532.         }
  533.         if (gameObject.hasTag("pauseBtn")) { // returns true if object contains given tag
  534.               Quick.play("pling"); // calls a static method from Quick class
  535.               if(!allPaused) {
  536.                 truth01SVspeed = truth01.getSpeedX();    truth01.setSpeedX(0);  //              this.setSpeedX(5);
  537.                 lies01SVspeed = lies01.getSpeedX();    lies01.setSpeedX(0);  //                     this.setSpeedX(5);
  538.                 truth02SVspeed = truth02.getSpeedX();    truth02.setSpeedX(0);  //              this.setSpeedX(5);
  539.                 lies02SVspeed = lies02.getSpeedX();    lies02.setSpeedX(0);  //                     this.setSpeedX(5);
  540.                 truth03SVspeed = truth03.getSpeedX();    truth03.setSpeedX(0);  //              this.setSpeedX(5);
  541.                 lies03SVspeed = lies03.getSpeedX();    lies03.setSpeedX(0);  //                     this.setSpeedX(5);
  542.                 truth04SVspeed = truth04.getSpeedX();    truth04.setSpeedX(0);  //              this.setSpeedX(5);
  543.                 lies04SVspeed = lies04.getSpeedX();    lies04.setSpeedX(0);  //                     this.setSpeedX(5);
  544.                 allPaused = true;
  545.               }
  546.               else  { alert('You are already paused , try Play  .');
  547.               }
  548.             };  //  gameObject.hasTag
  549. //  
  550.           if (gameObject.hasTag("playBtn")) { // returns true if object contains given tag
  551.               Quick.play("pling"); // calls a static method from Quick class
  552.               if(allPaused) {
  553.                 allPaused = false;  
  554.                 truth01.setSpeedX(truth01SVspeed);
  555.                 lies01.setSpeedX(lies01SVspeed);
  556.                 truth02.setSpeedX(truth02SVspeed); truth02.setWidth(64); truth02.setHeight(64);
  557.                 lies02.setSpeedX(lies02SVspeed);
  558.                 truth03.setSpeedX(truth03SVspeed);
  559.                 lies03.setSpeedX(lies03SVspeed);
  560.                 truth04.setSpeedX(truth04SVspeed);
  561.                 lies04.setSpeedX(lies04SVspeed);
  562.                 }  
  563.             };
  564.           if (gameObject.hasTag("quitBtn")) { // returns true if object contains given tag
  565.               Quick.play("byebye"); // calls a static method from Quick class
  566.               window.location = 'https://github.com/dgsprb/quick/wiki';
  567.             };
  568.     };
  569.                 return Spark; // finally publishes the class to the outer scope
  570. })();
  571.  
  572. //
  573.     var Thrower = (function () {
  574.         function Thrower() {
  575.             GameObject.call(this);
  576.             this.addTag("thrower");
  577.             this.controller = Quick.getController();
  578.             this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight()));
  579.             this.pointer = Quick.getPointer();
  580.             this.setImageId("throwerSprite");
  581.             this.setEssential();           
  582.             this.setCenterX(Quick.getWidth() / 2);
  583.             this.setBottom(Quick.getHeight() - this.getHeight());
  584.             this.setTop(506);    
  585.         };
  586.         Thrower.prototype = Object.create(GameObject.prototype);
  587.        
  588.         Thrower.prototype.fire = function () {
  589.             var ball = new Ball(); // create a brand new ball to be thrown
  590.             var scene = this.getScene(); // ask for the scene the avatar is
  591.             scene.add(ball); // add the ball to the same scene I am
  592.             if (ball) {ball.setX(this.getX()) }; // within your Thrower update method      
  593. //                totalShots ++ ;      
  594.             updateScores();
  595. //          if(ball ) { this.ball.setCenterX(this.getCenterX()) } ;
  596.             ball.setSpeedY(-9);
  597.         };
  598.        
  599.         Thrower.prototype.update = function () {
  600.             if (this.controller.keyDown(CommandEnum.LEFT) && this.getLeft() > 0) {
  601.                 this.moveX(-8);
  602.                 }
  603.             if (this.controller.keyDown(CommandEnum.RIGHT) && this.getRight() < Quick.getWidth()) {
  604.                 this.moveX(8);
  605.                 }              
  606.             if (this.controller.keyPush(CommandEnum.UP) || this.controller.keyPush(CommandEnum.A))
  607.                { totalShots += 1;  
  608.                 this.fire(); // call the method we defined above
  609.                 }
  610.                 }
  611.         Thrower.prototype.offBoundary = function (gameObject) {
  612.             this.setCenterX(Quick.getWidth() / 2);
  613.               };               
  614.        
  615.         return Thrower;
  616.     })();
  617.  
  618.     main();
  619.  
  620. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement