Specification of Assignment

In this assignment, you will write a simple “game” that allows a user to move a character (a circle) around the screen. An example of the game being played is shown below:

Note several things about this game:

  • The canvas is 500x500px. Each square on the grid is 100x100 pixels. These squares are called "tiles."
  • The background can be a color of your choosing (here, the color is blue).
  • Your character should start in the top-left position. The character must be a circle, but you can add to the look of the circle if you like.
  • The character can move up/left/down/right with the w/a/s/d keys, respectively.
  • The starting tile should be red.
  • There are two yellow tiles. The player should not be able to move onto a yellow tile, even if they try.
  • When the player lands on the green circle, the “You Win!” text should appear on the screen in large letters.
  • The player should be forced to stay in bounds on the grid of tiles.

The red, yellow, and green tiles should have the colors shown. You may choose any color you want for the player, borders, and background.

Also, you must:

  • Use for-loops , arrays, and recursive functions to generate the grid of tiles.
  • Use the keyPressed Boolean Variable to detect key presses. Do not use the keyPressed function.

Remember that all assignments should be written using only features that were presented in class to demonstrate your understanding of such material. Any material not covered in the lecture is considered unauthorized. For example, You must use the keyPressed Boolean variable to detect key presses. Do not use the void keyPressed () function. The assignment will be graded as Zero if you use any feature that has not been covered in the lecture. Use the slides to reference the topics that we have covered.

Development Strategy

Below are suggestions on how to implement this program. (You are not required to follow this development sequence, but you may find it helpful.) First, use for-loops to display the basic grid. Hint 1. Try drawing five squares next to each other using a for-loop. Hint 2. Try drawing five lines 100 pixels apart using a for-loop.

Next, draw the red, yellow, and green tiles. You don’t have to worry about enforcing the rules with the yellow or green tiles yet, just get them drawn.

Next, draw the player so that it begins on the top-left tile.

Next, get the player movement working. Make sure that you can properly detect that the player has won. You’ll need to use if-statements for both of these tasks. Don’t yet worry about blocking the yellow tiles or the borders.

Lastly, add some extra if-statements (or change ones you already wrote) so that the player stays on the canvas and cannot go over a yellow tile.

Comments and Style

Name the file game.pde.

Note: A portion of your score on this assignment will awarded based on your comments and style. Your programming should be well-formatted and easy for the graders to read and comprehend. You should follow the style guidelines that we have discussed in class. (See the lecture slides for reference.)

Each program file should have a header comment at the top that has roughly the following format:


/* Author: Student Name
 * Description:
 *    A short description of what this program does!
 */ 

To help with readability, use comments to separate your program’s main tasks and describe what the code is doing. For example,


// check for key presses
// if the 'w' key is pressed, move up

In general, you should follow the coding style guidelines covered in the lecture. That means that in addition to using comments, use blank lines to separate the key parts of your code. Also, all of your code should be properly intented, your variable names should be well-chosen and you should use camelCase for longer variable names.

Grading Rubric

Points Requirement
2 Name the file game.pde (autograder).
7 Use for-loops to generate the 5x5 grid of tiles. Each square on the grid is 100x100 pixels
6 Your character should start in the top-left position and the tile is red
7 The character can move up/left/down/right with the w/a/s/d keys, respectively.
7 There are two yellow tiles. The player should not be able to move onto a yellow tile, even if they try.
6 When the player lands on the green circle, the “You Win!” text should appear on the screen in large letters.
6 The player should be forced to stay in bounds on the grid of tiles.
3 Style