big-bang
stores only one piece of information, usually called the "world state." All the functions that work with big-bang
, like your drawing function, tick handler, and so on, must accept that world state as a single parameter.
It's up to you to decide what to store in your world state. If you want to store two locations (one for each paddle), a list or struct is the way to go. For instance, here is how you might define a struct called world
that can hold two positions at once.
; Create a type called `world` that holds two locations.
(define-struct world [paddle1 paddle2])
; Create a variable to store the initial state of the world.
(define initial-world (make-world (make-posn 0 100) (make-posn 300 100)))
When you write your drawing function, it must accept the entire world state at once:
(define (draw-game world)
(place-image
paddle1
(posn-x (world-paddle1 world))
(posn-y (world-paddle1 world))
(place-image
paddle2
(posn-x (world-paddle2 world))
(posn-y (world-paddle2 world))
BACKGROUND)))
In your big-bang
, treat the world state like any other kind of data:
(big-bang
initial-world
[to-draw draw-game])