6
Simple Platform Engine Game Maker 8 For beginner GM users

Simple Platform Engine

  • Upload
    redell

  • View
    31

  • Download
    0

Embed Size (px)

DESCRIPTION

Simple Platform Engine. Game Maker 8 For beginner GM users. The Step Event. All the real stuff happens in the awesome step event. It also all happens in one simple code block, unless you choose to divide it between others. We should start with moving left/right. // Move Left and Right - PowerPoint PPT Presentation

Citation preview

Page 1: Simple Platform Engine

Simple Platform Engine

Game Maker 8For beginner GM users

Page 2: Simple Platform Engine

The Step Event

All the real stuff happens in the awesome step event. It also all happens in one simple code block, unless you choose to divide it between others.

We should start with moving left/right.// Move Left and Rightif keyboard_check(vk_right) { x=x+5; y=y+0;}if keyboard_check(vk_left) { x=x-5; y=y+0;}

Let us examine each line of the code!

if keyboard_check(vk_right) {

This is just like the “Right Pressed” event, it simply checks whether right is pressed.

x=x+5;

y=y+0;

This sets the objects x (horizontal) position to 5 pixels to the right. And not moving the y (vertical) to not move at all. This event is repeated for left pressed.

Page 3: Simple Platform Engine

The Step Event (cont.)

// Jumping Eventif keyboard_check(vk_up) { if !(place_free(x+0,y+1)) { vspeed-=20; }}

Now in most platform games you will want the player to jump, so to do that we just add this simple code!

if !(place_free(x+0,y+1)) {

This line is just the same as dragging on a check collision event and setting the area below the player object.

vspeed-=20;

This is the same as dragging out a vspeed event and setting it to -20.

Page 4: Simple Platform Engine

The Step Event (cont.)

// Gravityif (place_free(x+0,y+1)) { gravity_direction=270; gravity=3;}if gravity > 12 { gravity = 12}

Lastly and most importantly we need gravity. Because we wouldn’t want the player to be able to fly around.

The first line is already covered. Then the second line will set the direction of the gravity. 270 is down, 180 is right, 90 is up, and 0 is left. Pretty simple system.

The next line sets the gravity speed, which is set to three.if gravity > 12 { gravity = 12

This is a bit more complicated. This says that if the gravity speed is greater that 12, then we will set the gravity speed to 12. This will keep the player from falling through the platforms.

Page 5: Simple Platform Engine

Collision Event

//wall collision codeif other.y>y && !place_free(x,y+vspeed){ move_contact_solid(270,8); vspeed=0; gravity=0;}if other.y<y && !place_free(x,y+vspeed){ move_contact_solid(90,8); vspeed=0;}

Now you’ll want the character to collide with the ground and walls. So we can use some simple code to do so!

The code simply checks whether there is a ground object below the character, then if there is it will set the speed and gravity to zero. Which will make it appear that the character lands on the platform.

The next section of code does the same thing except for it is for objects to the side of the characters.

Page 6: Simple Platform Engine

Closing NotesI hope you enjoyed this tutorial and it really helped you a lot! You

can see the code in action in the .gmk file contained in the .zip file you downloaded.

Also, you can use this code for any way you want as long as you credit Nikc-Nack Games and link to one of our websites.

Thank you!