CSC 221: Introduction to Programming
Fall 2011

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., variables, control, functions, objects), which we will later transfer to programming in Python.

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 extremely 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.

    Finally, add a background image to the stage and music that plays in the background during the dance.

    Save your sprites 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 constantly 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 counterclockwise. 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.

    Finally, add a help feature to the project. The user should be able to ask for help by hitting the space bar. As a result, the list of possible command keys should be listed on the stage. The user can then hit the space bar again to make the help information disappear. Note: this can be accomplished a number of ways, e.g., having a separate background that includes the text, hiding and showing a sprite made up of text, etc.

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

  3. Create an animation that contains two characters acting out a knock-knock joke. The two characters should enter the stage (perhaps with a door between them) and then take turns displaying the parts of the joke. For example:
    (Character 1): Knock knock.
    (Character 2): Who's there?
    (Character 1): Mikey.
    (Character 2): Mikey who?
    (Character 1): Mikey won't fit in the lock.
    Once you have your animation working, modify it so that the joke can be easily changed. You should add two variables to the stage, one for the person's name and another for the punch line of the joke. The scripts for the two characters should then access these variables in order to act out the joke. As a result, you should be able to change the animation simply by changing the values of the variables.

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

  4. 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).

  5. 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 variable to the page that keeps track of the number of credits the player has remaining. 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: