Hello
I'm trying to create a game that allows you to shoot at each other. so kind of like a first-person shooter. I am using the controls from the asteroid game in the book but the code is not working in my favor. Any idea what is wrong?
Here is the code for flaco one of the characters
public class Flaco extends Mover
{
private int gunReloadTime; // The minimum delay between firing the gun.
private int reloadDelayCount; // How long ago we fired the gun the last time.
private int shotsFired; // Number of shots fired.
private Vector acceleration;
public Flaco()
{
gunReloadTime=5;
reloadDelayCount=0;
shotsFired=0;
acceleration=new Vector (0,0.3);
}
/**
* Act - do whatever the Flaco wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.isKeyDown("Left"))
{
moveLeft();
}
if (Greenfoot.isKeyDown("Right"))
{
moveRight();
}
if (Greenfoot.isKeyDown("Down"))
{
moveDown();
}
if (Greenfoot.isKeyDown("Up"))
{
moveUp();
}
if(Greenfoot.isKeyDown("space"))
{
}
}
public int getShotsFired()
{
return shotsFired;
}
public void setGunReloadTime(int reloadTime)
{
gunReloadTime=reloadTime;
}
public Vector getMovement()
{
return movement;
}
private void fire()
{
if (reloadDelayCount >= gunReloadTime) {
Bullet b = new Bullet(getMovement().copy(), getRotation());
getWorld().addObject(b, getX(), getY());
b.move();
shotsFired++;
reloadDelayCount = 0; // time since last shot fired
}
}
}