08.11.2012 Views

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Generating Events<br />

Miscellaneous Variables and Functions<br />

Moving around<br />

Obviously, an important aspect of games is the moving around of object instances. Each<br />

instance has two built-in variables x and y that indicate the position of the instance. (To be<br />

precise, they indicate the place where the origin of the sprite is placed. Position (0,0) is the<br />

top-left corner of the room. You can change the position of the instance by changing its x and<br />

y variables. If you want the object to make complicated motions this is the way to go. You<br />

typically put this code in the step event for the object.<br />

If the object moves <strong>with</strong> constant speed and direction, there is an easier way to do this. Each<br />

object instance has a horizontal speed (hspeed) and a vertical speed (vspeed). Both are<br />

indicated in pixels per step. A positive horizontal speed means a motion to the right, a<br />

negative horizontal speed mean a motion to the left. Positive vertical speed is downwards and<br />

negative vertical speed is upwards. So you have to set these variables only once (for example<br />

in the creating event) to give the object instance a constant motion.<br />

There is quite a different way for specifying motion, using a direction (in degrees 0-359), and<br />

a speed (should be non-negative). You can set and read these variables to specify an arbitrary<br />

motion. (Internally this is changed into values for hspeed and vspeed.) Also there is the<br />

friction and the gravity and gravity direction. Finally, there is the function<br />

motion_add(dir,speed) to add a motion to the current one.<br />

To be complete, each instance has the following variables and functions dealing <strong>with</strong> its<br />

position and motion:<br />

x Its x-position.<br />

y Its y-position.<br />

xprevious Its previous x-position.<br />

yprevious Its previous y-position.<br />

xstart Its starting x-position in the room.<br />

ystart Its starting y-position in the room.<br />

hspeed Horizontal component of the speed.<br />

vspeed Vertical component of the speed.<br />

direction Its current direction (0-360, counter-clockwise, 0 = to the right).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!