Skip to content

Commit

Permalink
Tanks v0.2.1 - Mines now blow up when in range of another mine or hit…
Browse files Browse the repository at this point in the history
… by a bullet
  • Loading branch information
Matei Budiu authored and Matei Budiu committed Apr 15, 2018
1 parent 67a83b7 commit a3ee6d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/tanks/Bullet.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,27 @@ else if (dy >= 0 && dy < bound && horizontalDist < verticalDist)
((Tank) o).destroy = true;
}
}
else if (o instanceof Bullet && o != this)
else if ((o instanceof Bullet || o instanceof Mine) && o != this)
{
if (!((Bullet)o).destroy)
if (!o.destroy)
{

double horizontalDist = Math.abs(this.posX - o.posX);
double verticalDist = Math.abs(this.posY - o.posY);

double bound = this.size / 2 + Bullet.bullet_size / 2;
int s = Bullet.bullet_size;
if (o instanceof Mine)
s = Mine.mine_size;

double bound = this.size / 2 + s / 2;

if (horizontalDist < bound && verticalDist < bound)
{
this.destroy = true;
this.vX = 0;
this.vY = 0;
this.destroy = true;
((Bullet)o).destroy = true;
o.destroy = true;

this.vX = 0;
this.vY = 0;
Expand Down
6 changes: 5 additions & 1 deletion src/tanks/Mine.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

public class Mine extends Movable
{
public static int mine_size = 30;
int timer = 1000;
int size = 30;
int size = mine_size;

Tank tank;

Expand Down Expand Up @@ -37,6 +38,9 @@ public void update()
{
this.timer--;

if (destroy)
this.explode();

if (this.timer <= 0)
this.explode();
super.update();
Expand Down
2 changes: 2 additions & 0 deletions src/tanks/SolidObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

public interface SolidObject {
Obstacle getFaces();

//Not yet implemented
}

0 comments on commit a3ee6d2

Please sign in to comment.