You are currently using an older browser. Please update to the latest browser to ensure features and pages work properly. Learn more
2. Let's Move!
To make the cooperative game work,the characters need to move.
Click on the blue android sprite to start.
The player will press the right arrow keyto make the sprite move right.
From the Events menu, drag out theWhen Key Pressed Blockand select right arrow from the drop-down menu.
To make the sprite move when the key is pressed,place the Move Ten Steps blockfrom the motion menu under the When Key Press Block.
Press the right arrow to test your code.
The character moves but it looks kind of twitchy.
To make the character move more smoothly,make it repeat moving until the right arrow keyis no longer pressed.
From the Control menu, place the Repeat Until Blockaround the the Move 10 Steps Block.
The character should keep movinguntil the right arrow key is not pressed.
From the Operators menu, place a Not Operatorinside the Repeat Until Block.
Then, from the the Sensing Menu,place a Key Pressed Block inside the Not Operator.
Click the drop down and select right arrow for the key.
Now the code reads, when the right arrow key is pressedkeep moving 10 steps until the right arrow keyis not pressed anymore.
Test the code by pressing the right arrow.
The android moves more smoothly now.
To catch objects in the gamethe android needs to move left as well.
The code that makes the android move leftis almost the same as what you just createdto make it move right.
So you can copy the code to save yourself time and effort.
To copy your code, right click on the top of the code stackand click duplicate.
A new identical block stack should appear.
Next, change the names of the key in the new stack.
Click the drop down on the When Key Pressed Blockand change it from right arrow to left arrow.
Do the same for right arrow in the condition.
Finally, make the character move left instead of rightby changing the 10 in the Move 10 Steps Block,to a negative 10.
Test your code.
When you press the right arrow,the character should move right,and when you press the left arrow, it should move left.
The other character in the game needs to move as well.
You will program the yellow androidthe same way you programmed the blue one.
Drag both stacks of code fromthe blue android to the yellow android in the sprite's area.
Click on the yellow android.
It should now have the same code as the blue android,but you and your friend can't use the same keys to play.
Typically, when two players are using the same keyboardone uses the arrows, and the other usesthe W, A, S, and D keysbecause they have a similar configuration to the arrow keysbut are located on the other side of the keyboard.
Click on the drop downs to change left arrow to A,and right arrow to D on the Event and Sensing Blocks.
Test by pressing the A and D keys.
The yellow android moves left and right.
Now it's your turn.
Program the blue android to move right and leftusing When Key Pressed, Move, Key Press,Not, and Repeat Until Blocks.
Copy both stacks of code to the other character's spriteand make it move when the A and D keys are pressed.
Program the blue android to move right and left using "when key pressed," "move," "key pressed," "not," and "repeat until" blocks.
Copy both stacks of code to the other character sprite, and make it move when the "a" and "d" keys are pressed.