Guest User

Untitled

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