Game Development Reference
In-Depth Information
8.
Finally, the
Draw
event draws the character faces and the background rectangle for all
the dialogue objects.
1:
vx = view_xview[0];
2:
vy = view_yview[0];
3:
4:
switch( talking )
5:
{
6:
case TALK_NPC: face_index = sprite_index; break;
7:
case TALK_ARCHIE: face_index = spr_parrot_face; break;
8:
case TALK_FLYNN: face_index = spr_flynn_face; break;
9:
}
10:
11:
if( talking != TALK_NOONE && sequence != 999 )
12:
{
13:
draw_sprite( face_index, 0, vx + 60, vy + 540 );
14:
15:
draw_set_color( make_color_rgb( 0, 0, 64 ) );
16:
draw_set_alpha( 0.5 );
17:
draw_rectangle( vx+122, vy+490, vx+1014, vy+590, false );
18:
draw_set_alpha( 1.0 );
19:
}
Like a number of the other objects, we use
vx
and
vy
variables to store the position of
the view at the start of the
Draw
event (lines 1-2). This then provides a shorthand way
of adding the view position onto coordinates in lines 13 and 17 so that the face sprite
and blue rectangle follow the player's view around the room. The values
X1
=
122
,
Y1
=
490
and
X2
=
1014
,
Y2
=
590
represent the top left and bottom right coordinates of the
blue rectangle within the view. Adding
vx
and
vy
then makes these relative to the view
position in the room. Notice that we set (and reset) the alpha value of the drawing
operations so that the level can be seen through the rectangle.
Lines 6-8 determine which face sprite is displayed alongside the text. Rather than
have constants defined for every character, we use
TALK_NPC
for all characters other
than Flynn and Archie and display the default sprite for this object (
sprite_index
).
Each of the dialogue objects in the final game use the appropriate face sprite as its
default sprite, which makes it easier to identify it when it's placed within the room.
The actual content of the dialogue is controlled within
obj_dialogue_test
. This is the
initial conversation that takes place between Flynn and the first prisoner in the game,
as set out in Table 13-1. Open the
Step
event of
obj_dialogue_test
and observe how
the entire conversation is mapped out within a state machine. Each
case
statement
within the
switch
corresponds to the ID column of the table and the speaker column
corresponds to the
talking
variable.
9.
Search WWH ::
Custom Search