What a great first post, eh?
Well, I started working on a simple top-down shooter yesterday (Using the Slick library). I’ve made the enemies follow the player, but it’s somewhat buggy.
@Override
public void update(GameContainer gc, int delta) {
float dx = ((Engine.getPlayer().getLocation().x + 10) - this.location.x);
float dy = ((Engine.getPlayer().getLocation().y + 10) - this.location.y);
this.rotation = (float) Math.toDegrees(Math.atan2(dy, dx) + 89.65f);
final float SPEED = 1.0f;
this.location.x += Math.cos(this.rotation) * SPEED;
this.location.y += Math.sin(this.rotation) * SPEED;
}
@Override
public void render(GameContainer gc, Graphics g) {
sprite.setRotation(Math.round(this.rotation));
sprite.draw(this.location.x - (sprite.getWidth() / 2), this.location.y - (sprite.getHeight() / 2));
}
It works fine when the player isn’t moving, but when the player starts moving, the enemy starts doing all of these little circles (not rotation, but location) until the Player stops moving.
Anyone know what the issue might be?