Guest User

Untitled

a guest
Jul 15th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. //Whacky *document class*
  2. package whacked {
  3.  
  4. import flash.display.*;
  5. import flash.events.*;
  6. import flash.utils.*;
  7. import flash.text.TextField;
  8. import flash.media.Sound;
  9. import flash.media.SoundChannel;
  10. import flash.ui.Keyboard;
  11.  
  12.  
  13. public class Whacky extends MovieClip {
  14.  
  15. public var holder:Array;
  16. //these variables should be declared private and accessed via methods
  17. private var hits:int;
  18. private var misses:int;
  19. private var hitsStat:Sprite;
  20. private var missesStat:Sprite;
  21. public var crosshair:Crosshair;
  22. public var xmlLoader:XMLLoader;
  23. private var nSecs:int;
  24. private var myTimer:Timer;
  25. private var timeCount:Timer;
  26. private var timerText:TextField;
  27. public var gameOver:GameOver;
  28. public var temp:MovieClip;
  29.  
  30. public var bong:Bong;
  31.  
  32. public function Whacky() {
  33.  
  34. crosshair = new Crosshair();
  35. this.addChild(crosshair);
  36. crosshair.x = mouseX;
  37. crosshair.y = mouseY;
  38. this.addEventListener(Event.ENTER_FRAME, onEnter);
  39.  
  40. xmlLoader = new XMLLoader("whacky.xml", this);
  41.  
  42. timerText = new TextField();
  43. addChild(timerText);
  44. timerText.width = 125;
  45. timerText.x = 250;
  46. timerText.y = 25;
  47.  
  48. timeCount = new Timer(1000, 10);
  49. timeCount.addEventListener(TimerEvent.TIMER, countdown);
  50. timeCount.start();
  51.  
  52. hits=0;
  53. misses=0;
  54. stage.frameRate = 100;
  55. hitsStat = new ScoreBoard(hits, "hits");
  56.  
  57.  
  58. hitsStat.x=110;
  59. hitsStat.y=20;
  60. this.addChild(hitsStat);
  61.  
  62. missesStat = new ScoreBoard(misses, "misses");
  63.  
  64. missesStat.x=110;
  65. missesStat.y=60;
  66. this.addChild(missesStat);
  67.  
  68. gameOver = new GameOver();
  69. this.addChild(gameOver);
  70. gameOver.visible = false;
  71.  
  72. //generateTargets(.01, 12);
  73.  
  74. bong = new Bong();
  75.  
  76. }//end function
  77.  
  78. public function timerHandler(event:TimerEvent)
  79. {
  80.  
  81. trace("10 sec is up");
  82. timerText.text = String("TIME UP");
  83. gameOver.visible = true;
  84.  
  85. temp.endGame();
  86. removeChild(temp);
  87.  
  88.  
  89. }
  90.  
  91. public function countdown(event:TimerEvent)
  92. {
  93. timerText.text = String(10 - timeCount.currentCount);
  94. }
  95.  
  96. public function onEnter(event:Event) {
  97.  
  98. crosshair.x = this.mouseX;
  99. crosshair.y = this.mouseY;
  100. }
  101.  
  102. public function generateTargets(popUpRate:Number, resetFrame:int){
  103.  
  104. holder = new Array();
  105.  
  106. for(var i:int = 0; i < 8; i++){
  107. temp = new Target(popUpRate, resetFrame);
  108. addChild(temp);
  109. holder.push(temp);
  110. temp.x = i * (temp.width + 5) + 50;
  111. temp.y = 200;
  112. } // end for loop
  113.  
  114. } // end generateTargets
  115.  
  116. public function setNSecs(_nsecs:int):void
  117. {
  118. nSecs = _nsecs;
  119. trace("time limit in doc class " + nSecs);
  120. myTimer = new Timer(nSecs*1000,1);
  121. myTimer.addEventListener(TimerEvent.TIMER,timerHandler);
  122. myTimer.start()
  123. }
  124.  
  125. public function setHits(_hits:int):void
  126. {
  127. hits = hits + _hits;
  128. }
  129.  
  130. public function setMisses(_misses:int):void
  131. {
  132. misses = misses + _misses;
  133. }
  134.  
  135. public function setHitsStat(_hitsStat:Sprite):void
  136. {
  137. hitsStat = _hitsStat;
  138. }
  139.  
  140. public function setMissesStat(_missesStats:Sprite):void
  141. {
  142. missesStat = _missesStats;
  143. }
  144. public function getHits():int
  145. {
  146. return hits;
  147. }
  148.  
  149. public function getMisses():int
  150. {
  151. return misses;
  152. }
  153.  
  154. public function getHitsStat():Sprite
  155. {
  156. return hitsStat;
  157. }
  158.  
  159. public function getMissesStat():Sprite
  160. {
  161. return missesStat;
  162. }
  163.  
  164. }//end class
  165.  
  166. }//end package
  167.  
  168.  
  169.  
  170. //Target class
  171. package whacked {
  172.  
  173. import flash.display.*;
  174. import flash.events.*;
  175. import flash.events.KeyboardEvent;
  176. import flash.events.TimerEvent;
  177. import flash.utils.Timer;
  178.  
  179. public class Target extends MovieClip {
  180.  
  181. public var state:String;
  182. public var popUpRate:Number; //larger popUpRate makes targets pop up more frequently
  183. public var numberFramesUntilReset:int; //larger numberFramesUntilReset makes targets stay up longer
  184. public var counter:int;
  185. public var timer:Timer;
  186.  
  187. public function Target(popUpRate:Number, framesUntilReset:int) {
  188. this.stop();
  189.  
  190. timer = new Timer(100);
  191. this.state = "down";
  192. this.gotoAndStop("down");
  193. this.popUpRate = popUpRate;
  194. this.numberFramesUntilReset = framesUntilReset;
  195. this.counter=0;
  196. timer.addEventListener(TimerEvent.TIMER, timerHandler);
  197. this.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
  198.  
  199.  
  200. timer.start();
  201.  
  202. }//end function
  203.  
  204.  
  205. public function endGame()
  206. {
  207. trace("end game");
  208. timer.stop();
  209. this.stop();
  210. }
  211.  
  212.  
  213.  
  214.  
  215. public function timerHandler(anEvent:TimerEvent) {
  216.  
  217. if (this.state == "down") { //target is currently down
  218. if (Math.random() < this.popUpRate) { //pop up randomly
  219. this.state = "up";
  220. this.gotoAndStop("up");
  221. this.counter = this.numberFramesUntilReset;
  222. } // end if
  223. }
  224. else { //this.state == "up" means target is currently up
  225. this.counter--;
  226. if (this.counter < 0) { //target should be set back down
  227. this.state = "down";
  228. this.gotoAndStop("down");
  229. Whacky(this.parent).setMisses(1);
  230. ScoreBoard(Whacky(this.parent).getMissesStat()).statistic_txt.text = "" + Whacky(this.parent).getMisses();
  231. } // end if
  232. } // end if state == "up" or "down"
  233. } // end enterFrameHandler
  234.  
  235.  
  236.  
  237. public function mouseOverHandler(anEvent:MouseEvent) {
  238. if (this.state == "up") { //player nailed this one
  239. this.state = "down";
  240. this.gotoAndStop("down");
  241. Whacky(this.parent).setHits(1);
  242. Whacky(this.parent).bong.play();
  243. ScoreBoard(Whacky(this.parent).getHitsStat()).statistic_txt.text = "" + Whacky(this.parent).getHits();
  244. } // end if
  245. } // end mouseDownHandler
  246.  
  247. }//end class
  248. }//end package
Add Comment
Please, Sign In to add comment