Permalink
Browse files

Bounded player

Realized that player could move left of window and avoid all enemy
bullets...bounded player to be within window.
  • Loading branch information...
1 parent 8a77726 commit e44f0570c567468314424bf81ac34b9cdfd0e6e3 @SubSage committed Mar 7, 2013
Showing with 5 additions and 1 deletion.
  1. +5 −1 GDCalaga/src/org/gdc/gdcalaga/Player.java
@@ -54,26 +54,30 @@ public void draw(Graphics g)
public void moveUp(float delta)
{
y-=yVel*delta/1000;
+ y = Math.max(height/2, y);
}
public void moveDown(float delta)
{
y+=yVel*delta/1000;
+ y = Math.min(720 - height/2, y);
}
public void moveLeft(float delta)
{
x-=xVel*delta/1000;
+ x = Math.max(0 + width/2, x);
}
public void moveRight(float delta)
{
x+=xVel*delta/1000;
+ x = Math.min(1280 - width/2, x);
}
public void fire()
{
- Bullet newBullet = new Bullet(entities, (int)x + 20, (int)y ,1 , alliance);
+ Bullet newBullet = new Bullet(entities, (int)x + width/2, (int)y ,1 , alliance);
newBullet.setSpeed(500, 0);
}

0 comments on commit e44f057

Please sign in to comment.