Csu211 Sp '08
 
Assignments
The Hand In
The Recipes
The World
Set 1
Set 2
Set 3
Set 4
Set 5
Set 6
Set 7
Set 8
Set 9
Set 10
Set 11
Set 12-X

Problem Set 8

Due date: 3/12 @ 6pm


The goal of this problem set is to study the design of a small game program. Designing this program will demonstrate how the design recipe scales up to a first interesting program.


The Problem:

Imagine that you're on Co-op and you've been given the task of designing the prototype of a retro-game, Brick-Out, a spin off of the Atari Classic.

In this game, the player is in control of a paddle, that is allowed to move side to side, near the bottom of the screen. A ball is always moving diagonally; bouncing (changing direction) off the sidess and top of the screen and the paddle if it's in the right spot.

At the top of the screen there is a number of blocks (called bricks in our case). When the ball hits a brick the brick disappears and the ball changes direction depending on which side of the brick was hit.

The game ends when all the bricks are gone (You Win!!) or if the ball drops below the height of the paddle (You Lose!!).

Important: For this version, I would like you to construct a board with five (5) rows of eight (8) Bricks. These will then be removed as the player bounces the ball off of them. Here's an example image after a few brick removals.

To get you started, Here's a few Data Definitions; namely what the World is and what it has in it:

      ;; * * * * * * Data Definitions * * * * * *

      ;; List of possible Brick Colors
      (define colors (list 'red 'purple 'blue 'green 
                           'yellow 'magenta 'gray))
      
      ;; A Brick is:
      ;;    (make-brick Number Number Symbol)
      (define-struct brick (x y color))

      ;; Meaning:
      ;; (x,y) is the center of the Brick in the Screen, and the color is a
      ;;   symbol that represents the color of the Brick (from the above list)
      
      
      ;; A LoBrick is either:
      ;;   -- empty, or
      ;;   -- (cons Brick LoBrick)

      ;; A World is:
      ;;   (make-world Posn LoBrick Number Posn)
      (define-struct world (ball bricks padx dir))

      ;; Meaning:
      ;; ball is the current position of the ball in the screen, bricks is the
      ;;   list of remaining bricks, padx is the current x coordinate of the
      ;;   paddle, and dir is the current x/y velocity (speed and direction) of
      ;;   the ball
          
We've done inside/outside tests for rectangles in earlier assignments... those ideas will be useful here. But, remember that the Brick position represents its center, so they will be a little different!

Bouncing of the Ball is a little harder (requires a little Math) so we've provided you with two functions... it's up to you to figure out how to use them though.

Assuming you've defined a few constants: brick-width and brick-height here are some helper functions:

      ;; bounce-direct: Posn Number Number -> Symbol
      ;; Approximate the bounce of a Ball based on (x,y) being the Center of a
      ;;   brick that has been hit.  Returns 'updown or 'leftright depending on
      ;;   where the point is in relation to the brick
      (define (bounce-direct p x y)
        (local ((define px (posn-x p))
                (define py (posn-y p)))
          (cond [(or (< py (- y (/ brick-height 2)))
                     (> py (+ y (/ brick-height 2)))) 'updown]
                [(or (< px (- x (/ brick-width 2)))
                     (> px (+ x (/ brick-width 2)))) 'leftright])))
      
      ;; bounce: World Symbol -> World
      ;; Bounce the ball based on the given symbol ('updown or 'leftright)
      (define (bounce w sym)
        (make-world (world-ball w) (world-bricks w) (world-padx w)
                    (cond [(symbol=? 'updown sym) 
                           (make-posn (posn-x (world-dir w)) (- (posn-y (world-dir w))))]
                          [(symbol=? 'leftright sym)
                           (make-posn (- (posn-x (world-dir w))) (posn-y (world-dir w)))])))
      

Hints:

  • Start early... you will need some time to figure things out.
  • I suggest you start by designing a function to create a world with a number of rows/columns of blocks. Then design functions to draw all the elements of the World. Then you can start with the interactive functions
  • When you get to a point where the game should end (Win or Lose), use the world.ss function end-of-time. This function takes a String and, as its name suggests, stops everything related to the big-bang. Use the string to tell the player what happened (something like "You Win!" or "Game Over!").
  • You may implement more features, if you like (e.g., scoring, increasing speed, or game pausing). However, extra features won't save you from points taken off if your code has bugs or isn't well written.

    You will not receive 100% credit simply for having code that works. For full credit, your code must work and be well written. So you should put your effort into writing clean, readable, bug-free code.
  • You will be upgrading the game to full featured Brick-out in a future assignment. So effort expended in making sure that your code is clean and well-written will be rewarded when you have to extend it later --- it is quite difficult to modify and extend code that is a snarled-up, confused pile of chaos.
  • If you have trouble be sure to see a Tutor, the TA or the Instructor. But... be sure to come with specific questions and or examples. We will not be able to answer any vague questions like: "Why doesn't my code work?" or "How do I do the bricks?"


last updated on Fri Apr 4 11:29:56 EDT 2008generated with PLT Scheme