If your game is working and…
-
both the
Danger
andTarget
return to the screen -
your
Player
moves up and down with the arrow keys -
you’ve completed Challenge: Character Movement in Two Dimensions
-
your
Danger
is moving diagonally
you have all the tools you need to work through this Design Recipe and get your player moving in all four directions!
Write a new function update-player-2
that takes in the player’s x-coordinate, y-coordinate, and an arrow key (described by a String) and moves the player to a new Posn. Your goal is to get all 4 arrow keys working as you would expect them to by moving the player 50 pixels in the corresponding direction!
Contract and Purpose Statement |
Every contract has three parts…
_______________::______________________->____
_
Examples |
Write some examples, then circle and label what changes…
examples:
_______________ (____________) is _________________
_______________ (______________) is _________________
_______________ (______________) is _________________
_______________ (_______________) is _________________
end
Definition |
Write the definition, giving variable names to all your input values…
fun _______________(___):
___________________________
_____________________________
_____________________________
______________________________
__________
end
end
Follow the directions on Challenge: Character Movement in Two Dimensions (2) for adding your new function to your game file, this time changing update-player
to update-player-2
.
Once you’ve mastered 2-dimensional movement, you might want to add secret functionality for some of your favorite letters on the keyboard…
These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, 1738598, 2031479, and 1501927).
Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.