This section will go over how to use codes to make a game work. The tutorial will teach you how to make a simple platform engine. This engine will cover basic platform coding.
The Platform Game
Platform games are side view games where you have the ability to move left and right (Sometimes up and down). They require several codes to make a working engine.
Step 1 Create the following objects obj_player obj_ground
Assign a 32 * 32 green block as the sprite for ground and a black 32 * 32 block for player.
Step 2 Open the Player object and prepare to start coding. Create a "Up pressed" event and add the following code ____________________________________________________________________________________________ if place_meeting(x,y+1,obj_ground) and vspeed >= 0 //Checks place meeting between The Player and Ground {
vspeed=-6 //Sets vspeed to -6
} ____________________________________________________________________________________________ This will set up your player for jumping. You may notice he doesn't fall. To do this, we add a "Step Event".
____________________________________________________________________________________________ if place_free(x,y+1) //Checks if your player is free from any contact { gravity=0.5 // Sets the Gravity to 0.5 | Gravity will cause your player to fall } ____________________________________________________________________________________________ This is great and all, but you will notice that the player falls strait through the ground. To finish the engine you will create a contact code. There are many ways to do this, but the easiest is using solid objects. Open ground and check "Solid."
Step 3 The last step is to put in the contact code. Do this by putting the following code into a "Collision with Ground" event.
____________________________________________________________________________________________ move_contact_solid(270,12); //This moves your player to contact with the solid. gravity=0 vspeed=0 ____________________________________________________________________________________________ Finally build your room, test it out and build from it.
Comprehension
This is just a way to show you how easy coding is. You can easily build on to this using events and functions. Adding movement is only 2 events and 2 lines away. Try adding x += 3 and x -= 3 in the left and right key events. That will add movement into the game.
The next section will give you several engines to learn from along with a few more tips before we go into the complexities of programming your games.