Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

shooting straight

Options
  • 24-03-2005 8:05pm
    #1
    Closed Accounts Posts: 91 ✭✭


    I am making a 2d racing. The cars have guns but they only shoot straight when its facing right can anyone tell me whats wrong with my code.

    public ShotEntity(Game game,String sprite,int x,int y)
    {
    super(sprite,x,y);

    this.game = game;

    dx = moveSpeed;
    }

    public void tryToFire()
    {
    // check that we have waiting long enough to fire
    if (System.currentTimeMillis() - lastFire < firingInterval)
    {
    return;
    }

    // if we waited long enough, create the shot entity, and record the time.
    lastFire = System.currentTimeMillis();
    ShotEntity shot = new ShotEntity(this,"sprites/shot.gif",car.getX(),car.getY()+10);//this sets where shot goes from
    entities.add(shot);
    }


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    What does the inherited ShotEntity() do?


  • Closed Accounts Posts: 91 ✭✭magnia


    it just gives u the initial position, displays the pic and removes it if it leaves the screen u any idea how to get it to shoot in the position the car is facing


  • Registered Users Posts: 261 ✭✭HaVoC


    What happens when ya call this method: entities.add(shot)

    Sounds like in the add method or somewhere along the line, it takes the jpeg and steps it along the x axis, so no mather which way ya face it will shoot right.
    Do you store the heading of the car ?
    based on heading you'll have to step the shots jpeg's x and y values.
    ie x+step for East, x-step for West, y+step for north etc.


Advertisement