daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest May 16th, 2018 146 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  
  2. {
  3.     import net.flashpunk.Entity;
  4.     import net.flashpunk.graphics.Image;
  5.     import net.flashpunk.graphics.Spritemap;
  6.    
  7.     public class Background
  8.     {
  9.        
  10.         public var sprbackground:Spritemap = new Spritemap(background, 800, 600);
  11.         public function Background()
  12.         {
  13.             sprbackground.add("idle", [0], 1, true);
  14.             graphic = sprbackground;
  15.         }
  16.        
  17.     }
  18.  
  19. }
  20.  
  21.  
  22.  
  23.  
  24.  
  25. GAMEWORLD:
  26.  
  27.  
  28.  
  29. package  
  30. {
  31.     import flash.geom.PerspectiveProjection;
  32.     import flash.text.engine.TabAlignment;
  33.     import net.flashpunk.graphics.Backdrop;
  34.     import net.flashpunk.World;
  35.     import net.flashpunk.Entity;
  36.     import net.flashpunk.utils.Input;
  37.     import net.flashpunk.FP;
  38.     import net.flashpunk.graphics.Image;
  39.     import net.flashpunk.graphics.Text;
  40.     import net.flashpunk.Sfx;
  41.    
  42.     /**
  43.      * ...
  44.      * @author ...
  45.      */
  46.     public class GameWorld extends World
  47.     {
  48.         public static var background:Background = new Background();
  49.        
  50.         public var music:Sfx = new Sfx(Assets.MUSIC);
  51.         public var ball:Ball;
  52.         public static var vPaddle:VerticalPaddle;
  53.         public static var hPaddle:HorizontalPaddle;
  54.         public static var aiVPaddle:AIverticalPaddle;
  55.         public static var aiHPaddle:AIhorizontalPaddle;
  56.         public static var ballCount:int = 0;
  57.         public static var aiSpeed:int = 2;
  58.         public var P1ScoreText:Text = new Text("0");
  59.         public var AIScoreText:Text = new Text("0");
  60.         public var timer:Number = 0;
  61.         public static var pScore:int = 0;
  62.         public static var aScore:int = 0;
  63.         public function GameWorld()
  64.  
  65.         {
  66.             ball = new Ball(FP.screen.width / 2 - 7 / 2, FP.screen.height / 2 - 7);
  67.             vPaddle = new VerticalPaddle(25);
  68.             hPaddle = new HorizontalPaddle(25);
  69.             aiVPaddle = new AIverticalPaddle(FP.screen.width - 25 - 10);
  70.             aiHPaddle = new AIhorizontalPaddle(FP.screen.height - 25 - 10);
  71.             add(ball);
  72.             add(vPaddle);
  73.             add(hPaddle);
  74.             add(aiVPaddle);
  75.             add(aiHPaddle);
  76.             this.addGraphic(P1ScoreText, 4, FP.screen.width /2 - 50, FP.screen.height /2 -50);
  77.             this.addGraphic(AIScoreText, 4, FP.screen.width / 2 + 50, FP.screen.height / 2);
  78.             P1ScoreText.size = 90;
  79.             P1ScoreText.color = 0xe3563;           
  80.             AIScoreText.size = 90;
  81.             AIScoreText.color = 0xff0000;
  82.             music.loop();
  83.             add(background);
  84.         }
  85.        
  86.         override public function update():void
  87.         {
  88.             P1ScoreText.text = pScore.toString();
  89.             AIScoreText.text = aScore.toString();
  90.            
  91.             //aiHPaddle.x = ball.x - Image(aiHPaddle.graphic).scaledWidth / 2;
  92.             //aiVPaddle.y = ball.y - Image(aiVPaddle.graphic).scaledHeight / 2;
  93.            
  94.             aiHPaddle.moveTowards(ball.x - Image(aiHPaddle.graphic).scaledWidth / 2, aiHPaddle.y, aiSpeed);
  95.             aiVPaddle.moveTowards(aiVPaddle.x, ball.y - Image(aiVPaddle.graphic).scaledHeight / 2, aiSpeed);
  96.            
  97.             super.update();
  98.         }
  99.     }
  100.  
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top