Wolfos

Pong classes

Feb 11th, 2012
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Ball.as
  2. package{
  3.     import flash.display.MovieClip;
  4.    
  5.     public class Ball extends MovieClip{
  6.         public var xdir = -5;
  7.         public var ydir = 5;
  8.         public function Ball(){
  9.             this.graphics.beginFill(0x000000);
  10.             this.graphics.drawCircle(0,0,10);
  11.         }
  12.         public function update(){
  13.             this.x+=xdir;
  14.             this.y+=ydir;
  15.         }
  16.     }
  17. }
  18.  
  19. //PlayerBat.as
  20. package{
  21.     import flash.display.MovieClip;
  22.     import flash.events.KeyboardEvent;
  23.     import flash.text.TextField;
  24.     public class PlayerBat extends MovieClip{
  25.         var upkey:Boolean;
  26.         var downkey:Boolean;
  27.         public function PlayerBat(){
  28.             this.graphics.beginFill(0x000000);
  29.             this.graphics.drawRect(0,0,10,50);
  30.         }
  31.         public function init(){
  32.             stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
  33.             stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
  34.         }
  35.        
  36.         public function update(){
  37.             //trace(upkey);
  38.             if(upkey){
  39.                 this.y-=10;
  40.             }
  41.             if(downkey){
  42.                 this.y+=10;
  43.             }
  44.         }
  45.        
  46.         private function keyDown(keyEvent:KeyboardEvent){
  47.             if(keyEvent.keyCode == 38){
  48.                 upkey = true;
  49.             }
  50.             if(keyEvent.keyCode == 40){
  51.                 downkey = true;
  52.             }
  53.         }
  54.         private function keyUp(keyEvent:KeyboardEvent){
  55.             if(keyEvent.keyCode == 38){
  56.                 upkey = false;
  57.             }
  58.             if(keyEvent.keyCode == 40){
  59.                 downkey = false;
  60.             }
  61.         }
  62.     }
  63. }
  64.  
  65. //EnemyBat.as
  66. package{
  67.     import flash.display.MovieClip;
  68.     public class EnemyBat extends MovieClip{
  69.         public var goal:int = 200;
  70.         public function EnemyBat(){
  71.             this.graphics.beginFill(0x000000);
  72.             this.graphics.drawRect(0,0,10,50);
  73.         }
  74.         public function update(){
  75.             if(goal>this.y){
  76.                 this.y+=5;
  77.             }
  78.             if(goal<this.y){
  79.                 this.y-=5;
  80.             }
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment