Making RPG games : chapter II - Part 4/4

     
         
   

 

   
         
    Part 3 Back to Tutorials    
         
   
Learn Game Programming much faster: join my list! The source code for the game programming tutorials (first chapter 1, then chapter 2...) and more!
You'll be a pro in a couple weeks!
(You must be at least 13!)
 
Name:
Email:
Comment:
 
Privacy policy:  This list is all about the fun and entirely safe.  You can remove yourself permanently in just seconds, anytime you wish.  No one is getting your email from me and there will be no spam!
   
         
   

Making games in GML is object oriented.

Many objects besides the main character will make up a game. In this sample, there are the inactive objects that will be detected by the main character. There is the table, which, recognized as such, will cause specific reactions (see previous part). The doors will soon act appropriately using the same method. You previously read that the main character reacts to key prompts (arrow keys for movement and heading, O for renaming, space to see available options)

You can imagine countless options such as other characters to talk to, monsters to shoot, closets to explore, doors or windows to open...

There are the interface objects that react to mouse clicks or hovering (NoButton). Those are the character and inventory objects on the right (they react by creating or destroying the corresponding panels, as well as the objects they contain, by running the open and close inventory scripts), the two topbars and the squares.

And then there are item objects that are created when the right variables are set at the right values (the topbars are as well), and stored in their own inventory slots when they are picked up. That's all they do for now, but they will soon react to mouse events as well.

Objects are the core of your game. They make the game loop continue. When all object events have caused the assigned actions, the next step begins and the loop is restarted, ready to react to new events by running new actions.

Making scripts run in your game.

We saw that the space key causes a check for close objects, and a variable change if it finds something. This is done by using the if statement and instance_position(). Once that variable is changed, you get reactions by making sure that variable is checked at each step. You do that by assigning that verification in an action (a script or execute a piece of code). This action results from an event that happens at every step. Draw is one of them, and it is the one you must use if what happens next involves drawing text or images. If it is just variable value updates, the Step event will work fine. If you aren't sure yet, then just use the draw event to be sure.

In the main character draw event, if global.checking_character_options=1 character_options(); launches the script character_options because Space was pressed, causing the if condition here to be true.

Other variables determine if, ultimately, the gun and cookies end up in your inventory, and where. global.just_taken=10; in get_cookies() is a variable used to determine which object was just taken (item 10 is the cookies). This is used in the inventory scripts. First, add_to_inv() will determine what slot it will go in (the first available). Then when the inventory is open, open_inventory() draws the cookies inventory objects at the same coordinates as the square it was assigned to. Since the cookie's inventory object has a lower depth than the inventory square, it appears on top, giving the illusion that it is inside it.

Arrays are used to do this quickly. This allows you to update values using single or double "for" loops. Take a look at the open_inventory() script in the inventory folder. You'll see this is extremely useful (you can't make a decent game without it!)

   
         
    Part 3 Back to Tutorials    
 

Making Video Games Home     Game Programming Tutorials     Email Courses with Source Code    Make Games for a Living   Swords and Sorcery   Contact  Affiliates

© www.makingvideogames.com 2009

Other project:  Understand Fat Loss