Advertisement
vmars316

BenghaziGame-kirupa.js

Mar 24th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2. // programName: BenghaziGame-kirupa.js here:  http://pastebin.com/edit/Qc04CEGt    
  3. //                          .html here: pastebin.com/BfBE7NUW       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. //
  250.  window.addEventListener('resize', resizeCanvas, false);
  251. function resizeCanvas () {
  252. var myCanvas = document.getElementById('canvas');
  253. // canvasDiv = canvasDiv.align = 'center';
  254. // myCanvas.width = document.documentElement.innerWidth;  // .inner* = Black Screen
  255.  myCanvas.width =  document.documentElement.clientWidth;   //  .client* = bad canvas align
  256.  myCanvas.height = document.documentElement.clientHeight;   //  .client* = bad canvas align
  257. // myCanvas.height =  document.documentElement.innerHeight; // .inner* = Black Screen
  258.       Quick.setAutoScale(false);
  259.       Quick.setKeepAspect(true);
  260. }   //
  261. /* 
  262. window.addEventListener("resize", function(){
  263.     location.reload();  //  867x661  1027x773   if (i % 3 == 0) {};  
  264.         Quick.setAutoScale(false);
  265.         Quick.setKeepAspect(true);
  266. //      truth02.setWidth(64); truth02.setHeight(64);
  267.  
  268. var myCanvas = document.getElementById(“canvas”);
  269. myCanvas.width = 800;
  270. myCanvas.height = 600; 
  271.         } );
  272. */
  273.     var Truth = (function () {
  274.         function Truth() {
  275.             GameObject.call(this);
  276.             this.setImageId("");
  277.             this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight()));
  278. //          this.setEssential();
  279.             this.setSolid();
  280.             this.setLeft(0);
  281.             this.setTop(120);
  282.             this.setSpeedX(4);
  283.         };
  284.         Truth.prototype = Object.create(GameObject.prototype);
  285.  
  286.         Truth.prototype.offBoundary = function (gameObject) {
  287.            if (this.hasTag("truth02")) {
  288.                 truth02Trips += 1; // increment by 1
  289.                 if(truth02Trips > 2) { truth02Trips = 0;
  290.                     truth02.setLeft(0); truth02.setVisible(false); truth02.setSpeedX(0);       
  291.                 };
  292. //                Quick.play("oops"); // calls a static method from Quick class
  293.                 if(truth02.getVisible() ) { this.bounceX(); // for the horizontal axis
  294.                 this.setImage(ImageFactory.mirror(this.getImage())); // flip image horiz
  295.                 };
  296.                 if(!truth02.getVisible() ) {   // if not visible
  297.                 lies02.setLeft(0); lies02.setVisible(true); lies02.setSpeedX(4); //  
  298.                 };
  299.                 };
  300. //
  301.            if (this.hasTag("truth01")) {
  302.                 truth01Trips += 1; // increment by 1
  303.                 if(truth01Trips > 2) { truth01Trips = 0;
  304.                     truth01.setLeft(0); truth01.setVisible(false); truth01.setSpeedX(0);       
  305.                 };
  306. //                Quick.play("obamaVideo.ogg"); // calls a static method from Quick class
  307.                 if(truth01.getVisible() ) { this.bounceX(); // for the horizontal axis
  308.                 this.setImage(ImageFactory.mirror(this.getImage())); // flip image horiz
  309.                 };
  310.                 if(!truth01.getVisible() ) {
  311.                 lies01.setLeft(0); lies01.setVisible(true); lies01.setSpeedX(4); //  
  312.                 };
  313.                 };
  314. //             
  315.            if (this.hasTag("truth03")) {
  316.                 truth03Trips += 1; // increment by 1
  317.                 if(truth03Trips > 2) { truth03Trips = 0;
  318.                     truth03.setLeft(0); truth03.setVisible(false); truth03.setSpeedX(0);       
  319.                 };
  320. //                Quick.play("oops"); // calls a static method from Quick class
  321.                 if(truth03.getVisible() ) { this.bounceX(); // for the horizontal axis
  322.                 this.setImage(ImageFactory.mirror(this.getImage())); // flip image horiz
  323.                 };
  324.                 if(!truth03.getVisible() ) {
  325.                 lies03.setLeft(0); lies03.setVisible(true); lies03.setSpeedX(4); //  
  326.                 };
  327.                 };
  328. //
  329.            if (this.hasTag("truth04")) {
  330.                 truth04Trips += 1; // increment by 1
  331.                 if(truth04Trips > 2) { truth04Trips = 0;
  332.                     truth04.setLeft(0); truth04.setVisible(false); truth04.setSpeedX(0);       
  333.                 };
  334. //                Quick.play("oops"); // calls a static method from Quick class
  335.                 if(truth04.getVisible() ) { this.bounceX(); // for the horizontal axis
  336.                 this.setImage(ImageFactory.mirror(this.getImage())); // flip image horiz
  337.                 };
  338.                 if(!truth04.getVisible() ) {
  339.                 lies04.setLeft(0); lies04.setVisible(true); lies04.setSpeedX(4); //  
  340.                 };
  341.                 };
  342. //
  343.         };         
  344.         return Truth;
  345.     })();
  346. // 
  347.     var Lies = (function () {
  348.  
  349.         function Lies() {
  350.             GameObject.call(this);
  351.             this.setImageId("");
  352.             this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight()));
  353. //          this.setEssential();
  354.             this.setSolid();
  355.             this.setLeft(0);
  356.             this.setTop(120);
  357.             this.setSpeedX(5);
  358.         };
  359.         Lies.prototype = Object.create(GameObject.prototype);
  360.  
  361.         Lies.prototype.offBoundary = function (gameObject) {
  362.             this.bounceX(); // for the horizontal axis
  363.             this.setImage(ImageFactory.mirror(this.getImage()));
  364. //            alert("Lies.prototype.offBoundary");
  365.         };
  366.         return Lies;
  367.  
  368.     })();  
  369. //
  370.     var FirstScene = (function () {
  371.  
  372.         function FirstScene() {
  373.             Scene.call(this);
  374.             this.add(new Background());
  375.             var compound = new Compound();
  376.             this.add(compound);        
  377.             var playBtn = new PlayBtn();
  378.             this.add(playBtn);
  379.             playBtn.addTag("playBtn");
  380.             var restartBtn = new RestartBtn();
  381.             this.add(restartBtn);
  382.             restartBtn.addTag("restartBtn");
  383.             var pauseBtn = new PauseBtn();
  384.             this.add(pauseBtn);
  385.             pauseBtn.addTag("pauseBtn");
  386.             var quitBtn = new QuitBtn();
  387.             this.add(quitBtn);
  388.             quitBtn.addTag("quitBtn");         
  389.             manufacturer = new Manufacturer();
  390.             this.add(manufacturer);        
  391.             var ball = new Ball();
  392.             truth01 = new Truth();
  393.             this.add(truth01);
  394.             truth01.addTag("truth01");
  395.             truth01.setImageId("truth01Sprite");
  396.             truth01.setLeft(0);
  397.             truth01.setTop(0);
  398.             truth01.setSpeedX(4);          
  399.             lies01 = new Lies();
  400.             this.add(lies01);
  401.             lies01.addTag("lies01");
  402.             lies01.setImageId("lies01Sprite");
  403.             lies01.setVisible(false);
  404.             lies01.setLeft(0)    //  (-64);
  405.             lies01.setTop(0);
  406.             lies01.setSpeedX(0);
  407.             truth02 = new Truth();
  408.             this.add(truth02);
  409.             truth02.addTag("truth02");
  410.             truth02.setImageId("truth02Sprite");
  411.             truth02.setLeft(0);
  412.             truth02.setTop(70);
  413.             truth02.setVisible(false);
  414.             truth02.setSpeedX(0);          
  415.             lies02 = new Lies();
  416.             this.add(lies02);
  417.             lies02.addTag("lies02");
  418.             lies02.setImageId("lies02Sprite");
  419.             lies02.setLeft(0)    //  (-64);
  420.             lies02.setTop(70);
  421.             lies02.setSpeedX(6);
  422.             truth03 = new Truth();
  423.             this.add(truth03);
  424.             truth03.addTag("truth03");
  425.             truth03.setImageId("truth03Sprite");
  426.             truth03.setLeft(0);
  427.             truth03.setTop(140);
  428.             truth03.setSpeedX(3);          
  429.             lies03 = new Lies();
  430.             this.add(lies03);
  431.             lies03.addTag("lies03");
  432.             lies03.setImageId("lies03Sprite");
  433.             lies03.setVisible(false);
  434.             lies03.setLeft(0)    //  (-64);
  435.             lies03.setTop(140);
  436.             lies03.setSpeedX(0);
  437.             truth04 = new Truth();
  438.             this.add(truth04);
  439.             truth04.addTag("truth04");
  440.             truth04.setImageId("truth04Sprite");
  441.             truth04.setLeft(-64);
  442.             truth04.setTop(210);
  443.             truth04.setSpeedX(5);          
  444.             lies04 = new Lies();
  445.             this.add(lies04);
  446.             lies04.addTag("lies04");
  447.             lies04.setImageId("lies04Sprite");
  448.             lies04.setVisible(false);
  449.             lies04.setLeft(-64)    //  (-64);
  450.             lies04.setTop(210);
  451.             lies04.setSpeedX(0);
  452.             thrower = new Thrower();
  453.             this.add(thrower);
  454.             var cursorPoint = new Cursor();
  455.             this.add(cursorPoint);
  456.             var spark = new Spark();
  457.             this.add(spark);
  458.             alert( '<--- Arrow = move Left .\n' + '---> Arrow = move Right .\n' + ' Up Arrow = Throw Cowpie \n ' + '\n Best Screen size: Width = >840 , Height = > 640 .\n' +
  459.                      '\n Cheering after every 100 goodHits . \n' +
  460.                      '\n Click  anywhere on screen  to  ACTIVATE BUTTONS  .\n');
  461.             Quick.play("battleFire"); // calls a static method from Quick class
  462.         };
  463.         FirstScene.prototype = Object.create(Scene.prototype);
  464.  
  465.         // override
  466.         FirstScene.prototype.getNext = function () {
  467.             return new FirstScene();
  468.         };
  469.  
  470.         return FirstScene;
  471.  
  472.     })();
  473. //
  474.  
  475.     var Cursor = (function () {
  476.         function Cursor() {
  477.             GameObject.call(this);
  478.             this.addTag("pointerSprite");
  479.             this.controller = Quick.getController();
  480.             this.setBoundary(new Rect(0, 600, Quick.getWidth(), 30)); // a method of Sprite,set Boundary
  481.             this.pointer = Quick.getPointer();
  482.             this.setImageId("pointerSprite");
  483.             this.setSolid();
  484.             this.setEssential();           
  485.             this.setBottom(600); this.setLeft(50); this.setTop(572);    
  486.         };
  487.         Cursor.prototype = Object.create(GameObject.prototype);
  488.        
  489.         Cursor.prototype.fire = function () {
  490.             var spark = new Spark(); // create a brand new spark to be thrown
  491.             var scene = this.getScene(); // ask for the scene the avatar is
  492.             scene.add(spark); // add the spark to the same scene I am
  493.             if (spark) {spark.setX(this.getX()) };     
  494.             spark.setSpeedY(10);
  495.         };
  496.        
  497.         Cursor.prototype.update = function () {
  498.  
  499.             if (this.pointer.getPush()) {   // getpush is a method of Pointer as in Mouse pointer
  500.                 this.fire(); // call the  Cursor.prototype.fire  method we defined above
  501.                 var position = this.pointer.getPosition();
  502.             };
  503.             var mousePos = this.pointer.getPosition();
  504.             this.setPosition(mousePos);
  505.             }
  506.         Cursor.prototype.offBoundary = function (gameObject) {
  507. //          alert('Cursor.prototype.offBoundary');
  508. //          this.setCenterY(587);
  509.         };  
  510. //      this.setCenterY(587);
  511.        
  512.         return Cursor;
  513.     })();
  514.  
  515.     var Spark = (function () { // Spark class namespace
  516.     function Spark() { // Spark class constructor method
  517.         GameObject.call(this); // call the constructor from the superclass
  518.         this.setImageId("sparkSprite"); // setImageId,a method inherited from Sprite
  519. //        this.pointer = Quick.getPointer(); // pointer is a member property of Spark
  520.         this.setBoundary(new Rect(0, 600, Quick.getWidth(), 30)); // a method of Sprite,set
  521.         this.setSolid(); // a method of GameObject , so Spark can collide with other solid objects    
  522.         this.setBottom(600); this.setLeft(50); this.setTop(578);    
  523.         this.controller = Quick.getController();
  524.     };
  525.         Spark.prototype = Object.create(GameObject.prototype);
  526.         Spark.prototype.onCollision = function (gameObject) {        
  527.     var collision = this.getCollision(gameObject); // get direction at collision
  528.  
  529.         if (gameObject.hasTag("restartBtn")) { // returns true if object contains given tag
  530.               Quick.play("closeDoor"); // calls a static method from Quick class
  531.                totalScore = 0; oopsScore = 0; goodHits = 0; totalShots = 0;
  532.                updateScores();
  533.         }
  534.         if (gameObject.hasTag("pauseBtn")) { // returns true if object contains given tag
  535.               Quick.play("pling"); // calls a static method from Quick class
  536.               if(!allPaused) {
  537.                 truth01SVspeed = truth01.getSpeedX();    truth01.setSpeedX(0);  //              this.setSpeedX(5);
  538.                 lies01SVspeed = lies01.getSpeedX();    lies01.setSpeedX(0);  //                     this.setSpeedX(5);
  539.                 truth02SVspeed = truth02.getSpeedX();    truth02.setSpeedX(0);  //              this.setSpeedX(5);
  540.                 lies02SVspeed = lies02.getSpeedX();    lies02.setSpeedX(0);  //                     this.setSpeedX(5);
  541.                 truth03SVspeed = truth03.getSpeedX();    truth03.setSpeedX(0);  //              this.setSpeedX(5);
  542.                 lies03SVspeed = lies03.getSpeedX();    lies03.setSpeedX(0);  //                     this.setSpeedX(5);
  543.                 truth04SVspeed = truth04.getSpeedX();    truth04.setSpeedX(0);  //              this.setSpeedX(5);
  544.                 lies04SVspeed = lies04.getSpeedX();    lies04.setSpeedX(0);  //                     this.setSpeedX(5);
  545.                 allPaused = true;
  546.               }
  547.               else  { alert('You are already paused , try Play  .');
  548.               }
  549.             };  //  gameObject.hasTag
  550. //  
  551.           if (gameObject.hasTag("playBtn")) { // returns true if object contains given tag
  552.               Quick.play("pling"); // calls a static method from Quick class
  553.               if(allPaused) {
  554.                 allPaused = false;  
  555.                 truth01.setSpeedX(truth01SVspeed);
  556.                 lies01.setSpeedX(lies01SVspeed);
  557.                 truth02.setSpeedX(truth02SVspeed); truth02.setWidth(64); truth02.setHeight(64);
  558.                 lies02.setSpeedX(lies02SVspeed);
  559.                 truth03.setSpeedX(truth03SVspeed);
  560.                 lies03.setSpeedX(lies03SVspeed);
  561.                 truth04.setSpeedX(truth04SVspeed);
  562.                 lies04.setSpeedX(lies04SVspeed);
  563.                 }  
  564.             };
  565.           if (gameObject.hasTag("quitBtn")) { // returns true if object contains given tag
  566.               Quick.play("byebye"); // calls a static method from Quick class
  567.               window.location = 'https://github.com/dgsprb/quick/wiki';
  568.             };
  569.     };
  570.                 return Spark; // finally publishes the class to the outer scope
  571. })();
  572.  
  573. //
  574.     var Thrower = (function () {
  575.         function Thrower() {
  576.             GameObject.call(this);
  577.             this.addTag("thrower");
  578.             this.controller = Quick.getController();
  579.             this.setBoundary(new Rect(0, 0, Quick.getWidth(), Quick.getHeight()));
  580.             this.pointer = Quick.getPointer();
  581.             this.setImageId("throwerSprite");
  582.             this.setEssential();           
  583.             this.setCenterX(Quick.getWidth() / 2);
  584.             this.setBottom(Quick.getHeight() - this.getHeight());
  585.             this.setTop(506);    
  586.         };
  587.         Thrower.prototype = Object.create(GameObject.prototype);
  588.        
  589.         Thrower.prototype.fire = function () {
  590.             var ball = new Ball(); // create a brand new ball to be thrown
  591.             var scene = this.getScene(); // ask for the scene the avatar is
  592.             scene.add(ball); // add the ball to the same scene I am
  593.             if (ball) {ball.setX(this.getX()) }; // within your Thrower update method      
  594. //                totalShots ++ ;      
  595.             updateScores();
  596. //          if(ball ) { this.ball.setCenterX(this.getCenterX()) } ;
  597.             ball.setSpeedY(-9);
  598.         };
  599.        
  600.         Thrower.prototype.update = function () {
  601.             if (this.controller.keyDown(CommandEnum.LEFT) && this.getLeft() > 0) {
  602.                 this.moveX(-8);
  603.                 }
  604.             if (this.controller.keyDown(CommandEnum.RIGHT) && this.getRight() < Quick.getWidth()) {
  605.                 this.moveX(8);
  606.                 }              
  607.             if (this.controller.keyPush(CommandEnum.UP) || this.controller.keyPush(CommandEnum.A))
  608.                { totalShots += 1;  
  609.                 this.fire(); // call the method we defined above
  610.                 }
  611.                 }
  612.         Thrower.prototype.offBoundary = function (gameObject) {
  613.             this.setCenterX(Quick.getWidth() / 2);
  614.               };               
  615.        
  616.         return Thrower;
  617.     })();
  618.  
  619.     main();
  620.  
  621. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement