1

How can i put two objects with its own coordinates

(define padle1 (rectangle 10 30 "solid" "red"))
(define padle2 (rectangle 10 30 "solid" "red"))
(define (place-dot-at ... ) ...)

into bin-bang function

(big-bang ...
[to-draw place-dot-at])

Can i use list of padles

(define new-list (list padle1 padle2))
Leif Andersen
  • 19,065
  • 16
  • 62
  • 92
demsee
  • 53
  • 6

2 Answers2

3

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])
Alex Lew
  • 1,724
  • 12
  • 17
1

I recommend making a draw-paddle function that draws a single paddle on top of an image i.

(define (draw-paddle p i)
   (overlay/xy (rectangle ...)  ; the paddle
               50 70            ; coordinates on paddle on screen
               i))              ; image of what's previously drawn

Then make a function that draws all paddles in a list on top of an image i.

(define (draw-paddles ps i)
   (cond
      [(empty? ps) i]           ; no more paddles to draw
      [else        (draw-paddles 
                        (rest ps)       ; draw the rest of the paddles on top
                        (draw-paddle (first p) i))])) ; of the first paddle
                                                      ; ontop of i

Then finally you can made:

 (define (on-draw state)
     (draw-paddles (list paddle1 paddle2) my-background))

If you don't have a background you can make one with empty-image or rectangle.

soegaard
  • 28,660
  • 4
  • 50
  • 97