Guest User

Untitled

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