Extending Soccer

posted by: Ms. Martin 20 September 2010 No Comment

Now that we have structs, we can create a single game with both the ball and the goalie. The information that defines each frame now has two pieces: the x-coordinate of the ball and the y-coordinate of the goalie. We need to create a struct to hold these and to extend the functions for drawing, moving, and reacting to inputs to consume and return these structs instead of single coordinates.

  1. Write a data definition and examples of data for a struct for a game, which has both a ball and a goalie. Each is represented with a single coordinate.
  2. Write a function render-game that consumes a game struct and produces a scene containing both a ball and a goalie. Reuse your old functions wherever possible!
  3. Write a function next-game that consumes a game and produces a new game. In the new game, the ball should change using your old next-ball function and the goalie should be unchanged.
  4. Write a function react-game that consumes a game and a key and produces a game. In the returned game, the ball should be unchanged and the goalie should change using your old react-goalie function.
  5. Put it all together using the following commands:
    (define (soccer-sim init-world)
      (big-bang init-world
    	    (on-tick next-game 1/28)
    	    (on-draw render-game)
    	    (on-key react-game)))
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>