Maze Game Tutorial 8 Enemies Create Sprites for Enemies Our game might be fun as it is, but adding enemies will make a more challenging and entertaining experience. Let’s create some sprites for our monsters. Click on Sprites and then Create Sprite. Name the sprite spr_enemyHorizontal. Click Load Sprite and select monster1.png. Make sure Precise Collision Checking is not selected. Click OK. Create another sprite, but call this one spr_enemyVertical. Load Sprite and select monster3.png Make sure Precise Collision Checking is not selected. Click OK. Create Object for Horizontal Enemies We’re going to have different types of enemies behave differently. Let’s start with the enemies that move horizontally. Click on Objects and then Create Object. Name it obj_enemyHorizontal and select spr_enemyHorizontal for its sprite. Click on Add Event. Click on Create. Click on the control tab. Under variables, drag out the Set Variables icon. Name the variable speed. Set the value to be something less that the player’s speed (e.g. 3). Click OK. Click on Add Event Click on Step. Pedagogical GAMES Copyright © 2012 University of Southern California Sponsored by the U.S. National Science Foundation 1 Click on the move tab. Drag the Move Fixed icon to the Actions window. Select either right or left direction. Write speed in the space for Speed. Click OK. Make Horizontal Enemies Bounce Off Walls Currently our horizontal enemies aren’t very interesting. When they reach a wall they get stuck. Let’s make it so they turn around when they get to a wall. Click on Add Event. Click on Collision. Select obj_wall Select the control tab. Drag the Set Variable icon to the Actions window. Write Speed in the variable space. Write “speed* -1” in the value space. This makes the enemy change direction when it hits wall. Click OK. Make Enemies Kill the Player We have to give the players a reason to not bump into the enemies. So, let’s kill the player if they touch an enemy. Select obj_player and add event on collision select obj_enemy. Click on the main2 tab. Drag the Display Message icon to the Actions window. Write, “Oh, No! You have been eaten by the ghost.” as the message. Click OK. Click on the main1 tab. Drag the Restart Room icon out to the Actions window. Add transition effect in the Transition box. Click OK twice. Pedagogical GAMES Copyright © 2012 University of Southern California Sponsored by the U.S. National Science Foundation 2 Click on rm_one and put a ghost in the room. Run your game and test everything. Make Vertical Moving Enemies Now let’s make the enemies that are going to move vertically in our game. Lucky for us, we can reuse a lot of our work. Click on Objects. Right click on obj_enemyHorizontal. Click on Duplicate. Change the name to obj_enemyVertical. Change the sprite to spr_enemyVertical. In the Events window, click on Step. In the Actions window, click on the Directions icon. Uncheck the horizontal directions and select a vertical direction (up or down). Click OK twice. Click on rm_two and add vertical moving enemies to the room. Run your game and test everything. Pedagogical GAMES Copyright © 2012 University of Southern California Sponsored by the U.S. National Science Foundation 3