Cutscenes

Place the goblin in the town. Have it face west, away from the entrance.

[IMAGE]

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:

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.