Game Development Reference
In-Depth Information
The
lengthdir_x
and
lengthdir_y
functions are used to set the instance to a relative
distance of
100
from the spaceship's position. The variable
angle
is set up further
below and decides the current angle of position with regard to the spaceship. Line 4
sets a rotation speed; use negative values for clockwise rotation.
3.
Open the
obj_spaceship
object. We use the
Create
event to create the orbiting stars,
but obviously you may add it in a more appropriate place. Include an
Execute Code
action and insert the following lines:
1:
{
2:
var i;
3:
for ( i = 0; i < 360; i += 36)
4:
with ( instance_create(0,0,obj_star) ) angle = i;
5:
}
This script creates ten evenly distributed stars that each start at a different angle. Line 2
first defines a variable we will use for a
for
loop. Line 3 sets up the loop from
0
to
360
in
steps of
36
, which amounts to 10 steps (10 stars). Line 4 creates an instance of
obj_star
. Note that we do not specify any position here, as this is taken care of in the
star's
End Step
event using the instance's angle. Using the
with
statement, we set the
angle
variable of the created instance to the value of
i
(0, 36, 72, 108, and so forth).
4.
Because the stars are dependent on the existence of the spaceship, we should destroy
them when the spaceship is destroyed. Add a
Destroy
event and include a
Destroy
Instance
action. Select
Object
, and choose
obj_star
.
Result:
Reference/Result/orbiting_objects.gmk
Patrolling Enemies
Enemies do not always chase the player—often, they're just harmlessly patrolling an area, and the
player's only danger is in touching them. Having enemies walk around a maze with lots of turns
and corners would be a difficult job if it weren't for Game Maker's awesome path mechanisms.
Start with:
Reference/Framework/explorer5.gmk
Creating Patrolling Enemies
1.
Create a new object
obj_mummy
and assign any of the mummy sprites to it. Also create
an object
obj_scorpion
and assign it any of the scorpion sprites.
Now add a path resource and call it
path_mummy1
. To the top right of the path window,
click the
Indicate the room to show as background
button (it's on the far right at the
top of the window), and select
room_test
from the drop-down box. Resize the window
if necessary to show the entire room.
2.
3.
Uncheck the
Closed
check box. Make sure that
Connection kind
is set to
Straight
lines
.
Search WWH ::
Custom Search