Setting up the room

We have the player, now we need a world to place it in. Since we are making a platformer, we are going to use two types of building block: a ground object and a platform object. The ground will be impassable to the player and will be used for the outer perimeter. The platform object will allow the player to jump through and then land upon it:

  1. Create a new Sprite, spr_Ground, and load Chapter 5/Sprites/Ground.gif with Remove Background not checked. Click OK.
  2. Create a new Object, obj_Ground, and assign spr_Ground as the Sprite.
  3. Check the box for Solid. This is necessary as our collision code is looking for solid objects.
  4. Let's test this out. Create a new Room, and under the Settings tab, change the name to BossArena and change the Width to 800. We will want a good size room to fight in.
  5. Add instances of obj_Ground around the border of the room. Also add a single instance of obj_Player near the floor of the room.
  6. Run the game. At this point the player should be able to run and jump around the room, but not be able to pass through the walls or floor. You should also be able to shoot your weapon in a variety of directions. Also notice that the animation system is working as intended, with sprites changing based on the player's actions.
  7. Now to build the platforms. Create a new Sprite, spr_Platform, and load Chapter 5/Sprites/Platform.gif with Remove Background not checked. Click on OK.
  8. Create a new Object, obj_Platform, and assign spr_Platform as the Sprite.
  9. We want the platform to be solid only when the player is above it. For this we will need to create a new Script, scr_Platform_EndStep, with the following code:
    if (obj_Player.y < y) 
    {
        solid= true;
    } else {
        solid= false;
    }

    Here we compare the player's Y coordinate with the Y coordinate of the instance. If the player is above it, then the platform should be solid. Otherwise it is not solid and the player can jump through it.

  10. In obj_Platform, add a Step | End Step event and apply this script. We run this code at the end of the step because we want to change only after the player has actually moved, but before it does another forecast.
  11. Go back into the BossArena and add some platforms for the player to jump onto. The player can only jump around 128 pixels, so make sure the platforms are placed appropriately, such as can be seen below.
    Setting up the room
  12. Run the game. The player should be able to jump through the platforms and land on top.

We have successfully developed a series of systems for a platforming game. It required us to separate common elements such as the animation system and controls into unique scripts. If we were to stop here, it may feel like we did a lot of extra work for nothing. However, as we start building our boss battle, we will start reaping the rewards for this effort.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.9.169