Guest User

Untitled

a guest
May 20th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  
  2. {
  3.     import flash.geom.PerspectiveProjection;
  4.     import flash.text.engine.TabAlignment;
  5.     import net.flashpunk.graphics.Backdrop;
  6.     import net.flashpunk.World;
  7.     import net.flashpunk.Entity;
  8.     import net.flashpunk.utils.Input;
  9.     import net.flashpunk.FP;
  10.     import net.flashpunk.graphics.Image;
  11.     import net.flashpunk.graphics.Text;
  12.     import net.flashpunk.Sfx;
  13.    
  14.     /**
  15.      * ...
  16.      * @author ...
  17.      */
  18.     public class GameWorld extends World
  19.     {
  20.         public static var background:Background = new Background();
  21.        
  22.         public var music:Sfx = new Sfx(Assets.MUSIC);
  23.         public var ball:Ball;
  24.         public static var vPaddle:VerticalPaddle;
  25.         public static var hPaddle:HorizontalPaddle;
  26.         public static var aiVPaddle:AIverticalPaddle;
  27.         public static var aiHPaddle:AIhorizontalPaddle;
  28.         public static var ballCount:int = 0;
  29.         public static var aiSpeed:int = 9;
  30.         public var P1ScoreText:Text = new Text("0");
  31.         public var AIScoreText:Text = new Text("0");
  32.         public var timer:Number = 0;
  33.         public static var pScore:int = 0;
  34.         public static var aScore:int = 0;
  35.         public function GameWorld()
  36.        
  37.         {
  38.             ball = new Ball(FP.screen.width / 2 - 7 / 2, FP.screen.height / 2 - 7);
  39.             vPaddle = new VerticalPaddle(30);
  40.             hPaddle = new HorizontalPaddle(25);
  41.             aiVPaddle = new AIverticalPaddle(FP.screen.width - 25 - 60);
  42.             aiHPaddle = new AIhorizontalPaddle(FP.screen.height - 25 - 50);
  43.             add(ball);
  44.             add(vPaddle);
  45.             add(hPaddle);
  46.             add(aiVPaddle);
  47.             add(aiHPaddle);
  48.             this.addGraphic(P1ScoreText, 4, FP.screen.width /2 - 70, FP.screen.height /2 -90);
  49.             this.addGraphic(AIScoreText, 4, FP.screen.width / 2 + 20, FP.screen.height / 2);
  50.             P1ScoreText.size = 90;
  51.             P1ScoreText.color = 0x99ccff;          
  52.             AIScoreText.size = 90;
  53.             AIScoreText.color = 0xffcc99;
  54.             music.loop();
  55.             add(background);
  56.         }
  57.        
  58.        
  59.         public function gameWin():void
  60.         {
  61.             if (pScore >= 9)
  62.             {
  63.                 FP.world = new PlayerWin();
  64.             }
  65.         }
  66.        
  67.         public function gameLose():void
  68.         {
  69.             if (aScore >= 1)
  70.             {
  71.                 FP.world = new PlayerLose();
  72.             }
  73.         }
  74.        
  75.        
  76.         override public function update():void
  77.         {
  78.             P1ScoreText.text = pScore.toString();
  79.             AIScoreText.text = aScore.toString();
  80.            
  81.             //aiHPaddle.x = ball.x - Image(aiHPaddle.graphic).scaledWidth / 2;
  82.             //aiVPaddle.y = ball.y - Image(aiVPaddle.graphic).scaledHeight / 2;
  83.            
  84.             aiHPaddle.moveTowards(ball.x - Image(aiHPaddle.graphic).scaledWidth / 2, aiHPaddle.y, aiSpeed);
  85.             aiVPaddle.moveTowards(aiVPaddle.x, ball.y - Image(aiVPaddle.graphic).scaledHeight / 2, aiSpeed);
  86.            
  87.             gameWin();
  88.             gameLose();
  89.            
  90.             super.update();
  91.         }
  92.     }
  93.  
  94. }
Add Comment
Please, Sign In to add comment