From c2e6bd641a663f188709f33904db7094162be036 Mon Sep 17 00:00:00 2001 From: 17mgeffert Date: Mon, 6 Jun 2016 10:19:31 -0400 Subject: [PATCH] added fields and methods to player classs --- src/tanks/Tanks.java | 52 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/src/tanks/Tanks.java b/src/tanks/Tanks.java index 298e8bc..66fe3b4 100644 --- a/src/tanks/Tanks.java +++ b/src/tanks/Tanks.java @@ -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); - } }