diff --git a/game/resources/dialogue/intro/departure.tres b/game/resources/dialogue/intro/departure.tres new file mode 100644 index 0000000..6f38a02 --- /dev/null +++ b/game/resources/dialogue/intro/departure.tres @@ -0,0 +1,28 @@ +[gd_resource type="Resource" script_class="Conversation" format=3 uid="uid://c08yse6j7xhvk"] + +[ext_resource type="Script" uid="uid://b8csl51l2cwpg" path="res://game/scripts/conversation.gd" id="1_conversation"] +[ext_resource type="Script" uid="uid://oluompq3r367" path="res://game/scripts/dialogue_line.gd" id="2_line"] +[ext_resource type="Resource" path="res://game/resources/dialogue/speakers/farmer.tres" id="3_farmer"] +[ext_resource type="Resource" path="res://game/resources/dialogue/speakers/farmers_wife.tres" id="4_wife"] + +[sub_resource type="Resource" id="Resource_line1"] +script = ExtResource("2_line") +speaker = ExtResource("3_farmer") +text = "Well, I sure hope the farm will be okay." + +[sub_resource type="Resource" id="Resource_line2"] +script = ExtResource("2_line") +speaker = ExtResource("4_wife") +text = "Well then, you should have paid someone to come watch it for you instead of buying those front row tickets to the Bon Jovi concert." + +[sub_resource type="Resource" id="Resource_line3"] +script = ExtResource("2_line") +speaker = ExtResource("3_farmer") +text = "Ah, it'll be alright. What's the worst that could happen?" + +[resource] +script = ExtResource("1_conversation") +enabled = false +pause_game = true +auto_advance = 1.6 +lines = Array[ExtResource("2_line")]([SubResource("Resource_line1"), SubResource("Resource_line2"), SubResource("Resource_line3")]) diff --git a/game/resources/dialogue/intro/flight.tres b/game/resources/dialogue/intro/flight.tres new file mode 100644 index 0000000..5c6930f --- /dev/null +++ b/game/resources/dialogue/intro/flight.tres @@ -0,0 +1,38 @@ +[gd_resource type="Resource" script_class="Conversation" format=3 uid="uid://yna1lvpdeqe4"] + +[ext_resource type="Script" uid="uid://b8csl51l2cwpg" path="res://game/scripts/conversation.gd" id="1_conversation"] +[ext_resource type="Script" uid="uid://oluompq3r367" path="res://game/scripts/dialogue_line.gd" id="2_line"] +[ext_resource type="Resource" path="res://game/resources/dialogue/speakers/little_green_alien.tres" id="3_little"] +[ext_resource type="Resource" path="res://game/resources/dialogue/speakers/big_green_alien.tres" id="4_big"] + +[sub_resource type="Resource" id="Resource_line1"] +script = ExtResource("2_line") +speaker = ExtResource("3_little") +text = "I want to fly the ship!" + +[sub_resource type="Resource" id="Resource_line2"] +script = ExtResource("2_line") +speaker = ExtResource("4_big") +text = "You flew it all the way from the Andromeda galaxy! It's my turn!" + +[sub_resource type="Resource" id="Resource_line3"] +script = ExtResource("2_line") +speaker = ExtResource("3_little") +text = "Your tentacles don't even reach the pedals!" + +[sub_resource type="Resource" id="Resource_line4"] +script = ExtResource("2_line") +speaker = ExtResource("4_big") +text = "Mother said we take turns! Give me the stick!" + +[sub_resource type="Resource" id="Resource_line5"] +script = ExtResource("2_line") +speaker = ExtResource("3_little") +text = "Hands off! [shake]HANDS OFF![/shake]" + +[resource] +script = ExtResource("1_conversation") +enabled = false +pause_game = true +auto_advance = 1.6 +lines = Array[ExtResource("2_line")]([SubResource("Resource_line1"), SubResource("Resource_line2"), SubResource("Resource_line3"), SubResource("Resource_line4"), SubResource("Resource_line5")]) diff --git a/game/resources/dialogue/intro/uh_oh.tres b/game/resources/dialogue/intro/uh_oh.tres new file mode 100644 index 0000000..b4a0a69 --- /dev/null +++ b/game/resources/dialogue/intro/uh_oh.tres @@ -0,0 +1,23 @@ +[gd_resource type="Resource" script_class="Conversation" format=3 uid="uid://dvu0br3epblpb"] + +[ext_resource type="Script" uid="uid://b8csl51l2cwpg" path="res://game/scripts/conversation.gd" id="1_conversation"] +[ext_resource type="Script" uid="uid://oluompq3r367" path="res://game/scripts/dialogue_line.gd" id="2_line"] +[ext_resource type="Resource" path="res://game/resources/dialogue/speakers/big_green_alien.tres" id="3_big"] +[ext_resource type="Resource" path="res://game/resources/dialogue/speakers/little_green_alien.tres" id="4_little"] + +[sub_resource type="Resource" id="Resource_line1"] +script = ExtResource("2_line") +speaker = ExtResource("3_big") +text = "Uh oh.... we should go tell mother." + +[sub_resource type="Resource" id="Resource_line2"] +script = ExtResource("2_line") +speaker = ExtResource("4_little") +text = "Are you crazy!!! Let's just get out of here, maybe no one will notice!" + +[resource] +script = ExtResource("1_conversation") +enabled = false +pause_game = true +auto_advance = 1.6 +lines = Array[ExtResource("2_line")]([SubResource("Resource_line1"), SubResource("Resource_line2")]) diff --git a/game/resources/dialogue/speakers/big_green_alien.tres b/game/resources/dialogue/speakers/big_green_alien.tres new file mode 100644 index 0000000..fa66267 --- /dev/null +++ b/game/resources/dialogue/speakers/big_green_alien.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" script_class="DialogueSpeaker" format=3 uid="uid://chciiyc5efsqv"] + +[ext_resource type="Script" path="res://game/scripts/dialogue_speaker.gd" id="1_speaker"] +[ext_resource type="AudioStream" path="res://assets/audio/kenney/interface/pluck_001.ogg" id="2_voice"] + +[resource] +script = ExtResource("1_speaker") +display_name = "Big Green Alien" +icon = "thief" +side = 1 +portrait_height = 380.0 +voice = ExtResource("2_voice") +voice_pitch = 1.05 +voice_every = 3 diff --git a/game/resources/dialogue/speakers/farmer.tres b/game/resources/dialogue/speakers/farmer.tres new file mode 100644 index 0000000..07e9411 --- /dev/null +++ b/game/resources/dialogue/speakers/farmer.tres @@ -0,0 +1,13 @@ +[gd_resource type="Resource" script_class="DialogueSpeaker" format=3 uid="uid://dtxc1nfa3plr0"] + +[ext_resource type="Script" path="res://game/scripts/dialogue_speaker.gd" id="1_speaker"] +[ext_resource type="AudioStream" path="res://assets/audio/kenney/interface/pluck_002.ogg" id="2_voice"] + +[resource] +script = ExtResource("1_speaker") +display_name = "Farmer" +icon = "farmer" +portrait_height = 320.0 +voice = ExtResource("2_voice") +voice_pitch = 0.65 +voice_every = 3 diff --git a/game/resources/dialogue/speakers/farmers_wife.tres b/game/resources/dialogue/speakers/farmers_wife.tres new file mode 100644 index 0000000..e9cf97b --- /dev/null +++ b/game/resources/dialogue/speakers/farmers_wife.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" script_class="DialogueSpeaker" format=3 uid="uid://c5onilw721jwg"] + +[ext_resource type="Script" path="res://game/scripts/dialogue_speaker.gd" id="1_speaker"] +[ext_resource type="AudioStream" path="res://assets/audio/kenney/interface/pluck_001.ogg" id="2_voice"] + +[resource] +script = ExtResource("1_speaker") +display_name = "Farmer's Wife" +icon = "farmers_wife" +side = 1 +portrait_height = 320.0 +voice = ExtResource("2_voice") +voice_pitch = 1.2 +voice_every = 3 diff --git a/game/scripts/sketch.gd b/game/scripts/sketch.gd index da991c9..394887f 100644 --- a/game/scripts/sketch.gd +++ b/game/scripts/sketch.gd @@ -6,8 +6,8 @@ extends RefCounted ## sketched outlines (each edge drawn twice, slightly off, overshooting its corners), painted ## fills (a flat color, a lighter dab, a darker rim), and painted icons for the weapons, the ## materials, the backpack, the sun and moon, the scarecrow's portrait, what thieves take (crops, -## animals, supplies), and the enemies; and the morning screen's wooden sign (planks, a nailed -## sheet of paper, leaves). Every wobble comes from a hash of a seed, so a shape is drawn the +## animals, supplies), the enemies, and the farmer and his wife (talking heads); and the morning +## screen's wooden sign (planks, a nailed sheet of paper, leaves). Every wobble comes from a hash of a seed, so a shape is drawn the ## same way each frame (no flicker). ## Icons are designed in a 100 x 100 box and scaled to the rect they're drawn in. @@ -39,7 +39,7 @@ const LEAF := Color(0.42, 0.64, 0.22) ## EnemySystem.TYPE_NAMES, and these. const ICONS: Array[String] = ["pitchfork", "corn_shooter", "pumpkin_bomb", "potato_cannon", "shurikens", "propane_torch", "alien_ray", "wood", "scrap", "straw", "alien_goop", "backpack", "sun", "moon", "portrait", - "crops", "animals", "supplies", "crow", "thief", "breaker", "ufo"] + "crops", "animals", "supplies", "crow", "thief", "breaker", "ufo", "farmer", "farmers_wife"] static var _font: Font @@ -521,6 +521,85 @@ static func _icon(ci: CanvasItem, id: String) -> void: for i in 5: ci.draw_circle(Vector2(18.0 + i * 16.0, 57.0 + absf(i - 2.0) * -1.5), 3.6, Color(1.0, 0.86, 0.35)) ci.draw_circle(Vector2(43, 38), 3.5, Color(1.0, 1.0, 1.0, 0.85)) + "farmer": # a round face under a straw hat, a big moustache + var skin := Color(0.95, 0.73, 0.56) + var straw := Color(0.93, 0.78, 0.4) + var brown := Color(0.48, 0.31, 0.17) + for k: float in [-1.0, 1.0]: # ears + paint(ci, blob(Vector2(50.0 + 29.0 * k, 61.0), 6.0, 9.0, 291.0 + k), skin.darkened(0.08), 293.0 + k, 2.0) + paint(ci, blob(Vector2(50, 60), 30.0, 30.0, 295.0, 0.03), skin, 296.0) + for k: float in [-1.0, 1.0]: + ci.draw_colored_polygon(blob(Vector2(50.0 + 17.0 * k, 68.0), 7.0, 5.0, 297.0 + k), Color(0.93, 0.4, 0.34, 0.35)) # sunburnt + line(ci, Vector2(50.0 + 6.0 * k, 48.0), Vector2(50.0 + 18.0 * k, 47.0), brown, 3.5, 299.0 + k, 0.6) + ci.draw_circle(Vector2(50.0 + 12.0 * k, 55.0), 3.4, INK) + ci.draw_circle(Vector2(51.2 + 12.0 * k, 53.8), 1.1, Color.WHITE) + paint(ci, blob(Vector2(50, 63), 6.5, 6.0, 301.0), skin.lerp(Color(0.88, 0.42, 0.36), 0.3), 302.0, 1.2) # nose + var tache := _bezier(Vector2(24, 78), Vector2(34, 62), Vector2(50, 69), 8) + tache.append_array(_bezier(Vector2(50, 69), Vector2(66, 62), Vector2(76, 78), 8).slice(1)) + tache.append_array(_bezier(Vector2(76, 78), Vector2(64, 77), Vector2(50, 78), 6).slice(1)) + tache.append_array(_bezier(Vector2(50, 78), Vector2(36, 77), Vector2(24, 78), 6).slice(1, -1)) + paint(ci, tache, brown, 303.0, 2.0) + ci.draw_polyline(_bezier(Vector2(44, 81), Vector2(50, 85), Vector2(56, 81), 6), INK, 2.2, true) # a grin under it + var top := _bezier(Vector2(30, 16), Vector2(38, 2), Vector2(50, 12), 8) # the crown, pinched at the top + top.append_array(_bezier(Vector2(50, 12), Vector2(62, 2), Vector2(70, 16), 8).slice(1)) + paint(ci, _closed(top, [Vector2(72, 34), Vector2(28, 34)]), straw.darkened(0.05), 304.0) + paint(ci, PackedVector2Array([Vector2(30, 20), Vector2(70, 19), Vector2(71, 28), Vector2(29, 29)]), Color(0.62, 0.2, 0.12), 305.0, 0.0) # the band + paint(ci, blob(Vector2(50, 36), 48.0, 8.5, 306.0, 0.03, 32, -0.03), straw, 307.0) # the brim + var weave := Color(straw.darkened(0.35), 0.7) + for i in 8: + var x := 10.0 + i * 11.5 + line(ci, Vector2(x, 33.0), Vector2(x + 4.0, 40.0), weave, 1.5, 308.0 + i, 0.4) + for i in 3: + line(ci, Vector2(38.0 + i * 12.0, 15.0 - absf(i - 1.0) * 4.0), Vector2(37.0 + i * 13.0, 19.0), weave, 1.5, 316.0 + i, 0.4) + "farmers_wife": # curls under a straw sun hat with a flower in its ribbon + var skin := Color(0.97, 0.78, 0.63) + var hair := Color(0.7, 0.33, 0.15) + var straw := Color(0.95, 0.82, 0.47) + for i in 6: # curls down both sides, behind the face + for k: float in [-1.0, 1.0]: + var at := Vector2(50.0 + k * (28.0 + 2.5 * noise(331.0 + i + k * 7.0)), 42.0 + i * 8.0) + paint(ci, blob(at, 8.5, 7.0, 333.0 + i * 2.0 + k, 0.08), hair, 345.0 + i * 2.0 + k, 2.0) + paint(ci, blob(Vector2(50, 60), 24.0, 28.0, 357.0, 0.03), skin, 358.0) + for k: float in [-1.0, 1.0]: # curls at the temples, over the face's edge + paint(ci, blob(Vector2(50.0 + 22.0 * k, 47.0), 6.5, 5.5, 359.0 + k), hair.lightened(0.06), 361.0 + k, 1.5) + ci.draw_colored_polygon(blob(Vector2(50.0 + 14.0 * k, 68.0), 6.0, 4.5, 369.0 + k), Color(0.95, 0.42, 0.45, 0.4)) # rosy + var eye := Vector2(50.0 + 10.0 * k, 56.0) + ci.draw_circle(eye, 3.2, INK) + ci.draw_circle(eye + Vector2(1.0, -1.1), 1.0, Color.WHITE) + for j in 3: # lashes + var dir := Vector2.from_angle(-PI * 0.5 + k * (0.3 + 0.38 * j)) + line(ci, eye + dir * 3.0, eye + dir * 7.0, INK, 1.6, 371.0 + j * 2.0 + k, 0.3) + ci.draw_polyline(_bezier(Vector2(51, 60), Vector2(46, 66), Vector2(52, 66), 6), skin.darkened(0.4), 2.0, true) # nose + var lips := _bezier(Vector2(43, 73), Vector2(50, 71), Vector2(57, 73), 6) + lips.append_array(_bezier(Vector2(57, 73), Vector2(50, 80), Vector2(43, 73), 6).slice(1, -1)) + paint(ci, lips, Color(0.84, 0.24, 0.26), 378.0, 1.5) + var top := _bezier(Vector2(32, 20), Vector2(50, -2), Vector2(68, 20), 10) # the crown + paint(ci, _closed(top, [Vector2(69, 36), Vector2(31, 36)]), straw.darkened(0.05), 379.0) + paint(ci, PackedVector2Array([Vector2(33, 19), Vector2(67, 18), Vector2(68, 27), Vector2(32, 28)]), Color(0.38, 0.6, 0.86), 380.0, 0.0) # the ribbon + paint(ci, blob(Vector2(50, 37), 49.0, 9.5, 381.0, 0.05, 32, -0.05), straw, 382.0) # the brim, a little tipped + var weave := Color(straw.darkened(0.35), 0.7) + for i in 8: + var x := 9.0 + i * 11.5 + line(ci, Vector2(x, 34.0), Vector2(x + 4.0, 41.0), weave, 1.5, 383.0 + i, 0.4) + var flower := Vector2(64, 23) + leaf(ci, flower + Vector2(2, 2), 15.0, 0.4, 391.0) + for j in 5: + paint(ci, blob(flower + Vector2.from_angle(TAU * j / 5.0 - 0.3) * 5.5, 4.6, 4.6, 392.0 + j), Color(0.96, 0.42, 0.56), 397.0 + j, 1.2) + ci.draw_circle(flower, 3.4, Color(1.0, 0.84, 0.3)) + + +## An open outline (pts) closed with straight edges through corners, in steps about 5 long, so +## its points stay spread evenly (paint() places its lighter dab from their average). +static func _closed(pts: PackedVector2Array, corners: Array[Vector2]) -> PackedVector2Array: + var out := pts.duplicate() + var path: Array[Vector2] = [pts[pts.size() - 1]] + path.append_array(corners) + path.append(pts[0]) + for i in path.size() - 1: + var n := maxi(int(path[i].distance_to(path[i + 1]) / 5.0), 1) + for j in range(1, n + 1 if i < path.size() - 2 else n): # (not pts[0] again) + out.append(path[i].lerp(path[i + 1], float(j) / n)) + return out ## Points along a circle (center c, radius r) between where it crosses another circle (o, ro), diff --git a/game/tests/test_dialogue.gd b/game/tests/test_dialogue.gd index ab0be54..31617fa 100644 --- a/game/tests/test_dialogue.gd +++ b/game/tests/test_dialogue.gd @@ -6,10 +6,20 @@ extends RefCounted ## night's phase and delay, pauses the farm for it and lets it go after, puts the morning sign ## aside meanwhile, doesn't replay it on a retry but does on a new vacation, ## takes it down on a new morning, plays several in order, waits under a menu, and lets one that -## doesn't pause the game go on by itself. +## doesn't pause the game go on by itself. The opening intro's conversations (dialogue/intro/) +## have their lines and speakers and never play by themselves; the farmer's and his wife's heads +## (Sketch icons) draw. const P := CampaignController.Phase const DT := 1.0 / 60.0 +const INTRO := "res://game/resources/dialogue/intro/" +const SPEAKERS := "res://game/resources/dialogue/speakers/" +## The intro's conversations: who says each line, in order. +const INTRO_LINES := { + "departure": ["Farmer", "Farmer's Wife", "Farmer"], + "flight": ["Little Green Alien", "Big Green Alien", "Little Green Alien", "Big Green Alien", "Little Green Alien"], + "uh_oh": ["Big Green Alien", "Little Green Alien"], +} var r: GameTestRunner var sim: FarmSim @@ -23,6 +33,8 @@ var scarecrow: DialogueSpeaker func run(p_r: GameTestRunner) -> void: r = p_r _saved() + _intro() + await _heads_draw() var farm := (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D r.root.add_child(farm) await r.process_frame @@ -64,8 +76,67 @@ func _saved() -> void: if line == null or line.text.strip_edges() == "": bad.append(conv.resource_path) r.check(bad.is_empty(), "every saved conversation has lines with words and plays within the vacation (bad: %s)" % [bad]) - r.check(DialogueDirector.load_all("res://game/resources/dialogue/speakers/").is_empty(), - "a speaker's file isn't taken for a conversation") + r.check(DialogueDirector.load_all(SPEAKERS).is_empty(), "a speaker's file isn't taken for a conversation") + + +## The intro's conversations load with their lines and speakers, wait for the intro to play them +## (off, in a subfolder), and their speakers stand where they should. +func _intro() -> void: + for n: String in INTRO_LINES: + var conv := load(INTRO.path_join(n + ".tres")) as Conversation + if conv == null: + r.check(false, "intro/%s.tres loads as a Conversation" % n) + continue + var who: Array[String] = [] + for line in conv.lines: + who.append(line.speaker.display_name if line != null and line.speaker != null and line.text.strip_edges() != "" else "?") + r.check(who == INTRO_LINES[n], "intro/%s: its lines by %s (got %s)" % [n, INTRO_LINES[n], who]) + r.check(not conv.enabled and conv.pause_game and is_equal_approx(conv.auto_advance, 1.6), + "intro/%s is off (only the intro plays it), pauses (takes the taps), and goes on after 1.6 s" % n) + var paths: Array[String] = [] + for conv in DialogueDirector.load_all(DialogueDirector.DIR): + paths.append(conv.resource_path.get_file()) + r.check(paths == ["morning_day_2.tres"], "the director still plays only morning_day_2 by itself, not the intro's (got %s)" % [paths]) + r.check(DialogueDirector.load_all(INTRO).is_empty(), "and even loaded from intro/ they're off") + var big := load(SPEAKERS + "big_green_alien.tres") as DialogueSpeaker + var little := load(SPEAKERS + "little_green_alien.tres") as DialogueSpeaker + var farmer := load(SPEAKERS + "farmer.tres") as DialogueSpeaker + var wife := load(SPEAKERS + "farmers_wife.tres") as DialogueSpeaker + r.check(big != null and little != null and farmer != null and wife != null, "the intro's speakers load") + if big == null or little == null or farmer == null or wife == null: + return + r.check(big.icon == little.icon and big.portrait_height > little.portrait_height and big.voice_pitch < little.voice_pitch, + "the Big Green Alien is the little one's head, bigger (%d px), with a lower voice" % big.portrait_height) + r.check(farmer.icon == "farmer" and wife.icon == "farmers_wife" and farmer.voice_pitch < wife.voice_pitch, + "the farmer and his wife have their own heads; his voice is the lower") + r.check(farmer.side == DialogueSpeaker.HeadSide.LEFT and wife.side == DialogueSpeaker.HeadSide.RIGHT + and big.side == DialogueSpeaker.HeadSide.RIGHT and little.side == DialogueSpeaker.HeadSide.LEFT, + "the farmer and the little alien on the left, his wife and the big alien on the right") + var no_head: Array[String] = [] + for f in ResourceLoader.list_directory(SPEAKERS): + var sp := load(SPEAKERS + f) as DialogueSpeaker + if sp != null and sp.portrait == null and not Sketch.ICONS.has(sp.icon): + no_head.append(f) + r.check(no_head.is_empty(), "every speaker has a head: a portrait or a Sketch icon (none: %s)" % [no_head]) + + +## The farmer's and his wife's heads are Sketch icons and draw (big, and HUD-small) without error. +func _heads_draw() -> void: + var ids: Array[String] = ["farmer", "farmers_wife"] + r.check(Sketch.ICONS.has("farmer") and Sketch.ICONS.has("farmers_wife"), "the farmer and his wife are Sketch icons") + var drawn: Array[String] = [] + var canvas := Control.new() + canvas.size = Vector2(400.0, 400.0) + canvas.draw.connect(func() -> void: + for id in ids: + Sketch.icon(canvas, id, Rect2(Vector2.ZERO, Vector2(380.0, 380.0))) + Sketch.icon(canvas, id, Rect2(Vector2(10.0, 10.0), Vector2(40.0, 40.0))) + drawn.append(id)) + r.root.add_child(canvas) + await r.process_frame + await r.process_frame + r.check(drawn == ids, "their heads draw without an error (drew %s)" % [drawn]) + canvas.queue_free() func _writing() -> void: