Showing posts with label code. Show all posts
Showing posts with label code. Show all posts
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.
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.
Subscribe to:
Posts (Atom)