Game Development Reference
In-Depth Information
Figure 14-1.
Features with this image require the Game Maker Pro edition.
Browse around to see what's here, and add those finishing touches to your game—or just try
them out to learn, to tinker, and to have fun.
360-Degree Movement
If you've read
The Game Maker's Apprentice
, you are probably familiar with one form of
360-degree movement, where you used a sprite with rotated subimages to move in any direction.
If you have Game Maker Pro, however, there is another, simpler way to rotate the sprite. We'll
create an Asteroids-like space ship to show you how.
Start with:
Reference/Framework/spaceship1.gmk
Creating 360-Degree Movement
1.
Open
spr_spaceship
and note that the sprite contains two subimages that we will use
to show and hide the jet flames. Click the
Center
button—this is important because a
sprite rotates around its origin!
2.
Create a new object, call it
obj_spaceship
, and set the
Sprite
to
spr_spaceship
.
3.
Add a
Create
event and insert the
Set Variable
action with
Variable
image_speed
and
Value
0
. This stops the sprite from animating.
4.
Add a
Keyboard
,
<Left>
event and include a
Set Variable
action with
Variable
image_angle
and
Value
5
,
Relative
. This action rotates the sprite counter-clockwise.
5.
Add a
Keyboard
,
<Right>
event and include a
Set Variable
action with
Variable
image_angle
and
Value
-5
,
Relative
. This action rotates the image clockwise.
6.
Add a
Keyboard
,
<Up>
event and include a
Move Free
action. Set
Direction
to
image_angle
and
Speed
to
0.2
. Check the
Relative
box.
7.
In the same event, include a
Set Variable
action with
Variable
speed
and
Value
min(speed,6)
. This keeps the speed limited to 6.
8.
Add a
Key Press
,
<Up>
event and include a
Set Variable
action with
Variable
image_index
and
Value
1
. This will show the subimage with a fired engine.
9.
In the same event, include a
Play Sound
action for
snd_engine
. Set
Loop
to
true
.
10.
Add a
Key Release
,
<Up>
event and include a
Set Variable
action with
Variable
image_index
and
Value
0
. This returns to the subimage with the inactive engine.
11.
In the same event, include a
Stop Sound
action for
snd_engine
.
Search WWH ::
Custom Search