Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LOSESCREEN:
- package
- {
- import net.flashpunk.Entity;
- import flash.media.Sound;
- import net.flashpunk.Sfx;
- import net.flashpunk.graphics.Spritemap;
- import net.flashpunk.graphics.Image;
- /**
- * ...
- * @author ...
- */
- public class LoseScreen extends Entity
- {
- public function LoseScreen(x:int, y:int)
- {
- type = "losescreen";
- this.graphic = new Image (Assets.playerlose1);
- this.x = x;
- this.y = y
- }
- }
- }
- PLAYERLOSE:
- public class PlayerLose extends World
- {
- public var winscreen:LoseScreen = new LoseScreen(0, 0);
- public function PlayerLose()
- {
- add(losescreen);
- }
- }
- }
- package
- {
- import flash.geom.PerspectiveProjection;
- import flash.text.engine.TabAlignment;
- import net.flashpunk.graphics.Backdrop;
- import net.flashpunk.World;
- import net.flashpunk.Entity;
- import net.flashpunk.utils.Input;
- import net.flashpunk.FP;
- import net.flashpunk.graphics.Image;
- import net.flashpunk.graphics.Text;
- import net.flashpunk.Sfx;
- /**
- * ...
- * @author ...
- */
- public class GameWorld extends World
- {
- public static var background:Background = new Background();
- public var music:Sfx = new Sfx(Assets.MUSIC);
- public var ball:Ball;
- public static var vPaddle:VerticalPaddle;
- public static var hPaddle:HorizontalPaddle;
- public static var aiVPaddle:AIverticalPaddle;
- public static var aiHPaddle:AIhorizontalPaddle;
- public static var ballCount:int = 0;
- public static var aiSpeed:int = 9;
- public var P1ScoreText:Text = new Text("0");
- public var AIScoreText:Text = new Text("0");
- public var timer:Number = 0;
- public static var pScore:int = 0;
- public static var aScore:int = 0;
- public function GameWorld()
- {
- ball = new Ball(FP.screen.width / 2 - 7 / 2, FP.screen.height / 2 - 7);
- vPaddle = new VerticalPaddle(30);
- hPaddle = new HorizontalPaddle(25);
- aiVPaddle = new AIverticalPaddle(FP.screen.width - 25 - 60);
- aiHPaddle = new AIhorizontalPaddle(FP.screen.height - 25 - 50);
- add(ball);
- add(vPaddle);
- add(hPaddle);
- add(aiVPaddle);
- add(aiHPaddle);
- this.addGraphic(P1ScoreText, 4, FP.screen.width /2 - 70, FP.screen.height /2 -90);
- this.addGraphic(AIScoreText, 4, FP.screen.width / 2 + 20, FP.screen.height / 2);
- P1ScoreText.size = 90;
- P1ScoreText.color = 0x99ccff;
- AIScoreText.size = 90;
- AIScoreText.color = 0xffcc99;
- music.loop();
- add(background);
- }
- public function gameWin():void
- {
- if (pScore >= 9)
- {
- FP.world = new PlayerWin();
- }
- }
- public function gameLose():void
- {
- if (aScore >= 1)
- {
- FP.world = new PlayerLose();
- }
- }
- override public function update():void
- {
- P1ScoreText.text = pScore.toString();
- AIScoreText.text = aScore.toString();
- //aiHPaddle.x = ball.x - Image(aiHPaddle.graphic).scaledWidth / 2;
- //aiVPaddle.y = ball.y - Image(aiVPaddle.graphic).scaledHeight / 2;
- aiHPaddle.moveTowards(ball.x - Image(aiHPaddle.graphic).scaledWidth / 2, aiHPaddle.y, aiSpeed);
- aiVPaddle.moveTowards(aiVPaddle.x, ball.y - Image(aiVPaddle.graphic).scaledHeight / 2, aiSpeed);
- gameWin();
- gameLose();
- super.update();
- }
- }
- }
Add Comment
Please, Sign In to add comment