import net.sf.jirr.*;

public class Player extends TwoDGameObject 
{
  protected static final float PLAYER_SPEED = 150;
  protected static final float TIME_BETWEEN_SHOTS = 0.2f;
  protected boolean forward = false;
  protected boolean backward = false;
  protected boolean left = false;
  protected boolean right = false;
  protected boolean shooting = false;
  protected float timeSinceLastShot = 0;
  
  public void startupPlayer()
  {
    super.startupTwoDGameObject(ResourceManager.PlayerRes, new position2df(1010), CollisionIdentifiers.PLAYER);
  }
  
  public void shutdown()
  {
    super.shutdown();
  }
  
  public void enterFrame(double dt)
  {
    super.enterFrame(dt);
    
    timeSinceLastShot -= dt;
    
    if (forward)
      position.setY((float)(position.getY() - PLAYER_SPEED * dt));
    if (backward)
      position.setY((float)(position.getY() + PLAYER_SPEED * dt));
    if (left)
      position.setX((float)(position.getX() - PLAYER_SPEED * dt));
    if (right)
      position.setX((float)(position.getX() + PLAYER_SPEED * dt));
    if (shooting && timeSinceLastShot <= 0)
    {
      timeSinceLastShot = TIME_BETWEEN_SHOTS;
      float x = position.getX() + graphics.area.getWidth() - ResourceManager.TwoBulletsRes.area.getWidth() 2;
      float y = position.getY() - ResourceManager.TwoBulletsRes.area.getHeight();
      Weapon.getWeapon().startupPlayerWeapon(ResourceManager.TwoBulletsRes, new position2df(x, y));
    }
    
    keepOnScreen();
  }
  
  public void keyDown(EKEY_CODE keyCode)
  {
    switch (keyCode)
    {
    case KEY_UP:
      forward = true;
      break;
    case KEY_DOWN:
      backward = true;
      break;
    case KEY_LEFT:
      left = true;
      break;
    case KEY_RIGHT:
      right = true;
      break;
    case KEY_SPACE:
      shooting = true;
      break;
    }
  }
  
  public void keyUp(EKEY_CODE keyCode)
  {
    switch (keyCode)
    {
    case KEY_UP:
      forward = false;
      break;
    case KEY_DOWN:
      backward = false;
      break;
    case KEY_LEFT:
      left = false;
      break;
    case KEY_RIGHT:
      right = false;
      break;
    case KEY_SPACE:
      shooting = false;
      break;
    }
  }
}