Your sprite is on the move, but as of now it only moves in a straight line.
That won’t get it past the enemies! Now that you’ve programmed the sprite to “launch” whenthe spacebar is pressed, you need to program it to turn when the arrow keys are pressed.
Watch this screencast to learn how to create that programming, then try it on your own.
Drag out 2 “when key pressed” events, and change the values to left arrow and right arrow.
Then, add the appropriate turn blocks to each arrow.
Test your code to make sure the the sprite is turning properly when you press the arrow keys.
You’ll notice that there’s a problem herethat you’ve run into before. The sprites turn when the arrow key is held down,but they don’t turn smoothly. To fix this, you’ll need to program this to say,“When the arrow key is pressed, repeat turning until the arrow key is no longer being pressed.”
This will ensure that the sprite turns smoothlywhen the key is pressed and held down. Go to the control menu and select a “repeat until” blockto put around one of the turns.
Because you’ll have to program this twice, it’s a good idea to try it on one turn,see if it works, then copy the code for the other turn.
Go to the operators menu and select a “not” block.
Then, go to the sensing menu, select a “key pressed” block,and change the value to the correct arrow key.
Run the code to see how it works.
Remember, as a computer scientist it’s important to test your codeat every step, to make sure that it’s doing what you want it to do.
It’s much easier to find and correct problems when you test code earlyand often before multiple problems pile up.
In the next screencast, you’ll program this game to level up with spawning enemies!