Make RPG tutorial : chapter II - Part 3/4 |
||||||
|
|
Keep track of your game loop when you make games.Keeping your game loop in mind is a good way to not get lost or have to spend hours figuring out where to add new code to get a new feature to work. Our sample game's game loop is already getting a bit complex. That can be intimidating, but it shouldn't. If you keep good track of it, you'll realize it is just a series of logical steps that slowly build up as your game develops. First the room0 is created, or restarted at each consecutive step, as well as the objects that were added to it. Things that happen to the character (events such as draw, left key, up key...) cause actions (executing code, running scripts). The scripts and codes can start new events of their own by creating new objects (instance_create()) for example. Scripts can also call new scripts (if certain conditions are met by using an if statement, or without conditions at all). The game loop restarts at each step. How long a step lasts depends on the room speed you choose in room settings. Default is 30 steps per second, which means a step lasts 1/30th of a second. In this game I changed it to 60 so that the cursor would stay on the topbar. I'll change it back in a later tutorial though... There are other ways. At each step the room is restarted. All possible events are either checked for (key events) or executed every time (step events, draw events).
Each object can potentially generate events, just by existing. The step event happens at every step, as well the draw event. Nothing special has to happen.
main_ch is the name of the main character object. If you open its object properties, you'll see four keyboard events, an O key event, a draw event and a space release event.
(if instance_position(x-10,y,all)=noone x-=4 This translates as: if no object (noone) of any type (all) is at instance position (my x coordiante-10, my y coordinate) or 10 pixels to my left, then my new x coordinate is x-4 (x-=4) so I will move 4 pixels to the left. Otherwise (else), if global.space_mess=0, then change that global variable (global means it will be recognized in other scripts maunched by other objects) becomes =1. global.space_message is a variable that will be used to determine if a message is shown on the screen later in the loop. This prepares for that message to be shown, if another object is on its way to the left.
The sprite associated to the object is drawn, in conformity with the global.heading value. Takes the x and y "local" values and copies them into global values that can be used anywhere (global.posx and y). Runs the script character_options() if a variable value is equal to 1.
Now let's move on to another object. |
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