6 Flying Pigs
Platform games usually have some enemy characters that patrol the levels, getting in the way of your character at key times. To start things off for you, a flying pig graphic has been provided.
The pigs will fly horizontally across the screen and will take some of the player's health if they bump into it.
We will use a marker object to determine the flight path of the pig. The marker will not be visible or solid and will have no other role in the game. The following link will lead you to the image,
Create a sprite for the marker and call it spr_marker,
The pig will have to fly left and right. Start by creating a sprite called spr_pigl, this will contain the image of the pig flying to the left.
Now create a sprite called spr_pigr. Load the pig graphic again. Click on Edit Sprite, then go to the Transform menu and choose Mirror Horizontal. This should turn your image to face the opposite direction like so,
Create an object called obj_marker and complete the window exactly as shown below,
Create an object call obj_pig and load the right facing pig graphic.
Pigs In Flight
Go to your game room and find mark off a flight path with a marker at each end. Place the markers at exactly the same height, the pig will turn around when it hits a marker. Place the pig object somewhere in between the two markers.
Now go to the pig object window and add a Create Event. Drag in a Move Fixed action and complete the pop-up as shown,
Create a Collision Event with the marker. Here we need to work out which direction the pig is moving and turn it around the other way. The following series of actions will do this,
The first Move Fixed action makes the pig move to the left at speed 5, the second one moves to the right.
Save and test that you have made this work properly. Nothing should happen when the character touches the pig, but the pig should be flying like a good 'un.
We have to take a bit of care when working out the actions for the collision between the character and pig objects. If the pig moves across the character, it will collide with it many times and kill the character outright. We only want to nibble a little of the health away and allow the player to continue. We therefore have to develop some temporary pig immunity for the character.
Go to the character object window and a Create Event. Drag in a Set Variable action and set the variable immune to 0. When the value of this variable is less than zero, the character is not immune to the pigs.
Now go to the Begin Step Event and drag in another Set Variable action. Fill it in like so,
The Collision Event with the pig should be completed as follows,
Save and test the game so far.