You may copy any code you need from your Lab 1 file as you work on these exercises. Name your file lab2.
Write a data definition and examples of data for a struct for a game, which has both a ball and a goalie. (Your struct needs to represent the x-coordinate of the ball and the y-coordinate of the goalie.)
Write a function draw-game
that consumes a game struct and produces a scene containing both a ball and a goalie. Reuse your old functions
from Lab 1 wherever possible.
Write a function update-game
that consumes a game struct and produces a new game struct. In the returned game, the position of the ball should change using your old update-ball-x
function, and the goalie should be unchanged. Write
test cases for your function.
Write a function react-game
that consumes a game struct and a
string (representing a key press) and produces a game struct. In the returned game, the ball should be unchanged and the goalie should change using your old
goalie-react
function. Write test cases for your function.
Put it all together using the following commands, substituting a starting value for an-initial-game-structure (your starting value should be a struct):
(big-bang an-initial-game-structure (on-tick update-game) (to-draw draw-game) (on-key react-game))You should now get the combined effects of the ball and goalie in a single game.