Game Development Reference
In-Depth Information
Adding a Step Event to the Falling State Object
1.
Add a
Step, Step
event to the
obj_pod_falling
object.
2.
Include a
Test Variable
action (
control
tab) and use it to check that
vspeed
(the object's
vertical speed) is
larger than
12
.
3.
Include a
Set Variable
action (
control
tab) and use it to set
vspeed
to
12
. This is
equivalent to using a
Speed Vertical
action, which sets the
Vert. Speed
to
12
. This will
ensure that the vertical speed of Fishpod never exceeds 12 pixels in each step. Its
bounding box is 36 pixels high, so there should never be any gaps in the collision
detection when it is falling.
That's just about it for Fishpod's state objects. There is one more change we should make to
obj_pod
before running the game. We originally set the initial state of Fishpod to be
obj_pod_standing
, as this was the only state we had implemented at that stage. It makes more
sense now to start Fishpod in the falling state, as this handles the situation where he is not
supported by a platform at the start of the level.
Editing the Create Event of the Fishpod Object
1.
Reopen the
obj_pod
object and select the
Create
event.
2.
Edit the
Change Instance
action and set it to
obj_pod_falling
.
Now, run the game and it should start to feel like a platform game for the first time. You
should be able to walk along platforms and jump between them. Try not to jump off the screen at
the moment, as we've not implemented a way to restart the level without stopping the game yet.
Make sure that you have saved your work and then compare your version against the version in
Chapter02/Games/fishpod3.gmk
to check that everything is working as it should.
Challenges
Now that we have the basic platform game mechanics in place, we should be able to turn this into
a simple game by adding a few challenges. We'll do this by adding poisonous pansies and lava
flows that send the player straight back to the start as soon as Fishpod collides with them. All of
these objects need to have the same behavior, so we will use a parent object (
obj_hazard
) to make
it possible to handle them all in the same collision event.
It would also be nice if our lava flows finished themselves off automatically in the same way
as the rock platforms. So instances of the middle lava object will turn themselves into instances of
the begin and end lava objects if there are no more hazards to either side of them. We will also
make the begin and end lava objects add instances of platform objects to finish them off if there is
nothing there already.
Creating Hazard Objects and Their Create Events
Create a new object called
obj_hazard
and close the properties form.
1.
Create a new object called
obj_pansy
. Select the
spr_pansy
sprite and set
obj_hazard
as
the parent of this object. Set its
Depth
to
-2
(in front of Fishpod, as this will ensure that
the player can clearly see a hazard like this one when they collide with it).
2.
Create a new object called
obj_lava_begin
. Select the
spr_lava_begin
sprite and set
obj_hazard
as the parent of this object. Unlike the pansy hazard, we will leave the
Depth
set to
0
for all the lava hazards because they are part of the platforms.
3.
Add a
Create
event to
obj_lava_begin
.
4.
Search WWH ::
Custom Search