So I’m making a sort of space game in Java. Currently, the spacecraft stays in place if the user isn’t doing anything, and moves at a constant velocity in different directions based on the user’s key input.
I’d like to change it so that when the spacecraft is moving, as the user continues to press the key, the spacecraft’s velocity accelerates faster.
In my move method, I currently have
public void move() {
x += dx;
y += dy;
}
I’ve tried doing such things as
public void move() {
x *= dx;
y *= dy;
}
But constantly multiplying values makes the spacecraft move way too fast.
Is there another approach to doing this?
Thanks in advance.
Looks like you need to change
dxaccording to a keyboard event of your choice. So:dx(testing for min/max values) accordingly. You could do some fun physics formula here based on the current value ofdx?Then, when the spaceship
moves,dxwill be either large, or small, depending on how many times the user has pounded on the key.