how to script obstacles in scratch

Game Development: How to Script Obstacles

Games should be fun and just the right level of challenge. They shouldn’t be too easy, so that the player finishes quickly and has no incentive to play again. And games should not be too hard. Then the player may give up and abandon play. One way to inspire and motivate players is to script obstacles or traps that slow progress. By facing and successfully evading ugly ogres, black holes, or alien blasters, players get a sense of accomplishment. And if they have to try several times to avoid the traps and complete the game, the feeling of victory is that much better.

Script Obstacles

technorace

In TechnoRace, students use Scratch to become game developers. They build an imaginary rescue mission. Players must race against time to collect points. To obstruct progress, obstacles are added that must be evaded. They might be diving fireballs, stinging ladybugs, or evil robots. But once the obstacles have been chosen, what creative effects can be scripted to make the game captivating and fun?

What Are the Consequences?

Although at first glance Scratch blocks seem to be simple programming tools, they are much more! Game developers can create an infinite variety of effects and actions. Here are just a few ideas to script obstacles to entertain, puzzle, and slow game players.

Start Over

When the player touches an obstacle, make them go back to the start of the game.

Select the player sprite. Code the follow script, using a forever block to ensure that the action will always occur. An if-then statement runs the code whenever the condition is true. Add the sensing block to recognize when the player makes contact with the obstacle. Then use the x/y co-ordinates of the start point to set the consequence.

script obstacles

Get Sent to a Trap

Another idea is to add a sprite that represents a trap. If the player touches the obstacle, they are immediately sent to that trap sprite. It could be an open-mouthed shark, a hungry monster, or a dark, scary cave.

Replace the go to x:  y: block with a go to block and click the arrow to select the trap sprite.

obstacle script

Freeze!

To stop the player momentarily, replace the go to x:  y: block with a glide block. Drag the current x position and y position motion blocks into it. Decide how long the player will be penalized. This is a harsh result if a timer is running!

script obstacles

And Lots More…

Your imagination is the only limit to the effects an obstacle can cause. Here are a few more to keep your game unique and fun to play.

  • Back Up: Revert the player up to a previous position or move a number of steps back.
  • Change Appearance: Adjust the player in size by making it shrink temporarily. Or use the looks blocks to experiment with the selection of effects: color, fisheye, whirl, ghost, and more. If the player has multiple costumes, loop them to show action.
  • Play a Sound: Have a sound occur upon contact with the obstacle. Check out the sounds library for some terrific sounds in the Wacky category.
  • Say Something: Use a looks block to make the character talk, for example, “Ouch!” “Oh no.” “Yikes!”
  • Penalty Points: If the game has a point system, deduct points when contact is made between the player and the obstacle.
  • Code the Obstacle: You can also add any of the above effects to the script of the obstacle. If it touches the player, will you make it say something, get bigger, animate by changing costumes, or … ?

Script Obstacles to Boost Game Engagement

All the above ideas and scripts are from TechnoRace, TechnoKids’ recent Scratch project for elementary students. The resources include a teacher guide, student workbook, assessment tools, sample games, optional enrichment activities, and more. Turn your students into young game developers!

script obstacles
In TechnoRace, students program a game with a player, goal, obstacles, timer, and score.
Scroll to Top