Browse Source

added fields and methods to player classs

pull/1/head
17mgeffert 8 years ago
parent
commit
c2e6bd641a
1 changed files with 48 additions and 4 deletions
  1. +48
    -4
      src/tanks/Tanks.java

+ 48
- 4
src/tanks/Tanks.java View File

@ -53,7 +53,6 @@ public class Tanks
@Override
public void keyTyped(KeyEvent e)
{
}
@Override
public void keyPressed(KeyEvent e)
@ -104,6 +103,10 @@ public class Tanks
g.setFont(new Font("Arial" , 1, 25));
g.drawString("Wave: " + wave.waveNum, 50, fheight + 50);
g.setColor(Color.WHITE);
g.setFont(new Font("Arial" , 1, 25));
g.drawString("Ammo: "+ p.ammo, 150, fheight+50);
//Kills
g.setColor(Color.WHITE);
g.setFont(new Font("Arial" , 1, 25));
@ -211,9 +214,27 @@ public class Tanks
{
private Turret t;
private boolean up,down,left,right, rleft, rRight;
private int ammo=10;
private boolean shoot;
ActionListener coolDown = new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
if(shoot==false)
{
shoot=true;
}
}
};
Timer time=new Timer(300,coolDown);
public Player()
{
time.start();
t=new Turret(this);
speed = 5;
x = frame.getWidth()/2;
@ -303,24 +324,47 @@ public class Tanks
{
rRight = pressed;
}
else if(id==KeyEvent.VK_R)
{
ammo=10;
}
else if(id==KeyEvent.VK_SPACE)
{
if(pressed)
{
shoot();
if (shoot)
{
shoot();
shoot=false;
}
else
{
}
}
}
}
void shoot()
{
bullets.add(new Bullet (t));
if(ammo<=0)
{
}
else
{
bullets.add(new Bullet (t));
ammo--;
}
}
public void draw (Graphics g)
{
super.draw(g);
t.draw(g);
}
}

Loading…
Cancel
Save