Game Development Reference
In-Depth Information
4. Clicking on the grid will now create a path! But before you start clicking away, keep in
mind that the path line we're going to create describes the path of the origin of the
sprite. Since this will be a mummy path, and the mummy's sprite origin is at ( 0 , 0 ), this
means that the line describes the path of the top left corner of the sprite. It's important
to know this because we don't want our mummy to move through any walls! Let's add
the following points: ( 224 , 368 ), ( 48 , 368 ), ( 48 , 48 ), ( 304 , 48 ), and ( 304 , 144 ). Note that you
can drag points if you have placed them in the wrong spot.
5. Create a path called path_scorpion1 and again set room_test as the background. This
time, keep the path closed and add the points ( 192 , 144 ), ( 432 , 144 ), ( 432 , 336) , ( 304 , 336 ),
( 304 , 240 ), and ( 192 , 240 ). Put both paths in a group called room_test . It's best to keep
them grouped, as they only apply to this room.
6. Now place an instance of obj_mummy and obj_scorpion in the room. It actually doesn't
matter where you place them, as we'll let the path take care of placement, but it's a
good idea to place them somewhere near their paths.
7. We now need to tell these instances which path to use. There are actions for these, but
because your game is probably going to be littered with enemies of the same type, it
makes little sense to create lots of copies of them with a different path stored in each.
So we'll use the instance's Creation Code . Still in the room editor, objects tab, hold the
Control key and right-click on the mummy instance. Select Creation Code… from the
context menu. Insert the following lines:
1: {
2: path_start(path_mummy1,2,3,true);
3: }
This line tells the instance to start the path path_mummy1 with speed 2 . The third
parameter is the End action and determines what should happen if the end of the path
is reached. A value of 3 means the path should be reversed, making the instance turn
back on the same path. The last parameter tells the instance that the points in the path
are Absolute , which means they are room coordinates rather than coordinates relative
to the instance's position.
8. Now hold the Control key and right-click the scorpion instance, and select Creation
Code… again. Insert the following lines:
1: {
2: path_start(path_scorpion1,2,1,true);
3: }
The only changes in this script are the path and the End action , which now equals 1
(continue from start). This will make the scorpion loop its path.
We still need to make obj_mummy and obj_scorpion face in the direction they're walking,
and walk at a decent speed. We can make use of the fact that Game Maker
automatically adjusts the direction variable depending on the path! Open obj_mummy
and add a Step , Step event. Include an Execute Code action and insert the following
lines:
9.
Search WWH ::




Custom Search