GAME MAKER 3


 PLATFORMER GAME


CREATE OBJECT PLAYER/WALL
Select the object folder from the panel and create an object to be the player object, call it obj_player as per convention.Do the same for the platform walls, call it obj_wall

CREATE SPRITE PLAYER
If you use a spritesheet you should name your image file ending in strip and the number of divisions the sheet have: "spr_player_strip16.png" for an strip with drawings for 16 frames. We will sue here three sprites, one called sPlayerA, sPlayerR, and sPlayer.
Initially though, you can work with a simple image and link this to the obj player.
Importantly for the feeling of the gameplay, then go to the Collision mask subpanel and refine it, usually making it a little smaller than the image rectangle, in this case only covering the feet of the player drawing, and place the origin exactly in the center.. Then we go to the obj_player and in the collision mask sub panel select the same as the spr_player.

CREATE BLOCK PLATFORM
Create an sprite and then import a semitransparent object and link it to the obj_wall

SET UP PLAYER MOVEMENT
Add create event to obj_player,and define the main variables:
hsp =0;
vsp=0;
grv=0.3;
walkspd=4;
jumpsp=9;

Then, to get player input, we add the event Step panel, always in obj_player:

key_left=keyboard_check(vk_left);

key_right=keyboard_check(vk_right);

key_jump=keyboard_check(vk_space);


Then, to calculate movement, create a custom variable, still in step panel:

var _move= key_right-key_left;

hsp=_move*walksp;

vsp=vsp +grv;

if(place_meeting(x,y+1,oWall)) && (key_jump){

vsp=-jumpsp

}


SET UP COLLISION

Then, to detect horizontal collisions, in step panel:

  if(place_meeting(x+hsp,y,oWall))

{

  while(!place_meeting(x+sign(hsp),y,oWall)){

x=x+sign(hsp);

}

hsp=0;

  }

x=x+hsp;

Be careful with while statements check they become false otherwise you can get an infinite loop.

Then, to detect vertical collisions, in step panel:

  if(place_meeting(x,y+vsp,oWall))

{

  while(!place_meeting(x+sign(vsp),y,oWall)){

y=y+sign(vsp);

}

vsp=0;

  }

y=y+vsp;

By now we will add the animation sprites, one for moving left, one for right, and one for jumping and falling

Then we set up the animations, still in the step panel:

if(!place_meeting(x,y+1,oWall)){

sprite_index = sPlayerA;

//jumping

image_speed=0;

//falling

if(vsp>0)image_index=1; else image_index=0;

}

else

{ image_speed=1;

if(hsp==0){

sprite_index=sPlayer;

}

else{

sprite_index=sPlayerR;

}

}

if(hsp !=0)image_xscale=sign(hsp);


CREATE TILE SET UP

To create the environment we need to import a big tile png with the different parts, as well as images for certain effects such as a background, a pair of clouds.

We create a tile layer in the room editor as well as a tile set in the asset panels/tiles folder. Then we assign the spr for tiles to the tile set and then place it in the tile layer.Because the tiles go in the tile layer we need the ob all in the instances layer so the player can stand above the wall blocks; the tiles are purely visual.



SET UP CAMERA




Comments