Browse Source

Merge pull request #3 from 17mgeffert/master

Made some format changes, stepping stone to greater improvement.
TryingToMakeThisALittleBetter
17mgeffert 6 years ago
committed by GitHub
parent
commit
686f69b3b5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 75 deletions
  1. +40
    -75
      src/tanks/Tanks.java

+ 40
- 75
src/tanks/Tanks.java View File

@ -141,42 +141,38 @@ public class Tanks
frame.setVisible(true); frame.setVisible(true);
//Timer //Timer
ActionListener tic = new ActionListener()
{
//Override
public void actionPerformed(ActionEvent e)
//Override
ActionListener tic = e -> {
if(wave.gameMode == 1)
{ {
if(wave.gameMode == 1)
p.move();
for(int i = 0; i < bullets.size(); i ++)
{ {
p.move();
for(int i = 0; i < bullets.size(); i ++)
try
{
bullets.get(i).move();
}
catch(Exception ex)
{ {
try
{
bullets.get(i).move();
}
catch(Exception ex)
{
}
} }
for(int i = 0; i < enemy.size(); i++)
}
for(int i = 0; i < enemy.size(); i++)
{
try
{
enemy.get(i).move();
}
catch(Exception ex)
{ {
try
{
enemy.get(i).move();
}
catch(Exception ex)
{
}
} }
} }
wave.waveCheck();
panel.repaint();
} }
wave.waveCheck();
panel.repaint();
}; };
move = new Timer(30, tic); //Timer that moves things... Moves the player and enemies? move = new Timer(30, tic); //Timer that moves things... Moves the player and enemies?
@ -350,27 +346,16 @@ public class Tanks
} }
void shoot() void shoot()
{ {
if(ammo<=0)
{
}
else
{
bullets.add(new Bullet (t));
ammo--;
}
if(ammo>0) {
bullets.add(new Bullet (t));
ammo--;
}
} }
public void draw (Graphics g)
{
public void draw (Graphics g) {
super.draw(g); super.draw(g);
t.draw(g); t.draw(g);
} }
} }
/** /**
* A zombie extends Enemy * A zombie extends Enemy
* a zombie has a specialized move method which * a zombie has a specialized move method which
@ -396,26 +381,20 @@ public class Tanks
} }
//uses super to move player if collision then removes zombie and player //uses super to move player if collision then removes zombie and player
//takes damage //takes damage
public void move()
{
public void move() {
direction = angleToPlayer(p); direction = angleToPlayer(p);
super.move(-1); super.move(-1);
if(this.checkCollision(p))
{
if(this.checkCollision(p)) {
enemy.remove(this); enemy.remove(this);
p.takeDamage(); p.takeDamage();
if(!p.isAlive)
{
if(!p.isAlive) {
wave.setGameMode(2); wave.setGameMode(2);
wave.kills++; wave.kills++;
} }
} }
} }
} }
/** /**
* a bullet moves at a specified angle * a bullet moves at a specified angle
* if the bullet collides with a enemy it gives damage * if the bullet collides with a enemy it gives damage
@ -712,57 +691,48 @@ public class Tanks
switch(waveNum) switch(waveNum)
{ {
case 1: case 1:
if(kills == 15)
{
if(kills == 15) {
changeWave(); changeWave();
} }
break; break;
case 2: case 2:
if(kills == 20)
{
if(kills == 20) {
changeWave(); changeWave();
} }
break; break;
case 3: case 3:
if(kills == 26)
{
if(kills == 26) {
spawnTank.start(); spawnTank.start();
changeWave(); changeWave();
} }
break; break;
case 4: case 4:
if(kills == 32)
{
if(kills == 32) {
changeWave(); changeWave();
} }
break; break;
case 5: case 5:
if(kills == 33)
{
if(kills == 33) {
changeWave(); changeWave();
} }
break; break;
case 6: case 6:
if(kills == 35)
{
if(kills == 35) {
changeWave(); changeWave();
} }
break; break;
case 7: case 7:
if(kills == 37)
{
if(kills == 37) {
changeWave(); changeWave();
} }
break; break;
case 8: case 8:
if(kills == 40)
{
if(kills == 40) {
changeWave(); changeWave();
} }
break; break;
case 9: case 9:
if(kills == 49)
{
if(kills == 49) {
changeWave(); changeWave();
} }
break; break;
@ -776,18 +746,13 @@ public class Tanks
} }
} }
} }
public void changeWave()
{
public void changeWave() {
waveNum++; waveNum++;
spawnedZombies = 0; spawnedZombies = 0;
spawnedTanks = 0; spawnedTanks = 0;
kills = 0; kills = 0;
spawnTank.setDelay(4000); spawnTank.setDelay(4000);
} }
} }
} }

Loading…
Cancel
Save