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!
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…
(EXAMPLE (_______________ __________)________________________)
(EXAMPLE (_______________ ____________)________________________)
(EXAMPLE (_______________ ____________)________________________)
(EXAMPLE (_______________ _____________)________________________)
Definition |
Write the definition, giving variable names to all your input values…
(define (_______________ ____)
__(cond__
_____[___________________ ______________________]_____[_____________________ ______________________]_____[_____________________ ______________________]_____[______________________ ______________________]_____[____ _______________]
Follow the directions on Challenge: Character Movement in Two Dimensions (continued) 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, and 1738598).
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.