John C
John C

Reputation: 39

Racket image render

I need to make a function that will display an image under another image only if the Boolean fire? is #true

here is my code:

(define (render-rocket-fire RocketState FIRE)
    (cond
     [(or (rocket-state-fire? #true))
  (place-image FIRE
             (rocket-state-pos-x RocketState)
             (+ FIRE-SKIP (rocket-state-pos-y RocketState))
             SCENE-WIDTH SCENE-HEIGHT))

  [else (

I am confused as to what to put in else to make it so that no image is displayed

Upvotes: 1

Views: 205

Answers (2)

John Clements
John Clements

Reputation: 17223

This is a really good question, and figuring it out will help you rearrange your brain in a really important way.

What you really need to do is to consult your test cases. Or, if you haven't constructed this test case, write it. Specifically: write a test case that calls render-rocket-fire with a RocketState where the "fire?" field is false. What should the result be? The answer is what should go in the 'else' field.

Upvotes: 2

ben rudgers
ben rudgers

Reputation: 3669

An outline of a procedure that conditionally combines two images based on the value of a third argument.

(define (maybe-combine-images image1 image2 my-boolean)
  (if myboolean
    (under image1 image2)
    image1)))

The if could be rewritten using a 'two-legged' cond:

(define (maybe-combine-images image1 image2 my-boolean)
  (cond 
   [myboolean (under image1 image2)]
   [else image1]))

Upvotes: 0

Related Questions