This site requires JavaScript, please enable it in your browser!
Greenfoot back
Cragster25
Cragster25 wrote ...

2016/5/28

I have another issue with the bullets I have in my code.

Cragster25 Cragster25

2016/5/28

#
as the game is top down the bullets are meant to be the same direction as the player which they do get the players rotation but this doesn't seen to have an impact on the direction they are being fired at, at the moment the bullet will only move in 45 degree segments (0, 45, 90 ...) how can I fix this.
Super_Hippo Super_Hippo

2016/5/28

#
You can either increase the speed of the bullet to get a bit more precise firing or you can import the SmoothMover class and let the bullet extend this class.
Cragster25 Cragster25

2016/5/28

#
where can I find the SmoothMover class, I have looked for it but can't seem to find it. It might be being stupid but could you post a link.
danpost danpost

2016/5/28

#
Cragster25 wrote...
where can I find the SmoothMover class, I have looked for it but can't seem to find it. It might be being stupid but could you post a link.
Open up the greenfoot application and load your project. Then, use the menubar and select "Edit/Import class...". Finally, select the SmoothMover class and click on the 'Import' button. As an alternative to using that class, you could just save the original location of the bullet and add a step counter as follows:
// instance fields
private int originX;
private int originY;
private int speed = 1; // can be adjusted
private int counter;

// method to set origin coordinates
protected void addedToWorld(World world)
{
    originX = getX();
    originY = getY();
}

// in act method
move();

// the 'move' method
private void move()
{
    counter++;
    setLocation(originX, originY);
    move(counter*speed);
}
This should not interfere with the setting of the rotation of the bullet, which you should already have the code for.
You need to login to post a reply.