Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Whacky *document class*
- package whacked {
- import flash.display.*;
- import flash.events.*;
- import flash.utils.*;
- import flash.text.TextField;
- import flash.media.Sound;
- import flash.media.SoundChannel;
- import flash.ui.Keyboard;
- public class Whacky extends MovieClip {
- public var holder:Array;
- //these variables should be declared private and accessed via methods
- private var hits:int;
- private var misses:int;
- private var hitsStat:Sprite;
- private var missesStat:Sprite;
- public var crosshair:Crosshair;
- public var xmlLoader:XMLLoader;
- private var nSecs:int;
- private var myTimer:Timer;
- private var timeCount:Timer;
- private var timerText:TextField;
- public var gameOver:GameOver;
- public var temp:MovieClip;
- public var bong:Bong;
- public function Whacky() {
- crosshair = new Crosshair();
- this.addChild(crosshair);
- crosshair.x = mouseX;
- crosshair.y = mouseY;
- this.addEventListener(Event.ENTER_FRAME, onEnter);
- xmlLoader = new XMLLoader("whacky.xml", this);
- timerText = new TextField();
- addChild(timerText);
- timerText.width = 125;
- timerText.x = 250;
- timerText.y = 25;
- timeCount = new Timer(1000, 10);
- timeCount.addEventListener(TimerEvent.TIMER, countdown);
- timeCount.start();
- hits=0;
- misses=0;
- stage.frameRate = 100;
- hitsStat = new ScoreBoard(hits, "hits");
- hitsStat.x=110;
- hitsStat.y=20;
- this.addChild(hitsStat);
- missesStat = new ScoreBoard(misses, "misses");
- missesStat.x=110;
- missesStat.y=60;
- this.addChild(missesStat);
- gameOver = new GameOver();
- this.addChild(gameOver);
- gameOver.visible = false;
- //generateTargets(.01, 12);
- bong = new Bong();
- }//end function
- public function timerHandler(event:TimerEvent)
- {
- trace("10 sec is up");
- timerText.text = String("TIME UP");
- gameOver.visible = true;
- temp.endGame();
- removeChild(temp);
- }
- public function countdown(event:TimerEvent)
- {
- timerText.text = String(10 - timeCount.currentCount);
- }
- public function onEnter(event:Event) {
- crosshair.x = this.mouseX;
- crosshair.y = this.mouseY;
- }
- public function generateTargets(popUpRate:Number, resetFrame:int){
- holder = new Array();
- for(var i:int = 0; i < 8; i++){
- temp = new Target(popUpRate, resetFrame);
- addChild(temp);
- holder.push(temp);
- temp.x = i * (temp.width + 5) + 50;
- temp.y = 200;
- } // end for loop
- } // end generateTargets
- public function setNSecs(_nsecs:int):void
- {
- nSecs = _nsecs;
- trace("time limit in doc class " + nSecs);
- myTimer = new Timer(nSecs*1000,1);
- myTimer.addEventListener(TimerEvent.TIMER,timerHandler);
- myTimer.start()
- }
- public function setHits(_hits:int):void
- {
- hits = hits + _hits;
- }
- public function setMisses(_misses:int):void
- {
- misses = misses + _misses;
- }
- public function setHitsStat(_hitsStat:Sprite):void
- {
- hitsStat = _hitsStat;
- }
- public function setMissesStat(_missesStats:Sprite):void
- {
- missesStat = _missesStats;
- }
- public function getHits():int
- {
- return hits;
- }
- public function getMisses():int
- {
- return misses;
- }
- public function getHitsStat():Sprite
- {
- return hitsStat;
- }
- public function getMissesStat():Sprite
- {
- return missesStat;
- }
- }//end class
- }//end package
- //Target class
- package whacked {
- import flash.display.*;
- import flash.events.*;
- import flash.events.KeyboardEvent;
- import flash.events.TimerEvent;
- import flash.utils.Timer;
- public class Target extends MovieClip {
- public var state:String;
- public var popUpRate:Number; //larger popUpRate makes targets pop up more frequently
- public var numberFramesUntilReset:int; //larger numberFramesUntilReset makes targets stay up longer
- public var counter:int;
- public var timer:Timer;
- public function Target(popUpRate:Number, framesUntilReset:int) {
- this.stop();
- timer = new Timer(100);
- this.state = "down";
- this.gotoAndStop("down");
- this.popUpRate = popUpRate;
- this.numberFramesUntilReset = framesUntilReset;
- this.counter=0;
- timer.addEventListener(TimerEvent.TIMER, timerHandler);
- this.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
- timer.start();
- }//end function
- public function endGame()
- {
- trace("end game");
- timer.stop();
- this.stop();
- }
- public function timerHandler(anEvent:TimerEvent) {
- if (this.state == "down") { //target is currently down
- if (Math.random() < this.popUpRate) { //pop up randomly
- this.state = "up";
- this.gotoAndStop("up");
- this.counter = this.numberFramesUntilReset;
- } // end if
- }
- else { //this.state == "up" means target is currently up
- this.counter--;
- if (this.counter < 0) { //target should be set back down
- this.state = "down";
- this.gotoAndStop("down");
- Whacky(this.parent).setMisses(1);
- ScoreBoard(Whacky(this.parent).getMissesStat()).statistic_txt.text = "" + Whacky(this.parent).getMisses();
- } // end if
- } // end if state == "up" or "down"
- } // end enterFrameHandler
- public function mouseOverHandler(anEvent:MouseEvent) {
- if (this.state == "up") { //player nailed this one
- this.state = "down";
- this.gotoAndStop("down");
- Whacky(this.parent).setHits(1);
- Whacky(this.parent).bong.play();
- ScoreBoard(Whacky(this.parent).getHitsStat()).statistic_txt.text = "" + Whacky(this.parent).getHits();
- } // end if
- } // end mouseDownHandler
- }//end class
- }//end package
Add Comment
Please, Sign In to add comment