Google
Web todd101scout.tripod.com
Blog Tools
Edit your Blog
Build a Blog
RSS Feed
View Profile
Open Community
Post to this Blog
« July 2006 »
S M T W T F S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
You are not logged in. Log in
Entries by Topic
All topics  «
Game Programming
Gaming
IMPORTANT
Movies
Scouting
Sports
Fun Compendium
Sunday, 30 July 2006
Game Maker
Topic: Game Programming

Ads by AdGenta.com

I love to program. For that matter, I love computers.The only thing I don't like about computers is their frustrating tendency to refuse to co-operate. Of course, programming means that you are going to be living and working with this annoyance, so you have to be really good at it, or not do it at all. Right? WRONG!!! This is where game maker comes in: game maker makes it very easy for you to program games on every level. It supports both a drag-and-drop type programming, which allows for the simple and fast creation of basic games, and a user-friendly programming language. It took me only a few days to learn the basics of the language. The coolest thing is, you can use the two together, so even if you don't know how to programming something in GML (Game maker language, the programming language used by game maker), you can still program it in with the easier to use drag-and-drop interface. The whole shebang is organized very neatly into only 9 categories, but you only NEED to use 3. Game maker is available at www.gamemaker.nl

 

HOW TO: The Basics

Ok, programming with game maker is very simple. All you need is an idea of what you want to program, a few images, some spare time, and viola, instant game. How it works: Sprites are the images, objects control the sprites and all other aspects of the game, and rooms are what you see while playing the games. For basic games lacking sound or backgrounds, this is all you need.

I will be covering how to make a very simple racing game. Please let me know if you would like other tutorials.

Ads by AdGenta.comAds by AdGenta.com

 

THE DESIGN

For this racing game, you will drive in a straight line (but still have the ability to turn) and race against 1 opponent.

WHAT YOU WILL NEED

You will need about 5 to 10 minutes and 2 pictures of seperate cars (top-down is RECOMMENDED for the good of your game). You will also need either version of Game Maker (I think that this will work on the unregistered version. If it does not, please let me know.) So enjoy!

THE SPRITES

You will need only 2 sprites (3 if you want a finish line) 1 will be for your car, the other will be for the opponent's car. The cars must be facing right in the sprite disply, but that is the only madatory thing, though I do recommend leaving transparency checked, and making the picture's background all 1 color (try to keep the picture under 100*100) Make sure you know which sprite is which

THE OBJECTS

Create 3 objects: Your car, the enemy's car, and the finish line. For your car, add the following code to create event (double click on your car's object, click add event, then choose create. After that, go to the control tab, and drag the "execute a piece of code" block into the actions box)

friction=0.02
self.degree=90 (depending on which way you want your car to face at the start, you may want to change this (0= to the left, 90= up, 180= to the right, 270= down)

This will set the resistance that your car experiences and its starting angle

next, add a step event (click on add event, then step, and step again) and insert another code block, this time entering:

image_angle=self.degree
motion_set(self.degree,speed)

this tells your car's image to always face the way it is moving and to always move the way it is facing (I know, it is rendundant, but it works :) )

After that, add event "Keyboard left" by choosing keyboard, then left in the add event dialoge. Here, you also add another block of code:

self.degree+=2 (the larger the number, the faster your car turns)
speed-=0.09 (the larger the number, the more turning slows your car down)

this tells your car to turn to the left and slow down a bit whenever you are pressingthe left arrow key

Next, add event "Keyboard right" by choosing keyboard, then right in the add event dialoge. Here, you also add another block of code:

self.degree-=2
speed-=0.09

this does the same as the left key, except in the opposite direction.

To make your car brake, add in "keyboard down" the same way as you did for the other arrow keys, and add another block of code, then enter this:

speed-=0.1 (the larger this number, the faster your car will brake)

This lets your car know that whenever the back arrow key is pressed, it needs to slow down

Most importantly, to make your car accelerate, add the up arrow, with the following code:

if speed<10 (the larger the number, the faster your car can go)
speed+=0.2 (the larger the number, the faster your car acclerates)

this code tells your car to accelerate if it is going slwoer than its top speed

That is all for your car. Now for your opponent:

under create:

self.degree=90 (same as for your car)

under step:

if speed<9 (opponenet's top speed)

speed+=0.21 (opponent's acceleration)

image_angle=self.degree
motion_set(self.degree,speed)

this basically creates an automated version of your car that goes straight, with faster acceleration, but a lower top speed

also add event "outside room" it is under "other" and tell it to destroy itselft (under "main1")

 

now for the finish line:

set the sprite (if you made one), then add the folowing code under step:

if instance_number(Enemy_Car1)=1
{
score+=10
message_caption(1,"You won, congradulations!") (you can change the quoted text, but leave the quotes there)
}
else

message_caption(1,"You have lost, try again!") (see above)
room_restart()

this sets it so if you finish before the opponent, you get 10 points, and it displays You won, congradulations (or whatever you told it to) and if you lose, it displays You have lost, try again! (same as before)

 

THE ROOM

This part is vital. Add a room (the last option) and go to settings. Here, you can choose the size of the room (don't make it longer (or wider, depending on the starting angle) than 1280 so that you don't have to worry about views. Place the finish object anywhere in the room (or at the end, if you made a sprite for it) and your cars wherever you want them to start.

 

CONGRADULATIONS. YOU HAVE JUST PROGRAMMED YOUR FIRST GAME. ENJOY!

Ads by AdGenta.comAds by AdGenta.comAds by AdGenta.comAds by AdGenta.com


Posted by todd101scout at 2:16 PM PDT
Updated: Monday, 31 July 2006 5:46 PM PDT
Share This Post Share This Post
Post Comment | Permalink

View Latest Entries