Monsters Moving

Monster moving back & forth

Go into the object monster. Start with a Create event and set it to Move to the right at speed 4.

When the monster hits a block, it needs to reverse horizontal direction.

Add a Collision with marker event and set it to reverse direction.

Facing Direction

To have the monster facing the right direction, we need the End Step event. This event happens just before the instances are drawn. In it we set the correct sprite based on the the horizontal speed. If it is larger than 0 we let the monster face right and otherwise we let it face left.

  • Test Variable: if hspeed > 0
  • If it is, then Change Sprite to monsterR
  • Else
  • Change Sprite to monsterL

Room

  • add monsters on the floor and platforms (not in the air) as shown below
  • add markers just past the edges of platforms so they don’t fall off.

Save and test it out. If they work, keep going…

Flying Monsters

Go into the object monsterFlying . Start with a Create event and set it to Move to the right at speed 4.

When the monster hits a block, it needs to reverse horizontal direction.

Add a Collision with marker event where it also makes the monster reverse direction horizontally.

Change direction sprites

Add an End Step event and change the sprites to the flying monsters.

  • Test Variable: if hspeed > 0
  • If it is, then Change Sprite to monsterFlyingR
  • Else
  • Change Sprite to monsterFlyingL

Add to your rooms

Go into your room and place a few of the flying monsters in the air. Use markers to limit how far across the monsters can go.

  • have some monsters going across the whole room (near the top, by the clouds)
  • have some monsters only going across a small section or half of the room
  • markers can be in the bottom square row of the monster’s body, or the top square row

Losing Lives

Obj: character

Go into character object and duplicate Collision with death to create the Collision with monster

Duplicate it again for the Collision with monsterFlying

Test out your game. When you run into either of the monsters, you should lose a life and see it go down in the score panel.

Squishing Monsters

We want to make it so we squish/kill the flat monsters if our character jumps on top of it. In order to do this we have to have 2 conditions met:

Condition #1: The player should be moving downwards

vspeed > 0

Condition #2: The player has to be above the monster (or at least 8 pixels below the top of the monster)

y < other.y + 8

Person Jump on Monster

Go into your character object and then into the Collision with monster event.

Add the following actions at the top:

  1. Test Expression: copy the following code…
    vspeed > 0 and y < other.y + 8
  1. Change Instance: set to other (so monster, not character) and then change into monsterDead object, perform “yes”
  1. Set Score: give player 50 points (make sure relative)
  2. Move Fixed: center, speed 0 (so doesn’t move)

Add Start & End blocks with an Else to separate them…

Monster Dead

Go into the monsterDead object.

  • Create event – Set Alarm0 to 10 steps
  • Alarm0 event – Destroy Instance

Save and test the game.

Jump on the monster in the first room and make sure it works.

Shooting Monsters

Destroy bullet

We’ll set it up so it’ll be destroyed if it hits a wall or goes outside the room.

Go into the bullet object and add the following events:

  • Collision with block
    • Destroy Instance
  • Outside Room
    • Destroy Instance

Kill monsters

We’ll also set it to kill the monsters when the bullet hits it. Create the Collision with one of the monsters:

  • Collision with monster
    • Set Score: give player 50 points
    • Destroy Instance (other = monster)
    • Destroy Instance (self = bullet)

Then duplicate it for the flying monster…

Getting Ammo

To make things a bit more interesting, the player first needs to find some ammunition to be able to shoot. To this end we introduce a variable we call ammo that indicates how much ammunition the player has – it has to be this name, it can’t be the same name as the object/sprite so ammunition won’t work.

Go into your character object and add a Create event.

  • Set Variable: variable = “ammo” and value = “0” to start.
    The player can’t shoot until they’ve picked up the gun/ammunition

Then add a Collision with ammunition event.

  • Set Variable: pick up the gun = set variable “ammo” = 10, relative
  • Destroy Instance: other (=gun, not character!)

Shooting bullets

Still in the character object, add a Press <Space> to make it so every time the player presses the Space Bar, they can shoot.

It’s under Key Press (not Keyboard) and

  • Test Variable: is variable “ammo” > 0?

Add Start & End blocks…

We have to do some testing – which direction is the character facing? That’s the direction we want to shoot the bullets…

  • Inside those blocks, start adding actions::
    • Test Variable: check if our character is facing left
      variable “sprite_index” = value “characterL”?
  • Create Moving: then we shoot a bullet to the left
    object “bullet”, x=0, y=0, speed=12, direction=180, and relative
  • Else
  • Create Moving: otherwise shoot bullet to the right; can duplicate other one, only difference is the direction
    object “bullet”, x=0, y=0, speed=12, direction=0, relative
  • Set Variable: once it shoots, take away a bit of ammo
    set variable “ammo” to “-1”, relative

It should end up looking like this…

Put the gun in the room near the character and test it out – if you pick it up, can you shoot to the right and kill the monster? does it disappear? can you shoot to the left?

Score Panel

Go into the controller object. We want to have the gun sprite show up in the score panel when the player picks it up to show they can shoot. Go into the Draw event and at the end add 2 more actions:

  • Test Variable: test and see if player has any ammo
    character.ammo > 0
    Note: the variable is characterObjectName.variableAmmoName so if you’ve named your stuff any different than in my instructions, it won’t work unless you make your names match.
  • Draw Sprite: sprite = “ammunition”, x=”60″, y=”10″ (subimg = 0)

Room

Save and test the game.

When you pick up the gun, you should see it in the score panel…

If all the monster stuff is working, keep your game open and get it checked off.