Friday, January 28, 2011

How to make your car turn. (really cool!)


This is really cool! In this tutorial you will learn how to make your car turn and accelerate.
Here are the codes I used:
Code used in keyboard up event:

{
  if (speed < 8) speed = min(8,speed+1.6);
}
Code used in the keyboard down event:

{
  if (speed > -8) speed = max(-8,speed-1.6);
}
These are the really in portent codes that we used in the video. You should play around with the values a little to make them fit your purposes. These codes can be used in many many ways. If you have questions just let me know.

How to pause your game.

This is something that almost every game needs to have. It is really easy to explain and do. First, you need to decide what button will pause your game. Most games will have the letter P pause the game. That is what we will use. Add Event, key press P. Now in the event of key press P put this code in.
Code:
{
io_clear();
draw_sprite(spr_gamepaused,0,150,170);
screen_refresh();
while (!keyboard_check_pressed(vk_anykey) ) sleep(100);
}

Ok, the second line in this code allows you to draw a sprite paused.
The rest of this code creates a loop. Keeping the game paused. And then the game will un pause when you hit any button. Simple right?

How to save and load a game

Lets say you are making a Role Player Game or something. Something big, so big that you need a saving and loading feature. Now game maker 8 has a saving and loading action, but it only saves one file. So only one person can play your game. You don't want that do you! You want to have 3, 5 or maybe 10 saving and loading slots right? Here is how you do this.

Lets say you have a object. obj_load_slot1. When you click on this you want it to load a game. You want it to load game slot 1. Here is how you do this. Put this code in the mouse left pressed event.
code:
game_load(slot1)

Its as simple as that! the (slot1) is the name of the file, so it will only load that if the file (slot1) exists. Here is how you would save your game. Lets say you have a object obj_save_slot1. You want your game to save as slot 1 when you click on it. Put this code in the mouse left pressed event.
Code:
game_save(slot1)

Now the game is saved under slot 1. To load that file the names have to be the same. You can name your file anything you want making it easier to search and find it. This code has to be one of the easiest codes that there are in game maker. Its almost like you are reading it. game save slot1. Now you can have a dozen saving and loading slots! All you have to do is name then and use these two simple codes.

How to make a object orbit another object.

We are going to make a object orbit another object and orbit it around where ever he goes. To start, we put this in the create event:
code:

orbit_angle = 500;
orbit_radius = 50;
orbit_speed  = 10;

I will explain this more in a minute, orbit_angle is going to be the angle of the orbiting object. Orbit_radius is going to be the radius (how big) of the orbit. And orbit_speed is going to be how fast it will go when in orbit.
Here is the next code and it goes in the step event:
code:

orbit_angle += orbit_speed;
x = obj_player.x + orbit_radius * cos(orbit_angle * pi / 360);
y = obj_player.y - orbit_radius * sin(orbit_angle * pi / 360);

This is all you need to do to make the object angle. You can always change the values of orbit_angle and orbit_radius to get a different orbit. If you look at the code in the step event you can see its pretty easy to understand.

Make sure that you change obj_player to what ever name it is for the object that you want to be orbited.

Thursday, January 27, 2011

How to shoot in many directions.



This is a tutorial you will learn how to shoot in many directions using variables.
If you have any questions or feedback let me know.

How to make the camera follow a object


In this video, you will learn how to make the camera follow a object.

How to add health to your game.



In this video, you will learn how to add health and a health bar to your game.
Here is the code that I used to draw the health bar.
Code:
draw_sprite_stretched(HEALTH,0,x-5,y-14,hp,6)






How to make a simple platform game parts 1 and 2





In this tutorial, you will learn how to make a simple jumping platform game. If you have any questions let me know. Have fun!
If you want to play this game you can! http://www.yoyogames.com/games/161412-the-life-of-a-hairball