Skip to content

Commit

Permalink
Clean up some duplicate code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChickenProp committed Jul 27, 2012
1 parent f9bb1c8 commit b90628b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 13 additions & 4 deletions src/Ball.hx
Expand Up @@ -16,8 +16,10 @@ class Ball extends Entity {
public function new () {
super();

x = HXP.width / 2;
y = HXP.height / 2;
x = HXP.width / 2; // These are just in case G.paddle doesn't
y = HXP.height / 2; // exist, which shouldn't ever happen.
putOnPaddle();

width = 10;
height = 10;
centerOrigin();
Expand All @@ -30,8 +32,7 @@ class Ball extends Entity {

override public function update () : Void {
if (!launched) {
x = G.paddle.x;
y = G.paddle.y - G.paddle.halfHeight - halfHeight;
putOnPaddle();
return;
}

Expand Down Expand Up @@ -79,6 +80,14 @@ class Ball extends Entity {
launched = true;
}

public function putOnPaddle () : Void {
if (G.paddle == null)
return;

x = G.paddle.x;
y = G.paddle.y - G.paddle.halfHeight - halfHeight;
}

override public function moveCollideX (e) : Void {
if (Std.is(e, Brick))
hitBrick(e);
Expand Down
4 changes: 0 additions & 4 deletions src/BreakoutWorld.hx
Expand Up @@ -107,9 +107,7 @@ class BreakoutWorld extends World {
G.score = 0;
add(new ScoreDisplay());
paddle = G.paddle = new Paddle();
paddle.active = false;
add(paddle);
add(new Activator());
placeBall();

var seed:Int = 0;
Expand All @@ -125,8 +123,6 @@ class BreakoutWorld extends World {

public function placeBall () : Void {
ball = new Ball();
ball.x = paddle.x;
ball.y = paddle.y - paddle.halfHeight - ball.halfHeight;
add(ball);
paddle.recenter();
}
Expand Down

0 comments on commit b90628b

Please sign in to comment.