Browse Source

added fields and methods to player class

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

+ 44
- 3
src/tanks/Tanks.java View File

@ -54,18 +54,59 @@ public class Tanks
private class Player extends Living
{
Turret t;
boolean up,down,left,right;
void move()
{
if(up==true)
{
super.move(-1);
}
else if(down==true)
{
super.move(1);
}
else if(left==true)
{
super.direction +=5;
}
else if(right==true)
{
super.direction-=5;
}
}
void updateDir(KeyEvent e)
void updateDir(KeyEvent e, boolean pressed)
{
int id=e.getKeyCode();
if(id== KeyEvent.VK_UP)
{
up=pressed;
move();
}
else if(id==KeyEvent.VK_DOWN)
{
down=pressed;
move();
}
else if(id==KeyEvent.VK_LEFT)
{
left=pressed;
move();
}
else if(id==KeyEvent.VK_RIGHT)
{
right=pressed;
move();
}
else if(id==KeyEvent.VK_SPACE)
{
shoot();
}
}
void shoot()
{
bullets.add(new Bullet (this));
}
}

Loading…
Cancel
Save