On this page:
Chip the Cheap Sheep
Multiple Sheep

Lab 5 A Bunch of Sheep

home work!

Purpose The purpose of this lab is to give you some hands-on experience with designing a world program with multiple sprites.

image

Chip the Cheap Sheep

Note: This section is a repeat from Lab 3. If you didn’t get to it, do it now. If you have the code already, start from that. If you did it and lost the code, redo the minimum to get to the "Multiple Sheep" section below.

Switch roles

An animation studio is working on a game called "Chip, the Cheap Sheep". They have some basic idea, and that is to have a sheep running across the screen. Here are some sheep shapes that their artist has drawn:

You should be able to drag the images from the webpage into DrRacket, once they are there you should know what to do. If not save them to the desktop, and use "Insert">"Insert Image..." from the DrRacket menu bar.

0

 

1

 

2

 

3

 

 

 

Your goal is to create a simple proof-of-concept game with Chip running from offscreen to the (x coordinate of the) point the player clicks on first. Before Chip runs, the screen shows the text

image

The following exercises take you through the design steps for world programs again.

Switch roles.

Exercise 1 Draw some still frames from the game. Which aspects remain the same? Which change?

Exercise 2 Gather constant definitions for the properties of the world frames that remain the same. Here are some:
(define CHIP1 ...)
...
(define WIDTH (* 20 (image-width CHIP1)))
(define HEIGHT (* 2 (image-height CHIP1)))
(define PLAYGROUND (empty-scene WIDTH HEIGHT))
...
(define TXT (text "click the mouse to get Chip running" 33 "pink"))
...

Exercise 3 Develop a structure type definition so that your program can keep track of all the quantities that change between frames.

Hint In addition to where Chip currently is, your program must know where Chip is going. After all, at the very beginning you have no clue where Chip is supposed to go.

Develop a data definition so that you can represent the state of the game. Remember that data definitions come with an interpretation and sample data.

Exercise 4 Develop a wish list. You know you need a function that renders the current state of the game. What else do you need? Which kind of events make the game transition from one state to another?

Exercise 5 Create a main function to start your world program. Here is a sketch:
; PositiveNumber -> ... class of data that big-bang manages ...
; given the animation rate, play a game of Chip, the cheap sheep
; NOTE: by supplying the animation rate you can slow down the game
(define (chip rate)
  (big-bang initial-world
            [on-tick ... what name did you choose? ... rate]
            ; add your event handlers here))
Use your answer to the previous exercise to determine which event handlers you need.

Exercise 6 Develop a template for functions that work on the state of the Chip game.

TAs: time for a short lecture on: comment with "#;" and copy-paste to re-use the template from now on.

Exercise 7 Design the function pick-chip. It takes a number between 0 and 3 and returns the corresponding image of Chip from the sequence above.

Exercise 8 Design the rendering function.

Exercise 9 Design the clock tick event handler. The function takes world and returns a world where Chip is moved to the left, toward his goal. Use the function pick-chip to change the image according to where Chip currently is. Hint Check out modulo and/or remainder.

Switch roles.

Exercise 10 Design the mouse click handler. The function that takes a world, x and y coordinates, and a mouse event and returns a new world. The new world will have the mouse’s coordinates as Chip’s new destination and Chip teleported from offscreen to a location close to the right edge.

Remember that mouse events are just strings. Be sure to ignore all mouse events except "button-down".

Exercise 11 Design a function that determines whether Chip is close to his destination. We let you choose what "close" means. Then equip the chip function from above with a stop-when clause.

Multiple Sheep

Exercise 12 Update your world definition to be a list of multiple sheep.

Exercise 13 Design a program that consists of four sheep running across the screen at the same time. Consider: Should the sheep all start in the same animation state?

Exercise 14 Add a bed. Have the sheep jump over the bed.