CSC 221: Computer Programming I
Spring 2010

HW 1: Programming in Scratch

This assignment will introduce you to the process of programming using the animation/game development tool Scratch. In designing, creating, and animating Scratch projects, you will be learning the fundamental concepts of programming (e.g., objects, control, variables), which we will later transfer to programming in Java.

Part 1: Scratch Exercises

In completing the Part 1 exercises, you are allowed and even encouraged to work with a partner. Having someone to bounce ideas off of and to learn from is extrememly helpful as you begin the process of programming. However, you must be careful that the work you complete and turn in is your own. This means that, even if the two of you work out a design together, each of you must enter your own version of the code. Also, be sure to acknowledge your partner in any collaborative work that you hand in.

  1. Create a new sprite of your own choosing. You might draw the sprite entirely from scratch using the Paint Editor, or perhaps start with a photo and edit it. Then, animate that sprite so that it performs a specific dance sequence when the green flag is clicked. For example, you might add a sequence of blocks to the script of that sprite so that it moves 50 steps to the right, does a full rotation, then moves back 50 steps to the left.

    Once you have tested the behavior of your sprite, add a forever loop that encloses the dance steps. Thus, clicking on the green flag should cause the sprite to repeat the dance move over and over (until the stop sign is clicked to halt the script).

    Next, modify your sprite so that it has multiple costumes. As it moves, it should rotate through the costumes, yielding a more natural looking animation. Once you have done this, make multiple copies of the sprite on the stage (using the stamp button at the top of the stage) to create a group dance.

    Save your sprite in a project named lastnameDance where lastname is your last name (e.g., reedDance).

  2. Create another sprite whose animation is controlled directly by the user. Your sprite should move along with the cursor (i.e., it constanty moves to the coordinates of the mouse). When the user clicks on the right arrow key, the sprite should rotate a set amount in the clockwise direction. Likewise, clicking on the left arrow key should rotate counterclickwise. You may add additional movements controlled by other keys.

    Once you have tested your control over the sprite, modify it so that the sprite can leave a trail as it moves. Initially, the pen should be "up," meaning the sprite does not leave a trail. Clicking the down arrow key sets the pen "down" so that a trail is left as the sprite moves. Conversely, clicking the up arrow key resets it back to "up." You may use other keys to control the color and size of the pen, as desired.

    Save your sprite in a project named lastnameDraw where lastname is your last name (e.g., reedDraw).

  3. For this exercise, you will create a simple version of the old video game Frogger. First, create a sprite (call it the frog, although it need not look like a frog) and animate it When the user clicks on an arrow key (either up, down, left, or right), the sprite should move a set number of steps in that direction. Then add several identical sprites (call them trucks) that move horizontally, back and forth across the stage at even intervals. If a truck sprite ever touches the frog, a sound should be played. Tinker with the number, placement, and speed of the truck sprites so that it is challenging to move the frog sprite from the bottom of the stage to the top, and back again. Feel free to elaborate.

    Save your project under the name lastnameFrogger where lastname is your last name (e.g., reedFrogger).

  4. Download the slots project from the class code directory and load it in Scratch. This project simulates a slot machine, displaying three identical sprites on the stage, each with 4 different costumes. When the player clicks on the lever arm at the right, each of the slot sprites spins a random number of times. A variable in the page keeps track of the number of spins. You are to make the following modifications to complete the slot machine.
    1. Modify the arm script so that it recognizes a winning spin (i.e., when all three slots are identical) and plays a celebratory sound for a winner.
    2. Add a varibale to the page that keeps track of the number of credits the player has reminaing. The player should start with 20 credits, and each spin should cost a credit. If the spin is a winner, then the player wins 13 credits (for a net gain of 12 credits).
    3. Modify the arm script so that it disallows spins if the player has no credits. That is, the script should check to see if the number of credits and only perform the spin if the number is positive.
    Feel free to add additional features to your slot machine, such as a loan for broke players or better sound effects.

    Save your project under the name lastnameSlots where lastname is your last name (e.g., reedSlots).

Part 2: Animation/Game Project

Finally, you will build upon the programming skills you developed in Part 1 to design and implement a Scratch animation or game. The content of your Scratch project is entirely up to you. It might be an animation that tells a story or explains some topic. It might be an interactive game or a puzzle. Or, it might be something completely different. Devise something you find interesting and engaging, then go for it.

At a bare minimum, your project should have the following characteristics: