Book Image

Scratch 2.0 Game Development Hotshot

Book Image

Scratch 2.0 Game Development Hotshot

Overview of this book

Table of Contents (18 chapters)
Scratch 2.0 Game Development HOTSHOT
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a level generator


We will add a script to the sprite we just created that selects a costume at random and copies it onto the stage. With a double for loop, we will make sure the tile generator steps around the entire stage, so no space is left blank.

Prepare for lift off

To set up this game, we will create a small control script in the Stage object to set everything in motion as follows:

  1. Start a new script with the when <space> key pressed block.

  2. Attach a broadcast message to this.

  3. For the message, type createMaze:

This message will trigger when a new maze should be generated. It can be activated by pressing the Spacebar key and at a later stage, through the script when the player completes a level.

Engage thrusters

With the basics out of the way, we can start with the fun stuff; drawing levels automatically. We will draw the level from the lower-left to the upper-right of the screen using the following steps:

  1. Go to the script tab of the tileGenerator sprite.

  2. Start a new script with...