|
@ -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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|