#33: opening intro cutscene

OpeningIntro (game/scripts/opening_intro.gd) plays on every New vacation
(not Continue, not when hosting co-op): the farmers leave in their loaded
station wagon, "Later that night....", a bickering UFO crew drops a part
whose blue flash brings the scarecrow (hung on a post in its T-pose) to life,
the UFO zooms off, then the loading screen and the first morning's sign.
Hold Space / Enter / A (or E, or the mouse button) 1 s to skip from any
stage; Escape pauses it; Restart the night skips it; Save & quit clears it.
It ends with the farm exactly as new_campaign() leaves it.

Hooks: ReviewPanel keeps the sign down while the intro has the farm (and
only focuses Start when the sign is up); DialogueDirector holds its
conversations and the sign, then intro_over() plays night 1's morning
conversations before the sign; Tutorial hides; FarmAudio gets set_scene /
end_scene (ambience and music held by a cutscene) and stop_cue (the morning
stinger plays with the sign instead); Main wires new_vacation(intro),
blocked, resume's freeze, restart and to_menu.

Tests: test_intro (45 checks); test_flow skips the new intro. Tool:
game/tools/capture_intro.gd saves a frame per stage for the timing review.
Docs: README, RULES, LAYOUT (staging points), PLAYTEST.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-07 22:54:24 -04:00
parent d96ef8b5be
commit c6daf3d217
19 changed files with 2112 additions and 21 deletions

View file

@ -10,6 +10,9 @@ extends Node
## starts while a menu is up (the shops, or Main's: DialogueBox.blocked) or the vacation is over,
## and a new morning (or a retry) takes down whatever was up. play() shows a conversation from
## code at any time; replay() (debug: F5) plays this phase's again.
## The opening intro (OpeningIntro) holds all of it: nothing starts while it's on screen (play()
## waits) and the sign stays down while it has the farm; at its end (intro_over()) night 1's
## morning conversations play, then the sign comes up.
const DIR := "res://game/resources/dialogue/"
@ -73,9 +76,9 @@ func due(n: int, phase: CampaignController.Phase) -> Array[Conversation]:
return out
## Shows conversation c now, or after the one that's up.
## Shows conversation c now, or after the one that's up (or the opening intro).
func play(c: Conversation) -> void:
if is_playing():
if is_playing() or _intro_busy():
_asked.append(c)
return
_played[c] = true
@ -98,6 +101,17 @@ func replay() -> void:
play(c)
## Whether a conversation would start now (the intro keeps the sign down for it).
func has_due() -> bool:
return not _asked.is_empty() or (not _queue.is_empty() and _elapsed() >= _queue[0].delay)
## The opening intro is over: this morning's conversations now, then the sign.
func intro_over() -> void:
if not is_playing():
_next()
## Takes down whatever is up and forgets what was due.
func stop() -> void:
_queue.clear()
@ -120,7 +134,7 @@ func _exit_tree() -> void:
func _process(_delta: float) -> void:
if _queue.is_empty() or is_playing() or box.is_blocked() or sim.campaign.is_over() or sim._menu_open():
if _queue.is_empty() or is_playing() or box.is_blocked() or sim.campaign.is_over() or sim._menu_open() or _intro_busy():
return
if _elapsed() >= _queue[0].delay:
play(_queue.pop_front())
@ -146,6 +160,11 @@ func _on_phase(phase: CampaignController.Phase, _previous: CampaignController.Ph
func _on_finished(_c: Conversation) -> void:
_release()
_next()
## The next conversation (asked for, or due), or the sign.
func _next() -> void:
if not _asked.is_empty():
play(_asked.pop_front())
elif not _queue.is_empty() and _elapsed() >= _queue[0].delay:
@ -155,10 +174,10 @@ func _on_finished(_c: Conversation) -> void:
## The morning sign steps aside while a conversation is up, and comes back (with the focus on
## Start the day) after it.
## Start the day) after it (not while the opening intro has the farm).
func _sign(show: bool) -> void:
var review := sim.review_panel if sim != null else null
if review == null:
if review == null or (show and sim.intro != null and sim.intro.running):
return
if show:
review.refresh()
@ -167,6 +186,10 @@ func _sign(show: bool) -> void:
review.mouse_filter = Control.MOUSE_FILTER_IGNORE
func _intro_busy() -> bool:
return sim != null and sim.intro != null and sim.intro.busy()
## Stops the farm for a conversation that pauses the game: the whole tree solo, this machine's
## scarecrow in co-op.
func _hold(pause: bool) -> void:

View file

@ -16,7 +16,8 @@ enum Align { SIDE, LEFT, CENTER, RIGHT }
## Optional mouth flaps: shown in turn with portrait while the words are being written.
@export var talk_frames: Array[Texture2D] = []
## Placeholder art while there's no portrait: one of Sketch.ICONS ("portrait" is the scarecrow,
## "thief" an alien, "breaker" a robot, "crow", "ufo").
## "thief" an alien, "breaker" a robot, "crow", "ufo", "farmer" the farmer in his straw hat,
## "farmers_wife" the farmer's wife).
@export var icon := ""
@export var side: HeadSide = HeadSide.LEFT

View file

@ -17,7 +17,9 @@ extends Node3D
## * UI: hover, click, back, open, close, error (ui(), also from the menus)
## * the opening intro (OpeningIntro, solo only, so never sent): the farmhouse door's creak, the
## car doors, the big UFO's hum (a loop), spin-up whine, and zoom away, the part's falling
## whistle, and the flash that brings the scarecrow to life
## whistle, and the flash that brings the scarecrow to life. While it plays it holds the
## ambience and the music (set_scene: its morning, then its night) whatever the phase, and it
## stops new_campaign()'s morning stinger (stop_cue) to play it with the sign instead
## * Music (the Music bus), by phase: "On the Farm" on the title screen (the farm's morning
## behind it), the morning, and by day, and when the farmers are back; "Purgatory" at night;
## none at dusk, at dawn, or after a Game Over (only the ambience). Tracks crossfade.
@ -168,6 +170,8 @@ var _bell_left: float = -1.0
var music_track := ""
var _music := {}
var _music_level := {}
## A cutscene holds the ambience and the music (set_scene); the phase gets them back at end_scene().
var scene := false
func _ready() -> void:
@ -369,6 +373,36 @@ func wire_buttons(node: Node) -> void:
button.pressed.connect(func() -> void: ui("ui_click"))
## A cutscene's ambience (day, night levels, 0..1; they crossfade to it) and music track ("" for
## none), whatever the phase, until end_scene().
func set_scene(ambience: Vector2, track: String) -> void:
scene = true
_ambience_target = ambience
music_track = track
## Gives the ambience (at once) and the music back to the phase.
func end_scene() -> void:
if not scene:
return
scene = false
var phase := sim.campaign.state.phase if sim != null else CampaignController.Phase.MORNING
_ambience_target = AMBIENCE.get(phase, Vector2(1.0, 0.0))
_ambience = _ambience_target
music_track = MUSIC_FOR.get(phase, "")
## Stops whatever a cue is playing now.
func stop_cue(cue: String) -> void:
for p in _voices_3d:
if p.playing and p.get_meta(&"cue", "") == cue:
p.stop()
for pool: Array[AudioStreamPlayer] in [_voices_ui, _voices_game]:
for p in pool:
if p.playing and p.get_meta(&"cue", "") == cue:
p.stop()
## The first stream of a cue (for looping players the cutscene owns).
func stream_of(cue: String) -> AudioStream:
var list: Array = streams.get(cue, [])
@ -432,6 +466,8 @@ func _process(delta: float) -> void:
func _on_phase(phase: CampaignController.Phase, _previous: CampaignController.Phase) -> void:
if scene:
return # the cutscene's (it gives them back at its end)
_ambience_target = AMBIENCE.get(phase, Vector2(1.0, 0.0))
music_track = MUSIC_FOR.get(phase, "")
match phase:

View file

@ -25,7 +25,8 @@ extends Node
## combat, and interactions are that machine's own scarecrow's (player 2's).
## FarmAudio plays every sound, Tutorial shows the first
## day's and night's tips, DialogueDirector the talking-head conversations (game/resources/
## dialogue/), and FarmersReturn plays the ending. Debug: T / G / H send in a
## dialogue/), OpeningIntro the cutscene before a new vacation's first morning (Main starts it),
## and FarmersReturn plays the ending. Debug: T / G / H send in a
## thief / a crow / a fence breaker at any time.
const SCARECROW_RADIUS := 0.4
@ -86,6 +87,7 @@ var audio: FarmAudio
var tutorial: Tutorial
var dialogue: DialogueDirector
var ending: FarmersReturn
var intro: OpeningIntro
## Flow-field rebuild after a structure change: running, and stats of the last one.
var rebuilding := false
var rebuilds: int = 0
@ -313,6 +315,12 @@ func _ready() -> void:
ending.name = "FarmersReturn"
add_child(ending)
ending.setup(self)
intro = OpeningIntro.new()
intro.name = "OpeningIntro"
add_child(intro)
intro.setup(self)
if review_panel != null:
review_panel.intro = intro
if end_panel != null:
end_panel.setup(campaign)
end_panel.ending = ending

View file

@ -5,6 +5,9 @@ extends Node
## circles the farm behind the menu; the HUD is hidden.
## * New vacation (asks first when it would replace a save), Continue (the saved morning,
## SaveGame; refused with the reason when the save can't be used), Settings, Quit.
## * A new vacation opens with the intro (OpeningIntro; held down, it skips) before its first
## morning's sign. Continue never plays it, nor does hosting co-op. Restart the night during
## it skips it; Save & quit to menu takes it down (the save is that first morning already).
## * During play, Escape / Start pauses (PauseMenu): the tree pauses, so the simulation tick,
## timers, enemies, and game sounds all freeze. Resume, Restart the night (asks first),
## Settings, Save & quit to menu, Quit the game (asks first).
@ -65,6 +68,8 @@ func _ready() -> void:
sim.tutorial.enabled = settings.show_tips
if sim.dialogue != null:
sim.dialogue.box.blocked = func() -> bool: return screen != Screen.PLAYING
if sim.intro != null:
sim.intro.blocked = func() -> bool: return screen != Screen.PLAYING
main_menu.continue_requested.connect(continue_vacation)
main_menu.new_requested.connect(_ask_new_vacation)
main_menu.settings_requested.connect(_open_settings)
@ -158,10 +163,13 @@ func continue_vacation() -> bool:
return true
## New vacation: a fresh farm, the morning of night 1 (saved at once, replacing any save).
func new_vacation() -> void:
## New vacation: a fresh farm, the morning of night 1 (saved at once, replacing any save), and
## the opening intro before its sign (unless intro is false: hosting co-op).
func new_vacation(intro := true) -> void:
_play()
sim.campaign.new_campaign()
if intro and sim.intro != null:
sim.intro.start()
func pause() -> void:
@ -188,7 +196,7 @@ func resume() -> void:
pause_menu.close()
screen = Screen.PLAYING
get_tree().paused = false
if sim.local_frozen:
if sim.local_frozen and not (sim.intro != null and sim.intro.running): # (the intro's freeze is its own)
sim.freeze_local(false)
if sim.dialogue != null:
sim.dialogue.hold() # a conversation that was up stops the farm again
@ -196,6 +204,9 @@ func resume() -> void:
func restart_night() -> void:
resume()
if sim.intro != null and sim.intro.running:
sim.intro.skip() # its night is the first morning already: straight to it
return
sim.campaign.retry_night()
@ -204,6 +215,8 @@ func restart_night() -> void:
func to_menu() -> void:
confirm.close()
settings_menu.close()
if sim.intro != null:
sim.intro.clear()
if sim.coop.is_client():
_leave_as_partner("")
return
@ -262,7 +275,7 @@ func _host_coop(mode: CoopLobby.Mode, player: String, resume: bool) -> void:
if not continue_vacation():
return
else:
new_vacation()
new_vacation(false) # no intro: the friend can join any time
lobby.host(mode, player)
if not resume and SaveGame.read(save_path).status == SaveGame.Status.OK:
confirm.ask("Start a new vacation? It replaces your saved one.", "New vacation", go)

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1 @@
uid://cppgmcqeukqgy

View file

@ -7,7 +7,8 @@ extends CenterContainer
## * the enemies defeated, by type;
## * the materials gathered over the day and night.
## Each row has its icon; a type or material with none isn't listed. "Start the day" (focused,
## so Enter / A work) ends it. The first morning explains the vacation instead of results.
## so Enter / A work) ends it. The first morning explains the vacation instead of results. It
## stays down while the opening intro has the farm (intro.running).
const CATEGORIES := ["Crops", "Animals", "Supplies"]
const ENEMY_TYPES := [EnemySystem.TYPE_CROW, EnemySystem.TYPE_THIEF, EnemySystem.TYPE_BREAKER, EnemySystem.TYPE_UFO]
@ -19,8 +20,9 @@ const BOTTOM := 70.0
const WIDTH := 880.0
var campaign: CampaignController
## Set by FarmSim: the night plans (last night's title).
## Set by FarmSim: the night plans (last night's title), and the opening intro.
var waves: WaveDirector
var intro: OpeningIntro
var _board: PanelContainer
var _title: Label
@ -151,7 +153,7 @@ static func backing() -> StyleBoxFlat:
func refresh() -> void:
if campaign == null:
return
visible = campaign.state.phase == CampaignController.Phase.MORNING
visible = campaign.state.phase == CampaignController.Phase.MORNING and not (intro != null and intro.running)
mouse_filter = Control.MOUSE_FILTER_STOP if visible else Control.MOUSE_FILTER_IGNORE
if not visible:
return
@ -177,7 +179,14 @@ func refresh() -> void:
_fill_list(_enemies, _no_enemies, func(t: int) -> int: return int(e.get("killed_" + EnemySystem.TYPE_NAMES[t], 0)))
_fill_list(_materials, _no_materials, func(m: String) -> int: return int(e.get("gathered_" + m, 0)))
_board.queue_redraw()
_start.grab_focus.call_deferred()
_focus_start.call_deferred()
## Start the day takes the focus (unless the sign went down again meanwhile: a hidden button
## would still take Enter).
func _focus_start() -> void:
if is_visible_in_tree():
_start.grab_focus()
## The results table as text, one row per category ("Crops 4 3 1"), for tests.

View file

@ -10,6 +10,7 @@ extends Control
## [Backspace / Back] hides them until the game is restarted; Settings turns them off.
## Finished tips stay finished for the session, so a retry or a second vacation doesn't repeat
## them.
## None show while a talking-head conversation or the opening intro is up.
const TEXT := {
"move": "Move with [W A S D] or the left stick. You're the scarecrow: keep the farm safe until the farmers are back.",
@ -93,7 +94,7 @@ func _process(delta: float) -> void:
return
var s := sim.campaign.state
if not enabled or dismissed or s.night != 1 or sim.campaign.is_over() or sim._menu_open() \
or (sim.dialogue != null and sim.dialogue.is_playing()):
or (sim.dialogue != null and sim.dialogue.is_playing()) or (sim.intro != null and sim.intro.busy()):
_show("")
return
_check_done()