Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.MovieClip;
- import flash.events.TimerEvent;
- import flash.utils.Timer;
- import flash.events.Event; //calls event file
- import flash.events.KeyboardEvent; //calls keyboard class
- import flash.ui.Keyboard; //keyboard input
- import flash.ui.Mouse;
- import flash.net.SharedObject;
- public class PlayScreen extends MovieClip
- {
- //public var pKeyIsBeingPressed:Boolean;
- public var candyStorm:Array;
- public var lemonStorm:Array;
- public var newCandy:Candy;
- public var newDrop:LemonDrop;
- public var player:Player;
- public var gameTimer:Timer;
- public var sharedObject:SharedObject;
- public var gameScore:int;
- public function PlayScreen()
- {
- var sharedObject:SharedObject = SharedObject.getLocal("idleCatcherScore");
- if ( sharedObject.data.highScore == undefined )
- {
- sharedObject.data.highScore = 0;
- }
- else
- {
- gameScore = sharedObject.data.highScore;
- }
- player = new Player();
- Mouse.hide();
- //pKeyIsBeingPressed = false;
- var newCandy = new Candy( 100, -35 );
- var newDrop = new LemonDrop( 330, -20 );
- candyStorm = new Array();
- lemonStorm = new Array();
- candyStorm.push( newCandy );
- lemonStorm.push( newDrop );
- addChild( newCandy );
- addChild( newDrop );
- gameTimer = new Timer( 25 );
- gameTimer.addEventListener( TimerEvent.TIMER, onTick, false, 0, true )
- gameTimer.start();
- addChild( player )
- //addEventListener( Event.ADDED_TO_STAGE, onAddToStage );
- }
- /*public function onAddToStage( event:Event ):void
- {
- stage.addEventListener( KeyboardEvent.KEY_DOWN, onKeyPress );
- stage.addEventListener( KeyboardEvent.KEY_UP, onKeyRelease );
- }
- public function onKeyPress( keyboardEvent:KeyboardEvent ):void
- {
- if ( keyboardEvent.keyCode == Keyboard.P )
- {
- pKeyIsBeingPressed = true;
- }
- }
- public function onKeyRelease( keyboardEvent:KeyboardEvent ):void
- {
- if ( keyboardEvent.keyCode == Keyboard.P )
- {
- pKeyIsBeingPressed = false;
- }
- }*/
- public function onTick( timerEvent:TimerEvent ):void
- {
- player.x = mouseX;
- player.y = mouseY;
- if ( Math.random() < 0.1 )
- {
- var randomX:Number = Math.random() * 400;
- var newCandy:Candy = new Candy( randomX, -35 );
- candyStorm.push ( newCandy )
- addChild ( newCandy )
- }
- var i:int = candyStorm.length - 1;
- var candy:Candy;
- while ( i > -1 )
- {
- candy = candyStorm[i];
- candy.moveABit();
- if( PixelPerfectCollisionDetection.isColliding( player, candy, this, true ) )
- {
- candy.parent.removeChild( candy );
- gameScore.addToValue( 5 );
- candyStorm.splice( i, 1 );
- sharedObject.data.highScore = gameScore;
- }
- if ( candy.y > 550 )
- {
- candy.parent.removeChild( candy );
- candyStorm.splice( i, 1 );
- }
- i = i - 1;
- /*if ( Math.random() < 0.02 )
- {
- var lemonX:Number = Math.random() * 400;
- var newDrop:LemonDrop = new LemonDrop( lemonX, -15 );
- lemonStorm.push ( newDrop )
- addChild ( newDrop )
- }
- var g:int = lemonStorm.length - 1;
- var lemonDrop:LemonDrop;
- while ( g > -1 )
- {
- lemonDrop = lemonStorm[g];
- lemonDrop.moveLemonDrop();
- if( PixelPerfectCollisionDetection.isColliding( player, lemonDrop, this, true ) )
- {
- lemonDrop.parent.removeChild( lemonDrop );
- gameScore.addToValue( 10 );
- lemonStorm.splice( g, 1 );
- }
- if ( lemonDrop.y > 550 )
- {
- lemonDrop.parent.removeChild( lemonDrop );
- lemonStorm.splice( g, 1 );
- }
- g = g - 1;
- }*/
- }
- /*if ( pKeyIsBeingPressed )
- {
- }*/
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement