Guest User

Untitled

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