Click Alonzo Game

Please note, this is a adaptation of the student-facing pages and was designed for use in a brief conference session. The complete student-facing version is available on bjc.edc.org: Unit 1 Lab 1 Page 1: Getting Started with Snap!, Unit 1 Lab 1 Page 2: Programming a Game, Unit 1 Lab 1 Page 3: Sharing Your Game, Unit 1 Lab 1 Page 4: Giving the Player Feedback, and Unit 1 Lab 1 Page 5.

On this page, you'll build a simple game in which the player tries to click a character that's jumping around.

Making a Character Move

Yellow Is for Optional Reading

Alonzo character This is Alonzo, the mascot of our programming language, Snap!. You should see him on the stage, the white area in the top right corner of the Snap! window.

picture of Snap! window with white rectangle at right labeled 'Stage' and yellow character on that stage labeled 'Sprite named Alonzo'

  1. Click here to load a starter project in Snap! It contains two costumes for the Alonzo sprite: Alonzo character Alonzo character flipped to face the other way
  2. Make Alonzo jump someplace else on the stage when he's clicked; drag these two blocks into the scripting area (the center area of the window):
    when I am clicked, go to [random position]
    CRD-2.B.1

    Finding Blocks

    I refined the presentation of the supports in this problem, and we might want to consider using them in the students version also. --MF, 10/24/20

    You can find blocks in palettes with their matching color. Drag one block underneath another to snap them together.

    Palette categories: Motion, Looks, Sound, Pen, Control, Sensing, Operators, and Variables

    The go to () block appears in the palette without the "random position" option selected from the menu; you will have to choose that option by clicking the triangle to open the menu.
    go to () block with menu open showing 'random position', 'mouse pointer', and 'center'. The mouse pointer is hovering over 'random position'.

  3. Test your program: Click on the Alonzo sprite on the stage several times. If your program works, Alonzo should move to a random position on the stage each time you click him.
  4. If your program doesn't work, look back at the picture of the desired code and make sure yours matches exactly.
    • Make sure the two blocks are attached to each other by moving the when I am clicked block and checking that the go to block moves with it.
    • Make sure that the first block says when I am (clicked) and not something else, and make sure that the second block says go to (random position) and not something else.

Making the Game Challenging

The game isn't much fun if Alonzo just sits there waiting to be clicked. Once you've clicked him, he should keep jumping around on his own. To make Alonzo keep moving around, you need a block that says "do this forever." And there is a block that does it:
forever

  1. A bunch of blocks clicked together is called a script.
    Attach this to the bottom of your Alonzo script:
    forever {
    go to (random position)
}
    The sequence of blocks inside the forever block will repeat until you click the red stop sign, red stop button, or stop the script in some other way.
  2. Alonzo moves too fast. Use the wait 1 secs block to slow him down. (You will have to determine where it goes.) Try your program, and increase or reduce the wait time if you like.
    Where the wait block goes in your script matters. Do you want the script to wait one time or each time Alonzo moves?

Confirming Whether Alonzo Was Clicked

Now the game is challenging, but players can't tell how well they're doing because Alonzo jumps around whether the player clicks him or not. You will create a way for the player of your game to know how well they are doing.

: Sprites and Costumes

The Alonzo character is named after Alonzo Church, a major contributor to early computer science. In this project, there are three objects related to Alonzo:

Program Alonzo to face the other way when clicked so that the player will know right away whether they succeeded at clicking Alonzo before he moved. Alonzo character Alonzo character flipped to face the other way
  1. The project you loaded has two Alonzo costumes—one facing right and the other facing left—so you can use the next costume block to make the sprite face the other way. Add the next costume block to the place in your program where the user has just clicked on Alonzo.
  2. Test your program. Make sure Alonzo faces the other way when he is clicked but not when he jumps without being clicked.

Keeping Score

The player will also want to know how much progress they have made in the game. The command change (ghost) effect by () can control Alonzo's transparency.

Optional Reading for the Conference Format

The transparency of an image is how much you can see what's behind it. For example, here is the Alonzo sprite shown with three different transparencies (which have been set using the ghost effect block).
three pictures of Alonzo, with ghost effect 0%, 25%, and 50%, on a background of a brick wall

Use transparency to tell the user how close they are to winning: every time they click, Alonzo gets more invisible, and when he disappears completely, they win the game.

  1. Drag the change (ghost) effect block into the center scripting area, and experiment with different input numbers (clicking it repeatedly after each change) to see exactly what it does. At what ghost effect value does Alonzo become completely invisible? You can use the command clear graphic effects to make Alonzo fully opaque again.
  2. Then, modify your script so that every time Alonzo is clicked, he gets a little more ghostly. Think about how the input you use affects the length of the game. Try out your game.

Ending the Game

When Alonzo is completely transparent, the game should stop.

  1. Add this code to the right place in your script to end the game.
    if ((ghost effect) = 100) {clear graphic effects, stop all}
  2. If you want to save your work, open the Snap! File menu (File menu button) and choose save. You can either save the file to your computer, or if you have a Snap! account, you can save it to the Snap! cloud.

    Creating an Account

    In the Snap! window, click the Cloud menu, Cloud menu button, select "Signup...", and follow the instructions.
    cloud icon

    You'll be asked to click a link in your email to verify your account, but you don't have to do that right now.

    You may change your password at any time using the Cloud menu, Cloud menu button.

Making the Game Even More Challenging

The way the game is currently written, even a bad player will eventually make Alonzo disappear. The game will be much more interesting if the player is penalized for missing a click.

Students can click links like the one below to access extension activities.
  1. Figure out where to add a change (ghost) effect by (-5) block to your script to make Alonzo get less transparent any time he moves without being clicked.
  2. Play your game a few times, and adjust your code to get a level of difficulty that you like.
  3. You can change the ghost effect input number (for either instance of the block) and/or the wait time to make the game easier or harder.