Build a Paintball Game (part 2 of 6)

Tagged:

Previous: Setup (part 1 of 6)

Movement

In first person player games, there must be some way for the player to control the movement of the player's character. We will program keyboard arrow keys to make Mario move.  For instance, the up arrow key moves Mario forward 1, the down arrow key moves Mario backward 1, and the left and right arrow keys make him turn in place. Let's begin by defining a "Move" procedure. Grab a procedure block from the Procedures tab. Put this on the Mario section of the canvas and rename it Move. 

Grab an If block from the Logic tab and attach it underneath the Move procedure hat. For the test condition, go to the Controls tab and grab a block that says "keyboard up arrow?". This block will only be true when someone is pressing the up arrow key. In the Then section of the block, attach a Forward block.

Bring out another If block (or copy the one that is out there using control/command-c to copy and control/command-v to paste) and instead of the up arrow key, use the drop-down menu to change this to the down arrow key. Change the movement block to Back 1.



Copy the If block again, and change the key to be the left arrow key. Change the movement block to Left, and the argument to 15, for 15 degrees.

Finally, repeat that last step only using a right arrow key and a right 15 block. This can all be easily done by copying the last block you used and changing the conditions.

Drag out a Forever block onto the Runtime section of the canvas. Note that there are three sections in the Forever block, one for each breed. Rename the Forever block to Start Game.

Drag out a Move call block from the Mario drawer (My Blocks palette) and attach it to the Mario section of the Forever block.

Now start the Forever block by clicking on the Start Game button in the Runtime window or clicking on the green arrow in the Start Game block on the canvas. Try navigating around using the arrow keys. See how Mario moves around the world.

Notice that the turtles aren't moving. To make them move, drag a Forward block to the Turtles section of the Start Game (forever) block. Then start the game and see the turtles move.

Next: Launching Paintballs (part 3 of 6) Back To Top