Scrambling Sprites in Scratch

My advanced scratchers were looking for a challenging project with a superhero theme. We came up with a Q&A game where the player discovers their natural superhero affinity. This game was patterned after the Hogwarts game in the CreateCodeLoad 30 day challenge. Here’s a link to the demo version of the game:

The kids came up with a bunch of questions and provided answers that would match their favorites: Captain America, Wonder Woman, Flash, and Michaelangelo. We created a sprite for each of the four superheroes. Their answers were on costumes 1 – 10. Each hero’s picture was on a couple of other costumes to be used for different stages of the game.

The four superhero sprites were arranged in a 2×2 grid. The challenge was that we didn’t want the same sprite’s answers to always appear in the same location on the grid. So we needed a way to scramble the location of the sprites for each turn. We did this randomizing by using a list variable named Position.

Each turn, there was an event that loaded the Position list with four numbers. The process was as follows:

  1. Empty the list
  2. Set the index counter to 1
  3. Load four buckets in the list with 0
  4. Repeat until the list does not contain 0
    1. Set Dice to a random number between 1 and 4
    2. If the list does not contain Dice value, put the dice value in the bucket with number index and change index by 1
superhero skills chart for game design

Each bucket in Position corresponded to a superhero. Whatever number was in the superhero’s bucket, that’s the grid position where the sprite appeared. We used two other lists, PositionX and PositionY. These were preloaded with the X and Y coordinates for each grid position. After the Position list was populated, each sprite went to the coordinates associated with the number assigned in the randomizing process.

This was the most challenging part of the game. It was good that each kid in the Advanced group was working with an adult. Between the two they could troubleshoot any issues they had in the logic. I made a short video to explain the process and loaded it to Paula’s YouTube channel:


Read our latest posts

We love to write as much as teach. Get geeked for our latest posts and announcements.