Improve How the SpaceShip Moves
It's kind of limiting how the ship can only point and move in only four directions. It's possible for us to give the ship a greater range of direction. To do this, we're going to change how the arrow keys affect the ship's movement:
Left Key: | Turn Left instead of Move Left |
---|---|
Right Key: | Turn Right instead of Move Right |
Up Key: | Speed Up instead of Move Up |
Down Key: | Speed Down instead of Move Down |
Open spaceship.js in your code editor, and modify the following lines of code as indicated in yellow:
Now we need to change the way main.js handles keys so that it calls these four new methods. Open main.js in your code editor, and modify the following lines of code as indicated in yellow:
Refresh your browser, and see if the new ship movement behavior works. It should be similar to how shown below:
Great, we're ready to add some asteroids into the game!
Debugging Tips
- All JavaScript code is case-sensitive. Make sure that every letter of your code matches the casing as seen in the instructions.
- Keep an eye out for all symbols such as parenthesis, periods, commas, quotations, and semicolons.
- The semicolon at the end of every JavaScript statement is the easiest symbol to forget.
Note about whitespace:
For the most part, JavaScript doesn't care about whitespace (spaces, tabs, and carriage returns). In fact, it's actually encouraged for you to use as many spaces, tabs, and carriage returns as necessary to make your code easy to read. For example:
Which is easier to read?