Browse Source

enemy spawn update

pull/1/head
jrtechs 8 years ago
parent
commit
d0fa37d5fd
2 changed files with 15 additions and 18 deletions
  1. +7
    -7
      src/tanks/Enemy.java
  2. +8
    -11
      src/tanks/Tanks.java

+ 7
- 7
src/tanks/Enemy.java View File

@ -23,28 +23,28 @@ public abstract class Enemy extends Living
to determine which edge of map enemy spawns. Random number code to
determine how far down or how far over player spawns on given edge.
*/
public void spawn(JFrame frame)
public void spawn(int w, int h)
{
int temp=(int)(Math.random()*(4)) + 1;
if(temp==1)
{
y=0;
x=(int)(Math.random()*(frame.getWidth()+1));
x=(int)(Math.random()*(w));
}
else if(temp==2)
{
y=(int)(Math.random()*(frame.getHeight()+1));
x=frame.getWidth();
y=(int)(Math.random()*(h));
x=w;
}
else if(temp==3)
{
y=frame.getHeight();
x=(int)(Math.random()*(frame.getWidth()+1));
y=h;
x=(int)(Math.random()*(w+1));
}
else
{
x=0;
y=(int)(Math.random()*(frame.getHeight()+1));
y=(int)(Math.random()*(h - 200));
}
}

+ 8
- 11
src/tanks/Tanks.java View File

@ -43,7 +43,7 @@ public class Tanks
frame=new JFrame("Tanks project");
frame.setSize(fwidth,fheight + 150);
//frame.setResizable(false);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newGame();
@ -340,7 +340,7 @@ public class Tanks
public Zombie()
{
super();
this.spawn(frame);
spawn(fwidth, fheight);
width = 30;
height = 30;
health = 10;
@ -399,11 +399,11 @@ public class Tanks
super.move(-1);
//Checks if the bullet goes off screen, if so... it get removed
if(x < 0 || x > frame.getWidth())
if(x < 0 || x > fwidth)
{
bullets.remove(this);
}
if (y < 0 || y > frame.getHeight())
if (y < 0 || y > fheight)
{
bullets.remove(this);
}
@ -489,7 +489,7 @@ public class Tanks
{
super();
enemy.add(this);
this.spawn(frame);
this.spawn(fwidth, fheight);
width = 50;
height = 50;
health = 20;
@ -554,7 +554,7 @@ public class Tanks
}
private class Wave extends DrawableElement
private class Wave extends DrawableElement
{
/*fields time is continous while playing, gameMode(1=playing,
2=paused, 3=menu. spawntime keeps a countdown until next spawn,
@ -587,7 +587,7 @@ public class Tanks
};
//action listener increments time
spawn = new Timer(2000,s);
spawn = new Timer(5000,s);
spawn.start();
ActionListener t = new ActionListener()
{
@ -622,10 +622,7 @@ public class Tanks
//enemy
public void spawn()
{
Enemy temp = new Zombie();
temp.spawn(frame);
enemy.add(temp);
enemy.add(new Zombie());
enemy.add(new Tank());
}

Loading…
Cancel
Save