Browse Source

Created Bullet Class

pull/1/head
17bthompson 8 years ago
parent
commit
92276dfc40
1 changed files with 29 additions and 0 deletions
  1. +29
    -0
      src/tanks/Tanks.java

+ 29
- 0
src/tanks/Tanks.java View File

@ -9,12 +9,14 @@ package tanks;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.JPanel;
import java.util.ArrayList;
public class Tanks public class Tanks
{ {
//fields //fields
private JFrame frame; private JFrame frame;
private JPanel panel; private JPanel panel;
private ArrayList<Bullet> bullets;
//constructor //constructor
public Tanks() public Tanks()
@ -74,6 +76,33 @@ public class Tanks
private class Bullet extends RotationalElement private class Bullet extends RotationalElement
{ {
public Bullet(RotationalElement e)
{
x = e.x; //Change this coordinate to the player's location
y = e.y; //Change this coordinate to the player's location
direction = e.direction; //Change this coordinate to the player turret's angle
speed = 10;
}
//Moving the bullet
public void move()
{
super.move(-1);
//Checks if the bullet goes off screen, if so... it get removed
if(x < 0 || x > frame.getHeight())
{
bullets.remove(this); //Jeff does this work?
}
if (y < 0 || y > frame.getWidth())
{
bullets.remove(this); //" "
}
}
} }
/* /*

Loading…
Cancel
Save