Assignment 5

An Assignment Just for Fun!!!

 

Getting Started

Step 1 - Create a simple room. Use obj_block for now, we will improve on this later.

 

Step 2 - Create an obj_character. It can be anything you want. Use something simple for now, you can improve it later

Step 3- Moving Left and Right

We will move at a speed of 4 pixels (you can change this if you want)

Left Key Event

Right Key Event

Repeat for the right key (this time x will be +4)

Step 4- Gravity

To let the character fall down we can use gravity. But it should stop moving when we hit the floor. Also, you normally want a maximum falling speed, otherwise the character will move too fast.

Create a Step Event to check if the object is in the air. If it is apply gravity. Also set the maximum vertical speed

 

Next we have to land correctly on the platform.

 

 

Add a collision event with obj_block

 

 

Step 5 - Jump

 

Finally we have to let the character jump when the up arrow key is pressed. But this must only happen when the character is currently on the floor(or the platform) . So we first test whether the position below the character creates a collision and, if so, set the vertical speed e.g. to -10. You might have to play a bit with the value of 10 for the vertical speed and may have to modify the gravity to get the effect you want.

 

 

 

 

Better Graphics

 

The Character

 

Create a character with two different sprites: one for the character facing to the left and one for the character facing to the right. If your sprite is animated you will also need a sprite for when the character is not moving.

 

 

 

 

 

 

 

On the left button change the sprite to left and on the right button change the sprite to right

 

The Platforms and Walls

 

We will use tiles for our background. Tiles are pieces of background images that are drawn at particular places in the room. They do not have associated events nor do they create collision. The good part is that they are fast and use little memory. So you can create large rooms without the need for large images.

 

To add tiles to your rooms you first need a background image that contains the tiles. Tiles in a background image preferably have a fixed size and have a little (1-pixel) border between them so that they can easily be separated. A small tileset is in the resources folder on K:Drive but you can find

 

Now, when creating a room, you can click on the tiles tab page. You can select the tile set (that is, the appropriate background resource). Now you can draw tiles by clicking on the appropriate tile and next placing them in the room, like you would do for objects. The right mouse button deletes tiles. Use your imagination to create challenging rooms. (Note that you can place tiles on different depth layers by adding layers. For example, you can make a layer of tiles that lie in front of the moving characters. We will not use them here but they are great for giving a better 3D effect.) Make the block objects invisible s0 you will not see them.

 

 

 

There might be one problem here. The 16x16 block objects will be too large to cover the background nicely. So we want to make a few other block objects of size 16x8 and 8x16. Again we make them solid. To avoid having to specify collision events with these as well, we use the parent mechanism.

 

 

 

Threats and Treats

 

Just jumping around from platform to platform is rather boring. You definitely need some more challenges and goals. In this section we treat a number of these.

 

Monsters

 

Let us first add some monsters. We will make two monsters, one that moves left and right on a platform and the other that flies left and right in the sky. Jumping on top of it can squash the first one; the second one should be avoided at all times.

 

Platform Monster

 

We need two sprites for it, one with the monster facing left and the other with the monster facing right. And we need to add invisible block to stop the monster from falling off the platform. Whenever a monster touches it, it reverses its direction of motion.

1. Start moving the monster on Create

2. Use End Step to change sprite image based on direction

 

3. Revese Horizontal direction on collision with marker(invisible) or block

4. Squashing the Monster 

Create a obj_monster_dead

When the character hits a monster, the character should die. But actually, as in most platform games we like to make it possible for the character to jump on top of the monster and squash it.

 

In the collision event of the character with the monster we will check whether we hit the monster from above to squash it.

 

 

 

 

Flying Monster

 

The flying monster is even easier. Do the same thing but in the collision event of the character with the flying monster, there is no squashing the monster

 

You might want to add some more monsters, e.g. with different speeds, to make things harder. You can also make a monster or rock that falls down or moves up and down. Just use your own imagination.

 


Pits

 

Most platform games require careful timing of jumps to avoid falling into pits. Falling into a pit normally kills the character. Add a new object, called death. This object is a red block that again is not visible. You can place it at the bottom of the pit. (In the tiled room you can put some spikes there.) In the collision event of the character with the death object it should play a sound, wait a while, and restart the room.


 

Collecting points

 

Most platform games have some mechanism in which the player can collect points. Normally you have to pick up certain objects or catch certain things. In our example the player can collect mushrooms. So we make a mushroom object. To give a bit of variation, the mushroom sprite contains 10 different mushrooms sub-images.

 

 

 

The mushroom object picks one at random upon creation using the Change Sprite action:

 

In the collision event of the character with the mushroom object:

 

- play a sound, destroy the other object (that is, the mushroom) and add 10 to the score.

In some platform games, collecting things has a more important function than just raising your score. For example, you might get an extra life when you collect enough objects. Also there might be objects that restore your health (assuming monsters don't kill you but simply weaken you), make you move faster, jump higher, etc. Try adding some of these


Next Level

 

Of course there should be a way to finish a level, so that the player can move on to the next level.

 

Create an obj_levelexit object. When the character gets there you are moved to the next level.

 

 

Make the level exit only appear when for example all mushrooms have been collected.

 

In the creation event of the obj_levelexit object, move it to a position – 100,-100 (so off the screen).

 

Now in the step event of the object we check whether the number of mushroom objects is equal to 0, and, if so, move the object back to its starting position).

 

Level 2 - More Motions

 

 

Ramps

 

 

 

It is nice if the player can walk up sloping ramps. We will do this on the left and right keys

 

Rather than just testing whether the position to the right is collision free we also test whether a position 8 pixels higher is collision free. If so we move the character there and use the landing action to move it down to the contact position.

 

Add an Else to your if's

 

 

 

Repeat with the left arrow key!!!!!!!! Remember to change + to -

 

Ladders

 

People always want ladders in platform game along which the character can move from one platform to the other. This requires a bit of work. A ladder will be represented by a thin vertical block that is invisible (the real ladder or vine or whatever is used for climbing is drawn again using tiles) and not solid. When the character is not in contact with a ladder, motion should be as before. But when it is in contact with the ladder things will be different. First of all, the character should not fall down. So in the step event we have to make a change, adding some actions that set the vertical speed and gravity to 0 when in contact with a ladder. Also we set the sprite to the climbing sprite in that case.

 

On the Step of the Character

Note: Make sure the mask of your ladder is set to full block and check your center point

The second thing that needs to change is the event for the up key. When the character is at a ladder, the up arrow key should move it up, rather than jump. Again we need a few additional actions for this. We test whether the character is in contact with a ladder and, if so, move it up a bit.

 

Add an if at the start of your up key and change the current code to an else

Do something similar for the Down Key

 


Using a view

 

Click on the views tab. Click on the checkbox Enable the use of Views to start using views. Select the first view and check the box Visible when room starts to make sure this view can be seen. Give it a width of 300 and a height of 200 (or something else that you like).At the bottom we can indicate which object to follow. Here we choose the character. The view will now automatically move to keep the character in focus. We don’t want the character to get too close to the border. To this end we set the Hbor and Vbor values to 64. There will now always be a 64 pixel area visible around the character. Finally, to get a smooth view motion we set the maximal view speed to 4. (This also gives a very nice effect at the start because the character comes slowly into view.)

 

Having the view is nice but it makes the window in which things happen rather small. To avoid this, in the Global Game Settings indicate a fixed scale of 200 percent. Clearly you can play with these values to get the effect you want.

 

 

 

Shooting monsters

 

The next step is to enable the player to shoot monsters. To make things a bit more interesting, the player first needs to find some ammunition to be able to shoot. A

1. On create of the character set an ammo variable to 0

2. On collision with obj_ammo add 10 to the ammo variable (or whatever you want)

3. On the Press of the space bar

a. Check if ammo is greater than 0
b. If it is then check if your sprite is facing left
c. Create a left moving bullet

var bullet = instance_create(X, Y, OBJECT);
bullet.direction = DIRECTION;
bullet.speed = SPEED;

d. Do the same if the character sprite is facing right

e. Subtract 1 from ammo variable

f. Destroy the bullet when it leaves the room, hits a wall, or the monster.

g. Destroy the monster when it is hit

 

A Score Panel (We will use drag and drop to speed things up)

 

A player now has a score and ammunition. We are also going to give it some lives. Hitting a monster or falling in a pit will cost a life. When the player has No More Lives show the highscore table and restart the game.

 

Display the number of lives, the score, ammunition, etc. on a panel. We are going to draw this in the Draw event of the controller object. There is though a problem here. Where should we draw it? We cannot draw it at a fixed place in the room because the view changes and we want the panel always in view. Fortunately we can ask for the position of the view. This is indicated by the two variables view_xview and view_yview that indicate the left position and top position of the view respectively. So we can draw the panel with the information relative to this position. Here is a start .... try the rest on your own.

 

 

Also draw an image when the player can shoot.

 

 

 

 

 

 

 

 

 

 

What next?

 

The sections above have explained some of the basics of making platform games. Now it is your turn. Use these ideas to create at least 3 additional levels.

 

Here are some ideas you might try

·         different monsters, e.g. bouncing balls and monsters that shoot

·         keys that you need to find in order to open doors

 

·         mines that you can place somewhere and that go off when a monster (or yourself) steps on them

 

·         water to swim in (this will completely change the motions; no gravity anymore, or a mild upwards gravity until you reach the surface, limited time before you run out of air, air bubbles to grab, etc.)

 

·         walls and floors you can destroy, e.g. by shooting them or jumping on them with force

 

·         trampolines that make you jump higher

 

·         platforms that appear and disappear

·         one-way streets

·         moving platforms (this is not easy!)

·        

 

Post your Game to your Website. Include .exe and .gm81