Advertisement
Guest User

Untitled

a guest
Oct 14th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  
  2. {
  3.    
  4.     import flash.display.MovieClip;
  5.     import flash.events.TimerEvent;
  6.     import flash.utils.Timer;
  7.     import flash.events.Event; //calls event file
  8.     import flash.events.KeyboardEvent; //calls keyboard class
  9.     import flash.ui.Keyboard; //keyboard input
  10.     import flash.ui.Mouse;
  11.     import flash.net.SharedObject;
  12.  
  13.    
  14.     public class PlayScreen extends MovieClip
  15.     {
  16.         //public var pKeyIsBeingPressed:Boolean;
  17.         public var candyStorm:Array;
  18.         public var lemonStorm:Array;
  19.         public var newCandy:Candy;
  20.         public var newDrop:LemonDrop;
  21.         public var player:Player;
  22.         public var gameTimer:Timer;
  23.         public var sharedObject:SharedObject;
  24.         public var gameScore:int;
  25.        
  26.         public function PlayScreen()
  27.         {
  28.             var sharedObject:SharedObject = SharedObject.getLocal("idleCatcherScore");  
  29.             if ( sharedObject.data.highScore == undefined )
  30.             {
  31.                 sharedObject.data.highScore = 0;
  32.             }
  33.             else
  34.             {
  35.                 gameScore = sharedObject.data.highScore;
  36.             }
  37.  
  38.             player = new Player();
  39.             Mouse.hide();          
  40.             //pKeyIsBeingPressed = false;
  41.             var newCandy = new Candy( 100, -35 );          
  42.             var newDrop = new LemonDrop( 330, -20 );
  43.             candyStorm = new Array();
  44.             lemonStorm = new Array();
  45.             candyStorm.push( newCandy );
  46.             lemonStorm.push( newDrop );
  47.             addChild( newCandy );
  48.             addChild( newDrop );
  49.                
  50.             gameTimer = new Timer( 25 );
  51.             gameTimer.addEventListener( TimerEvent.TIMER, onTick, false, 0, true )
  52.             gameTimer.start();
  53.             addChild( player )
  54.             //addEventListener( Event.ADDED_TO_STAGE, onAddToStage );
  55.         }
  56.        
  57.         /*public function onAddToStage( event:Event ):void
  58.         {
  59.             stage.addEventListener( KeyboardEvent.KEY_DOWN, onKeyPress );
  60.             stage.addEventListener( KeyboardEvent.KEY_UP, onKeyRelease );
  61.         }
  62.  
  63.         public function onKeyPress( keyboardEvent:KeyboardEvent ):void
  64.         {
  65.             if ( keyboardEvent.keyCode == Keyboard.P )
  66.             {
  67.                 pKeyIsBeingPressed = true;
  68.             }
  69.         }
  70.        
  71.         public function onKeyRelease( keyboardEvent:KeyboardEvent ):void
  72.         {
  73.             if ( keyboardEvent.keyCode == Keyboard.P )
  74.             {
  75.                 pKeyIsBeingPressed = false;
  76.             }
  77.         }*/
  78.        
  79.         public function onTick( timerEvent:TimerEvent ):void
  80.         {          
  81.             player.x = mouseX;
  82.             player.y = mouseY;
  83.            
  84.             if ( Math.random() < 0.1 )
  85.             {
  86.                 var randomX:Number = Math.random() * 400;
  87.                 var newCandy:Candy = new Candy( randomX, -35 );
  88.                 candyStorm.push ( newCandy )
  89.                 addChild ( newCandy )
  90.             }
  91.             var i:int = candyStorm.length - 1;
  92.             var candy:Candy;
  93.            
  94.             while ( i > -1 )
  95.             {
  96.                 candy = candyStorm[i];
  97.                 candy.moveABit();
  98.                 if( PixelPerfectCollisionDetection.isColliding( player, candy, this, true ) )
  99.                 {
  100.                     candy.parent.removeChild( candy );
  101.                     gameScore.addToValue( 5 );
  102.                     candyStorm.splice( i, 1 );
  103.                     sharedObject.data.highScore = gameScore;
  104.                 }              
  105.                
  106.                 if ( candy.y > 550 )
  107.                 {
  108.                     candy.parent.removeChild( candy );
  109.                     candyStorm.splice( i, 1 );
  110.                 }
  111.                
  112.                 i = i - 1;
  113.                
  114.             /*if ( Math.random() < 0.02 )
  115.             {
  116.                 var lemonX:Number = Math.random() * 400;
  117.                 var newDrop:LemonDrop = new LemonDrop( lemonX, -15 );
  118.                 lemonStorm.push ( newDrop )
  119.                 addChild ( newDrop )
  120.             }
  121.             var g:int = lemonStorm.length - 1;
  122.             var lemonDrop:LemonDrop;
  123.            
  124.             while ( g > -1 )
  125.             {
  126.                 lemonDrop = lemonStorm[g];
  127.                 lemonDrop.moveLemonDrop();
  128.                 if( PixelPerfectCollisionDetection.isColliding( player, lemonDrop, this, true ) )
  129.                 {
  130.                     lemonDrop.parent.removeChild( lemonDrop );
  131.                     gameScore.addToValue( 10 );
  132.                     lemonStorm.splice( g, 1 );
  133.                 }              
  134.                
  135.                 if ( lemonDrop.y > 550 )
  136.                 {
  137.                     lemonDrop.parent.removeChild( lemonDrop );
  138.                     lemonStorm.splice( g, 1 );
  139.                 }
  140.                
  141.                 g = g - 1;
  142.  
  143.                
  144.             }*/
  145.         }
  146.         /*if ( pKeyIsBeingPressed )
  147.         {
  148.         }*/
  149.     }
  150.    
  151. }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement