Browse Source

finished enemy tank constructor

pull/1/head
16nlyons 8 years ago
parent
commit
95ae6c0149
1 changed files with 54 additions and 18 deletions
  1. +54
    -18
      src/tanks/Tanks.java

+ 54
- 18
src/tanks/Tanks.java View File

@ -478,49 +478,77 @@ public class Tanks
/* /*
*/ */
private class Tank extends Enemy
private class Tank extends Enemy
{ {
Bullet b; Bullet b;
Turret t; Turret t;
Timer tim; Timer tim;
ActionListener al;
public Tank() public Tank()
{ {
super(); super();
speed=3;
ActionListener al = new ActionListener()
enemy.add(this);
this.spawn(frame);
width = 50;
height = 50;
health = 20;
isAlive=true;
speed = 2;
imageLocation = "enemyTank.png";
super.loadImage();
t = new Turret(this);
t.imageLocation = "enemyTurret.png";
t.loadImage();
al = new ActionListener()
{ {
@Override @Override
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
b = new Bullet(t);
b.enemyBullet=true;
bullets.add(b);
if(getAlive())
{
b = new Bullet(t);
b.enemyBullet=true;
bullets.add(b);
}
} }
}; };
tim = new Timer(3500,al); tim = new Timer(3500,al);
tim.start(); tim.start();
}
public void draw (Graphics g)
{
super.draw(g);
t.draw(g);
} }
public void move() public void move()
{ {
if(this.distToPlayer(p)>150)
if(this.distToPlayer(p)>250)
{ {
direction = angleToPlayer(p); direction = angleToPlayer(p);
super.move(-1); super.move(-1);
if(this.checkCollision(p)) if(this.checkCollision(p))
{ {
enemy.remove(this);
p.takeDamage(); p.takeDamage();
this.takeDamage();
if(isAlive==false)
{
enemy.remove(this);
}
if(!p.isAlive) if(!p.isAlive)
{ {
wave.setGameMode(2); wave.setGameMode(2);
} }
} }
} }
t.x=this.x+25;
t.y=this.y+25;
t.x=this.x;
t.y=this.y;
t.direction=this.angleToPlayer(p); t.direction=this.angleToPlayer(p);
} }
@ -567,10 +595,10 @@ public class Tanks
@Override @Override
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
if(wave.gameMode == 1)
{
timeCount++;
}
if(gameMode==1)
{
timeCount++;
}
} }
}; };
@ -579,19 +607,26 @@ public class Tanks
} }
public void setGameMode(int newGameMode) public void setGameMode(int newGameMode)
{ {
gameMode = newGameMode;
gameMode = newGameMode;
if(gameMode == 2)
{
//Player has died, ending the game
time.stop();
move.stop();
}
} }
//spawn method checks if spawn timer ==0 and if so then spawns an //spawn method checks if spawn timer ==0 and if so then spawns an
//enemy //enemy
//Turn off enemy spawning when the game is paused ************************************************************
public void spawn() public void spawn()
{ {
Enemy temp = new Zombie(); Enemy temp = new Zombie();
temp.spawn(frame); temp.spawn(frame);
enemy.add(temp); enemy.add(temp);
enemy.add(new Tank());
} }
@ -599,3 +634,4 @@ public class Tanks
//timer //timer
} }
} }

Loading…
Cancel
Save