Permalink
Browse files

Fixed relation between bullet vs entity

Took the advice of vt about bullets not caring about entities. Seems
like the better way to do it, as the Collide method in enemy and player
serve a purpose, and if we add new types of guns, with new types of
bullets, it would involve massive rewrites.
  • Loading branch information...
1 parent 09de877 commit d6e0914a36a9e0a64f36a9365471b06251071483 @SubSage committed Mar 7, 2013
@@ -76,24 +76,29 @@ public void Collide(Entity other)
{
if(other instanceof Enemy)
{
- Enemy enemy = (Enemy)other;
- if(alliance!=enemy.getAlliance())
+ if(alliance!=((Enemy)other).getAlliance())
{
- enemy.Hurt(damage);
Destroy();
}
}
else if(other instanceof Player)
{
- Player player = (Player)other;
- if(alliance!=player.getAlliance())
+ if(alliance!=((Player)other).getAlliance())
{
- player.Hurt(damage);
Destroy();
}
}
}
+
+ public float getDamage(){
+ return damage;
+ }
+
+
+ public int getAlliance() {
+ return alliance;
+ }
}
@@ -59,7 +59,7 @@ public void update(float delta)
yVel*=-1;
}
- if(Math.random()*1000*delta < 100){
+ if(Math.random()*100*delta < 10){
fire();
}
@@ -90,6 +90,10 @@ public void draw(Graphics g)
public void Collide(Entity other)
{
+ if(other instanceof Bullet && ((Bullet)other).getAlliance()!=alliance)
+ {
+ Hurt(((Bullet)other).getDamage());
+ }
}
@@ -24,7 +24,7 @@ public void init(GameContainer container, StateBasedGame game) throws SlickExcep
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
entities.draw(g);
- g.drawString("Player HP: " + player.getHealth(), 5, 30);
+ g.drawString("Player HP: " + player.getHealth() + " Round " + Spawn.wave, 5, 30);
}
@Override
@@ -47,7 +47,7 @@ public void draw(Graphics g)
int drawX = (int) (x - width/2);
int drawY = (int) (y - height/2);
float scale = width / ship.getWidth();
- ship.draw(drawX, drawY, scale, Color.white);
+ ship.draw(drawX, drawY, scale, Color.red);
}
@@ -79,7 +79,10 @@ public void fire()
public void Collide(Entity other)
{
-
+ if(other instanceof Bullet && ((Bullet)other).getAlliance()!=alliance)
+ {
+ Hurt(((Bullet)other).getDamage());
+ }
}
public void Hurt(float dmg){

0 comments on commit d6e0914

Please sign in to comment.