Browse Source

added turret images

boolean movement for player turret
pull/1/head
jrtechs 8 years ago
parent
commit
b7f6c9ce64
6 changed files with 23 additions and 14 deletions
  1. +2
    -1
      .gitignore
  2. +1
    -1
      src/tanks/DrawableElement.java
  3. +20
    -12
      src/tanks/Tanks.java
  4. BIN
      src/tanks/enemyTank.png
  5. BIN
      src/tanks/player.png
  6. BIN
      src/tanks/turret.png

+ 2
- 1
.gitignore View File

@ -1,2 +1,3 @@
/nbproject/private/ /nbproject/private/
/build/
/build/
/dist/

+ 1
- 1
src/tanks/DrawableElement.java View File

@ -32,7 +32,7 @@ public abstract class DrawableElement
img = null; img = null;
try try
{ {
System.out.println(imageLocation);
//System.out.println(imageLocation);
img = ImageIO.read(getClass().getResourceAsStream(imageLocation)); img = ImageIO.read(getClass().getResourceAsStream(imageLocation));
//img = ImageIO.read(new File(imageLoc)); //img = ImageIO.read(new File(imageLoc));
} }

+ 20
- 12
src/tanks/Tanks.java View File

@ -43,6 +43,7 @@ public class Tanks
frame=new JFrame("Tanks project"); frame=new JFrame("Tanks project");
frame.setSize(fwidth,fheight + 150); frame.setSize(fwidth,fheight + 150);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newGame(); newGame();
@ -184,7 +185,7 @@ public class Tanks
private class Player extends Living private class Player extends Living
{ {
private Turret t; private Turret t;
private boolean up,down,left,right;
private boolean up,down,left,right, rleft, rRight;
public Player() public Player()
{ {
@ -201,12 +202,19 @@ public class Tanks
void move() void move()
{ {
if(rleft)
{
t.rotate(-1);
}
if(rRight)
{
t.rotate(1);
}
if(up==true) if(up==true)
{ {
super.move(-1); super.move(-1);
t.move(-1); t.move(-1);
} }
if(down==true) if(down==true)
{ {
@ -239,8 +247,8 @@ public class Tanks
{ {
y-=speed; y-=speed;
} }
t.x = x+12;
t.y = y+12;
t.x = x;
t.y = y;
} }
void updateDir(KeyEvent e, boolean pressed) void updateDir(KeyEvent e, boolean pressed)
@ -264,11 +272,11 @@ public class Tanks
} }
else if(id==KeyEvent.VK_A) else if(id==KeyEvent.VK_A)
{ {
t.rotate(-1);
rleft = pressed;
} }
else if(id==KeyEvent.VK_D) else if(id==KeyEvent.VK_D)
{ {
t.rotate(1);
rRight = pressed;
} }
else if(id==KeyEvent.VK_SPACE) else if(id==KeyEvent.VK_SPACE)
{ {
@ -352,8 +360,8 @@ public class Tanks
{ {
width = 25; width = 25;
height = 25; height = 25;
x = e.x;
y = e.y;
x = e.x + 12;
y = e.y + 12;
direction = e.direction; direction = e.direction;
speed = 10; speed = 10;
imageLocation = "bullet.png"; imageLocation = "bullet.png";
@ -423,13 +431,13 @@ public class Tanks
{ {
public Turret(RotationalElement e) public Turret(RotationalElement e)
{ {
width = 25;
height = 25;
width = 50;
height = 50;
x = e.x; x = e.x;
y = e.y; y = e.y;
direction = e.direction; direction = e.direction;
speed = 10; speed = 10;
imageLocation = "bullet.png";
imageLocation = "turret.png";
super.loadImage(); super.loadImage();
} }
public void shoot() public void shoot()
@ -562,7 +570,7 @@ public class Tanks
Enemy temp = new Zombie(); Enemy temp = new Zombie();
temp.spawn(frame); temp.spawn(frame);
enemy.add(temp); enemy.add(temp);
} }

BIN
src/tanks/enemyTank.png View File

Before After
Width: 50  |  Height: 50  |  Size: 2.0 KiB

BIN
src/tanks/player.png View File

Before After
Width: 50  |  Height: 50  |  Size: 3.2 KiB Width: 50  |  Height: 50  |  Size: 2.1 KiB

BIN
src/tanks/turret.png View File

Before After
Width: 50  |  Height: 50  |  Size: 1.9 KiB

Loading…
Cancel
Save