Cutscenes
Place the goblin in the town. Have it face west, away from the entrance.
![[IMAGE]](/static/tutorial/cutscenes/editor.jpg)
We could just leave it at that; the player enters the hideout and immediately fights the goblin. But we can do more than just that. Let's add a cutscene that runs when the player first enters the town. The goblin will turn around, yell indignantly at the intrusion, and then try to run away. In z1hideout.txt, add the following code to the INIT_STATE (the state that runs whenever something is loaded by the game):
beginstate INIT_STATE; if (get_flag(1, 0) == 0) { set_flag(1, 0, 1); force_view_center(20, 15); force_instant_terrain_redraw(); pause(10); text_bubble_on_char(6, "!"); force_instant_terrain_redraw(); pause(10); text_bubble_on_char(6, ""); force_instant_terrain_redraw(); pause(5); set_character_facing(6, 4); force_instant_terrain_redraw(); pause(5); set_character_facing(6, 6); force_instant_terrain_redraw(); pause(5); text_bubble_on_char(6, "What? No!"); force_instant_terrain_redraw(); pause(20); text_bubble_on_char(6, ""); force_instant_terrain_redraw(); pause(10); text_bubble_on_char(6, "It's mine!"); force_instant_terrain_redraw(); pause(20); text_bubble_on_char(6, ""); force_instant_terrain_redraw(); pause(10); text_bubble_on_char(6, "MINE!"); force_instant_terrain_redraw(); pause(20); text_bubble_on_char(6, ""); force_instant_terrain_redraw(); pause(10); set_character_facing(6, 4); force_instant_terrain_redraw(); pause(5); relocate_character(6, 20, 16); run_animation_sound(49); force_instant_terrain_redraw(); pause(3); relocate_character(6, 20, 17); run_animation_sound(50); force_instant_terrain_redraw(); pause(3); relocate_character(6, 20, 18); run_animation_sound(49); force_instant_terrain_redraw(); pause(3); relocate_character(6, 20, 19); run_animation_sound(50); force_instant_terrain_redraw(); pause(3); relocate_character(6, 20, 20); run_animation_sound(49); force_instant_terrain_redraw(); pause(3); relocate_character(6, 20, 21); run_animation_sound(50); force_instant_terrain_redraw(); pause(3); set_character_facing(6, 2); force_instant_terrain_redraw(); pause(2); relocate_character(6, 19, 21); run_animation_sound(49); force_instant_terrain_redraw(); pause(3); relocate_character(6, 18, 21); run_animation_sound(50); force_instant_terrain_redraw(); pause(3); relocate_character(6, 17, 21); run_animation_sound(49); force_instant_terrain_redraw(); pause(3); relocate_character(6, 16, 21); run_animation_sound(50); force_instant_terrain_redraw(); pause(3); relocate_character(6, 15, 21); run_animation_sound(49); force_instant_terrain_redraw(); pause(3); relocate_character(6, 14, 21); run_animation_sound(50); force_instant_terrain_redraw(); pause(3); } break;
That's a big chunk of code, so let's break it down. First of all, the if statement and the get_flag / set_flag calls you've seen before. They make sure that the cutscene only runs once. The rest of the code is made up of cutscene calls. Each chunk of code follows the same pattern: one or more function calls with various side effects, then a force_instant_terrain_redraw function call, then a pause function call. force_instant_terrain_redraw tells the game to update the display. pause tells the game to pause for a certain amount of time (given in tenths of seconds). Taken together, each chunk of code essentially reads "change one or more things, then show the changes, then wait for a bit".
As for all the other function calls:
- force_view_center recenters the screen on the given (X,Y) coordinates. Here, we want the focus to be on the pesky goblin, so we set the center to be (20,15), its current coordinates.
- text_bubble_on_char makes a string of text appear over a given character's head. It's one of the most common calls in a cutscene, used to make a character talk. In this cutscene, we just want the goblin (character number 6) to talk, but you can easily have more than one character talk at once. To remove a text bubble, you need to call text_bubble_on_char with an empty string as an argument.
- set_character_facing changes the direction the given character is facing. In the first example, set_character_facing(6, 4) makes character number 6 (the goblin) face direction number 4 (south). Read the linked documentation to see what number each direction is assigned to.
- relocate_character moves the specified character to the given (X,Y) coordinates. This can teleport a character to any location, but in our case we're going to move the goblin one square at a time, to simulate walking.
- run_animation_sound is one of the ways to play a sound effect in the game. We're using it because it doesn't pause the game while the sound is playing. For a full list of all the sound effects in the game, read page 16 of the appendix.
Note that there's nothing special about any of these calls that force you to use them inside a "cutscene". You could, for instance, use relocate_character inside a script to make an enemy teleport at certain times.
Getting the timing right on cutscenes is a bit of trial and error. You'll have to play your scenario, save just before the cutscene, and then watch it a few times before you're happy with your pause times. Feel free to play around with this one. After that, we'll continue adding things to the town.