Rocket (movement)


The next challenge is to get the rocket to move around when the arrow keys are pressed.


1. In the Rocketship constructor, set its speed variable to 10.


2. Add up(), down(), left() and right() methods to the Rocketship class that modify its x or y value by the amount in the speed variable. For example:

    public void right() {
        x+=speed;
    }

GamePanel


3. In the GamePanel, modify the keyPressed() method to call the appropriate method of the rocketship. The rocket must ALWAYS appear in the window, so make sure you only move the rocket if it will still be visible in the game's window after it moves. For example, before you call the rocket's up() method, make sure there is room above it in the window.


TESTING

4. Run the program. Press the Enter key to put the game into the GAME state (black background). Does the blue rocketship (square) appear at the bottom? Does it move when you press the arrow keys? Does it stop when it gets to the top, bottom, left, and right of the game's window?

CHALLENGE
5. Does the rocketship move too quickly or slowly? Is the movement smooth or jagged? Play around with the speed and think about how you might use the keyPressed and keyReleased methods of the GamePanel to improve the rocket's movement. You might need to add more variables and/or methods to achieve the behavior you want.