diff --git a/docs/booth-runbook.md b/docs/booth-runbook.md index 0a548ae7..a22dc61f 100644 --- a/docs/booth-runbook.md +++ b/docs/booth-runbook.md @@ -96,3 +96,13 @@ tools/booth/macos/setup.sh --undo --apply ``` `--undo` puts back the settings the first setup recorded on that Mac. Then turn off automatic login and Do Not Disturb, and copy the session logs. + +## Four-controller co-op + +On the hub or in any of the six games, click the left stick **(L3)** on each DualSense to join. The order sets P1 through P4. A visitor already playing solo with a controller keeps P1 when a second visitor joins. Each player's numbered, colored badge follows their Hoppy. The team shares the score. + +- In the platformers, any teammate can collect a pickup, fight the boss or activate MERGE. Trailing players catch up when the leader lands. Reaching the boss rallies fallen teammates. +- In both brawlers, each fighter controls their own combos and weapon. A cleared room's exit gathers the team and brings back fallen fighters with one heart. +- In Endless Runner, players share three lanes in a staggered formation. Each can dodge, collect power-ups and hit hazards. Health, shields and pursuit belong to the team. + +If a controller drops, the game holds the team's places. Reconnect it to continue. When several identical pads are missing, use the face button beside **your player number** on the recovery screen. A spare can reclaim a seat the same way. Returning to the hub clears the team for the next visitors. At an unattended booth the idle timer does this automatically, including while a pad is missing. diff --git a/docs/previews/four-player-coop.jpg b/docs/previews/four-player-coop.jpg new file mode 100644 index 00000000..724a4751 Binary files /dev/null and b/docs/previews/four-player-coop.jpg differ diff --git a/hoppys-adventure-arcade/app/app_router.gd b/hoppys-adventure-arcade/app/app_router.gd index c375b39c..10f658a5 100644 --- a/hoppys-adventure-arcade/app/app_router.gd +++ b/hoppys-adventure-arcade/app/app_router.gd @@ -136,6 +136,7 @@ func go(route: String, reason := "menu") -> bool: if session_log: session_log.route_changed(route, reason) if route == ATTRACT_ROUTE: + LocalParty.reset() game_overs = 0 how_to_play_seen.clear() if wants_how_to_play(route): @@ -308,7 +309,7 @@ func _process(delta: float) -> void: return idle_seconds = 0.0 var scene := get_tree().current_scene - if scene == null or scene.scene_file_path != ROUTES[ATTRACT_ROUTE]: + if scene == null or scene.scene_file_path != ROUTES[ATTRACT_ROUTE] or LocalParty.size > 0: go(ATTRACT_ROUTE, "idle") func smoke_routes() -> void: diff --git a/hoppys-adventure-arcade/app/arcade_team.gd b/hoppys-adventure-arcade/app/arcade_team.gd new file mode 100644 index 00000000..a46a027f --- /dev/null +++ b/hoppys-adventure-arcade/app/arcade_team.gd @@ -0,0 +1,64 @@ +extends Node +## A stage owns its actors. The party owns their seat numbers across stage changes and retries. +var members: Array[CharacterBody2D] = [] +var _badges: Array[Label] = [] +var _shown_hp: Array[int] = [] +var _spawn: Callable +var _badge_height: float + + +func setup(first: CharacterBody2D, spawn: Callable, badge_height: float) -> void: + members.assign([first]) + _badges.clear() + _shown_hp.clear() + _spawn = spawn + _badge_height = badge_height + if not LocalParty.changed.is_connected(sync): + LocalParty.changed.connect(sync) + sync() + + +func sync() -> void: + if not is_inside_tree() or members.is_empty(): return + while members.size() < LocalParty.size: + var seat := members.size() + var actor: CharacterBody2D = _spawn.call(seat) + actor.seat = seat + actor.reset_physics_interpolation() + members.append(actor) + if LocalParty.size > 0: + for actor in members: + actor.controls.names = LocalParty.bindings(actor.seat) + while _badges.size() < members.size(): + var seat := _badges.size() + _badges.append(LocalParty.decorate(members[seat], seat, _badge_height)) + _shown_hp.append(-1) + update_health() + + +func update_health() -> void: + for i in _badges.size(): + var hp: int = members[i].hp + if hp == _shown_hp[i]: continue + _shown_hp[i] = hp + _badges[i].text = "P%d %s" % [i + 1, "♥".repeat(hp) if hp > 0 else "OUT"] + + +func nearest(point: Vector2) -> CharacterBody2D: + var closest := members[0] + var best := INF + for actor in members: + if actor.hp <= 0: continue + var distance := actor.position.distance_squared_to(point) + if distance < best: + best = distance + closest = actor + return closest + + +func front() -> CharacterBody2D: + var leader := members[0] + for actor in members: + if actor.hp > 0 and (leader.hp <= 0 or actor.position.x > leader.position.x): + leader = actor + return leader diff --git a/hoppys-adventure-arcade/app/arcade_team.gd.uid b/hoppys-adventure-arcade/app/arcade_team.gd.uid new file mode 100644 index 00000000..acd65aac --- /dev/null +++ b/hoppys-adventure-arcade/app/arcade_team.gd.uid @@ -0,0 +1 @@ +uid://dj1x2v8c8crmq diff --git a/hoppys-adventure-arcade/app/controller_service.gd b/hoppys-adventure-arcade/app/controller_service.gd index 8c956c86..383f7b96 100644 --- a/hoppys-adventure-arcade/app/controller_service.gd +++ b/hoppys-adventure-arcade/app/controller_service.gd @@ -2,7 +2,7 @@ extends Node ## Which controller the player is using, what its buttons are called, and what happens when it ## disconnects. ## -## Every pad binding answers every controller (device -1), so any pad on the table can play. The +## In solo play every pad binding answers every controller (device -1), so any pad on the table can play. The ## pad that last sent input is player one: prompts name its buttons ("Cross", "A" or "B" for the ## same bottom button). If that pad disconnects during a game, the game pauses through its own ## pause menu and a banner asks for it back; the game resumes when the pad reconnects. Start on @@ -55,7 +55,7 @@ func use_hardware(hardware: RefCounted) -> void: roster.role_restored.connect(_on_role_restored) _set_paused_for_controller(false) roster.refresh() - _update_family() + update_family() ## The label of an action's first pad binding for the current controller, or "" without one. @@ -86,6 +86,7 @@ func _input(event: InputEvent) -> void: ## Lets a pad's press make it player one. _input calls this; so does the how-to-play card, which ## swallows input before this autoload would see it. func observe(event: InputEvent) -> void: + if LocalParty.size > 0: return var device := _gameplay_device(event) if device < 0 or roster.role_of(device) == PLAYER: return @@ -119,12 +120,12 @@ func _on_joy_connection_changed(device: int, connected: bool) -> void: func _on_role_assigned(_role: StringName, _device: int) -> void: - _update_family() + update_family() func _on_role_lost(_role: StringName, _device: int) -> void: - _update_family() - if not _in_gameplay(): + update_family() + if LocalParty.size > 0 or not _in_gameplay(): roster.release(PLAYER) else: # Connection callbacks can arrive while Input is dispatching; pause once it is idle. @@ -132,13 +133,13 @@ func _on_role_lost(_role: StringName, _device: int) -> void: func _on_role_restored(_role: StringName, _device: int) -> void: - _update_family() + update_family() _resume_for_controller.call_deferred() func _pause_for_controller() -> void: # A game already paused by its player stays paused, and a reconnect won't resume it. - if roster.is_waiting(PLAYER) and _in_gameplay() and not get_tree().paused: + if LocalParty.size == 0 and roster.is_waiting(PLAYER) and _in_gameplay() and not get_tree().paused: _toggle_pause() _set_paused_for_controller(get_tree().paused) @@ -154,9 +155,13 @@ func _set_paused_for_controller(value: bool) -> void: banner.visible = value -func _update_family() -> void: +func update_family() -> void: var device: int = roster.device_for(PLAYER) var current: String = roster.family(device) if device >= 0 else "" + var party := get_node_or_null("/root/LocalParty") + if party and party.size > 0: + var host: int = party.roster.device_for(PLAYER) + if host >= 0: current = party.roster.family(host) if current != family: family = current family_changed.emit(family) diff --git a/hoppys-adventure-arcade/app/how_to_play.gd b/hoppys-adventure-arcade/app/how_to_play.gd index 49ff27bb..0f882989 100644 --- a/hoppys-adventure-arcade/app/how_to_play.gd +++ b/hoppys-adventure-arcade/app/how_to_play.gd @@ -259,7 +259,7 @@ func close() -> void: var router := tree.root.get_node_or_null(^"AppRouter") var leaving: bool = router != null and router.busy var self_paused: bool = scene != null and scene.has_method("is_player_paused") and scene.is_player_paused() - if tree.current_scene == scene and not leaving and not self_paused: + if tree.current_scene == scene and not leaving and not self_paused and not tree.root.get_node("LocalParty").hold_for_reconnect(): tree.paused = false elif is_instance_valid(return_focus) and return_focus.is_visible_in_tree(): return_focus.grab_focus() diff --git a/hoppys-adventure-arcade/app/local_party.gd b/hoppys-adventure-arcade/app/local_party.gd new file mode 100644 index 00000000..a9c04be9 --- /dev/null +++ b/hoppys-adventure-arcade/app/local_party.gd @@ -0,0 +1,242 @@ +extends CanvasLayer +## Explicit local co-op. Until the first stick click, the existing solo controls own the game. +signal changed + +const Roster := preload("res://addons/cr_kit/input/device_roster.gd") +const ROLES := [&"p1", &"p2", &"p3", &"p4"] +const COLORS := [Color("#80e5bb"), Color("#84c7ff"), Color("#ffcc73"), Color("#f29dce")] +const CLAIM_BUTTONS := [JOY_BUTTON_A, JOY_BUTTON_B, JOY_BUTTON_X, JOY_BUTTON_Y] +const CLAIM_LABELS := ["Cross", "Circle", "Square", "Triangle"] +const ACTIONS := [&"move_left", &"move_right", &"move_up", &"move_down", &"jump", &"attack", &"roll", + &"brawl_jump", &"brawl_attack", &"brawl_pickup", &"review_burst"] + +var roster: Roster +var size := 0 +var _solo_device := -1 +var _bindings: Dictionary = {} +var _devices: Dictionary = {} +var _owned_pause := false +var _blocked_buttons := {} +var _notice: Label +var _hint: Label + + +func _ready() -> void: + process_mode = Node.PROCESS_MODE_ALWAYS + layer = 95 + _notice = Label.new() + _notice.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + _notice.vertical_alignment = VERTICAL_ALIGNMENT_CENTER + _notice.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + var shade := StyleBoxFlat.new() + shade.bg_color = Color(0.035, 0.07, 0.11, 0.94) + _notice.add_theme_stylebox_override("normal", shade) + _notice.add_theme_font_size_override("font_size", 26) + _notice.hide() + add_child(_notice) + _hint = Label.new() + _hint.set_anchors_and_offsets_preset(Control.PRESET_BOTTOM_RIGHT) + _hint.grow_horizontal = Control.GROW_DIRECTION_BEGIN + _hint.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + _hint.offset_left = -240 + _hint.offset_top = -34 + _hint.offset_right = -16 + _hint.offset_bottom = -8 + _hint.add_theme_constant_override("outline_size", 5) + _hint.add_theme_font_size_override("font_size", 15) + _hint.mouse_filter = Control.MOUSE_FILTER_IGNORE + add_child(_hint) + use_hardware(null) + changed.connect(ControllerService.update_family) + Input.joy_connection_changed.connect(connection_changed) + # Godot visits the viewport's children in reverse order for input. An internal + # back child keeps the filter ahead of gameplay, GUI and newly opened modals. + var gate := InputGate.new() + gate.filter = handle_event + gate.process_mode = Node.PROCESS_MODE_ALWAYS + get_tree().root.add_child.call_deferred(gate, false, Node.INTERNAL_MODE_BACK) + get_tree().scene_changed.connect(_scene_changed) + + +class InputGate extends Node: + var filter: Callable + + func _input(event: InputEvent) -> void: + if filter.is_valid() and filter.call(event): + get_viewport().set_input_as_handled() + + +func use_hardware(hardware: RefCounted) -> void: + reset() + roster = Roster.new(ROLES, hardware) + roster.auto_assign = false + roster.role_assigned.connect(_assigned) + roster.role_lost.connect(_lost) + roster.role_restored.connect(_assigned) + roster.refresh() + + +func connection_changed(device: int, connected: bool) -> void: + _blocked_buttons.erase(device) + if not connected and _solo_device == device: _solo_device = -1 + roster.on_joy_connection_changed(device, connected) + _update_display() + + +func reset() -> void: + if roster: + for role in ROLES: + roster.release(role) + _clear_bindings() + _blocked_buttons.clear() + size = 0 + _solo_device = -1 + _release_pause() + if _notice: + _notice.hide() + changed.emit() + + +func _scene_changed() -> void: + refresh_bindings() + _update_display() + + +func _assigned(_role: StringName, _device: int) -> void: + size = 0 + for role in ROLES: + if roster.device_for(role) >= 0 or roster.is_waiting(role): + size += 1 + refresh_bindings() + _update_display() + changed.emit() + + +func _lost(_role: StringName, _device: int) -> void: + refresh_bindings() + _update_display() + changed.emit() + + +## Called when another modal hands the pause back while a seat is still missing. +func hold_for_reconnect() -> bool: + if not _notice.visible: return false + _owned_pause = true + return true + + +func _update_display() -> void: + var missing := roster.waiting_roles() + if missing.is_empty(): + _release_pause() + else: + if not get_tree().paused: + get_tree().paused = true + _owned_pause = true + var lines := PackedStringArray(["Controller disconnected", ""]) + for role in missing: + var seat := ROLES.find(role) + lines.append("P%d · Reconnect, or press %s on a free controller" % [seat + 1, CLAIM_LABELS[seat]]) + lines.append("\nOptions on a joined controller or Esc returns to the arcade") + _notice.text = "\n".join(lines) + _notice.visible = not missing.is_empty() + var scene := get_tree().current_scene + _hint.visible = scene != null and scene.has_method("is_player_paused") and size < 4 \ + and not roster.connected_devices().is_empty() and missing.is_empty() + _hint.text = "L3 · Click to join" if size == 0 else "%d/4 · L3 to join" % size + + +func _release_pause() -> void: + if _owned_pause: + _owned_pause = false + var scene := get_tree().current_scene + if not (scene and scene.has_method("is_player_paused") and scene.is_player_paused()) \ + and not (is_instance_valid(AppRouter.how_to_play) and AppRouter.how_to_play.visible): + get_tree().paused = false + + +func handle_event(event: InputEvent) -> bool: + if roster == null: return false + var button := event as InputEventJoypadButton + if button and _blocked_buttons.get(button.device, -1) == button.button_index: + if not button.pressed: _blocked_buttons.erase(button.device) + return true + if _notice.visible: + if button and button.pressed and roster.role_of(button.device).is_empty(): + var seat := CLAIM_BUTTONS.find(button.button_index) + if seat >= 0 and roster.is_waiting(ROLES[seat]): + roster.claim(button.device, ROLES[seat]) + _blocked_buttons[button.device] = button.button_index + elif (event.is_action_pressed("pause") or (event is InputEventKey and event.is_action_pressed("ui_cancel"))) and not AppRouter.busy: + AppRouter.go("hub") + AppRouter.note_input(event) + return true + if button and button.button_index == JOY_BUTTON_LEFT_STICK and button.pressed: + if not AppRouter.busy and not (AppRouter.next_player and AppRouter.next_player.visible): + if size == 0 and _solo_device >= 0 and _solo_device != button.device: + roster.claim(_solo_device) + roster.claim(button.device) + _blocked_buttons[button.device] = button.button_index + AppRouter.note_input(event) + return true + if size == 0: + if button and button.pressed: + _solo_device = button.device + elif event is InputEventJoypadMotion and absf(event.axis_value) > 0.5: + var scene := get_tree().current_scene + if scene and scene.has_method("is_player_paused"): + _solo_device = event.device + return size > 0 and (button != null or event is InputEventJoypadMotion) and roster.role_of(event.device).is_empty() + + +## Copy each game's own mappings, including analog deadzones, once they have been installed. +## The engine keeps independent pressed/released edges for each device-specific action. +func refresh_bindings() -> void: + for seat in size: + var device := roster.device_for(ROLES[seat]) + var names: Dictionary = _bindings.get_or_add(seat, {}) + for action in ACTIONS: + if not InputMap.has_action(action): continue + if names.has(action) and _devices.get(seat) == device: continue + var scoped := StringName("party_%d_%s" % [seat, action]) + if names.has(action): + Input.action_release(scoped) + InputMap.action_erase_events(scoped) + else: + InputMap.add_action(scoped, InputMap.action_get_deadzone(action)) + names[action] = scoped + if device < 0: continue + for binding in InputMap.action_get_events(action): + if binding is InputEventJoypadButton or binding is InputEventJoypadMotion: + var copy := binding.duplicate() as InputEvent + copy.device = device + InputMap.action_add_event(scoped, copy) + _devices[seat] = device + + +func _clear_bindings() -> void: + for names: Dictionary in _bindings.values(): + for scoped: StringName in names.values(): + Input.action_release(scoped) + InputMap.erase_action(scoped) + names.clear() + _bindings.clear() + _devices.clear() + + +func bindings(seat: int) -> Dictionary: + return _bindings.get(seat, {}) + + +func decorate(actor: Node2D, seat: int, height: float) -> Label: + var badge := Label.new() + badge.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + badge.position = Vector2(-52, -height) + badge.size.x = 104 + badge.z_index = 20 + badge.mouse_filter = Control.MOUSE_FILTER_IGNORE + badge.add_theme_font_size_override("font_size", 17) + badge.add_theme_constant_override("outline_size", 5) + badge.modulate = COLORS[seat] + actor.add_child(badge) + return badge diff --git a/hoppys-adventure-arcade/app/local_party.gd.uid b/hoppys-adventure-arcade/app/local_party.gd.uid new file mode 100644 index 00000000..44ab39dc --- /dev/null +++ b/hoppys-adventure-arcade/app/local_party.gd.uid @@ -0,0 +1 @@ +uid://bvngk4y0bribh diff --git a/hoppys-adventure-arcade/app/seat_input.gd b/hoppys-adventure-arcade/app/seat_input.gd new file mode 100644 index 00000000..8504b463 --- /dev/null +++ b/hoppys-adventure-arcade/app/seat_input.gd @@ -0,0 +1,29 @@ +extends RefCounted +## Solo uses the game's ordinary actions, including keyboard input. A party seat +## receives a map of the same actions bound exclusively to its controller. +var names := {} + + +func held(action: StringName) -> bool: + return Input.is_action_pressed(names.get(action, action)) + + +func pressed(action: StringName) -> bool: + return Input.is_action_just_pressed(names.get(action, action)) + + +func released(action: StringName) -> bool: + return Input.is_action_just_released(names.get(action, action)) + + +func strength(action: StringName) -> float: + return Input.get_action_strength(names.get(action, action)) + + +func horizontal() -> float: + return Input.get_axis(names.get(&"move_left", &"move_left"), names.get(&"move_right", &"move_right")) + + +func movement() -> Vector2: + return Input.get_vector(names.get(&"move_left", &"move_left"), names.get(&"move_right", &"move_right"), + names.get(&"move_up", &"move_up"), names.get(&"move_down", &"move_down")) diff --git a/hoppys-adventure-arcade/app/seat_input.gd.uid b/hoppys-adventure-arcade/app/seat_input.gd.uid new file mode 100644 index 00000000..342be995 --- /dev/null +++ b/hoppys-adventure-arcade/app/seat_input.gd.uid @@ -0,0 +1 @@ +uid://cjqd5gervt0s diff --git a/hoppys-adventure-arcade/modes/beatem_up/boss.gd b/hoppys-adventure-arcade/modes/beatem_up/boss.gd index 533d9570..e37bffbd 100644 --- a/hoppys-adventure-arcade/modes/beatem_up/boss.gd +++ b/hoppys-adventure-arcade/modes/beatem_up/boss.gd @@ -85,19 +85,19 @@ func begin_reposition() -> void: state = "reposition" timer = 1.25 if phase<3 else .95 body.play("idle") - var side := -1.0 if position.x>arena.player.position.x else 1.0 + var side := -1.0 if position.x>arena.team.nearest(position).position.x else 1.0 if phase==1: side=-side # Pressure Hoppy without walking through them. - destination=arena_point(arena.player.position+Vector2(side*(170 if phase==1 else 250),-45 if cycle%2 else 45)) + destination=arena_point(arena.team.nearest(position).position+Vector2(side*(170 if phase==1 else 250),-45 if cycle%2 else 45)) func _tick_motion(dt: float) -> void: motion_clock += dt if state=="idle" or state=="reposition": if state=="idle": - var side := 1.0 if position.x>=arena.player.position.x else -1.0 - destination=arena_point(arena.player.position+Vector2(side*170,0)) + var side := 1.0 if position.x>=arena.team.nearest(position).position.x else -1.0 + destination=arena_point(arena.team.nearest(position).position+Vector2(side*170,0)) var previous := position position=position.move_toward(destination,(145.0 if phase==1 else 370.0 if phase==2 else 460.0)*dt) - body.flip_h=arena.player.position.x>position.x + body.flip_h=arena.team.nearest(position).position.x>position.x body.position.y=-absf(sin(motion_clock*11))*7 if position.distance_to(previous)>.1 else 0.0 elif state=="active" and leaping: var t := clampf(1.0-(timer-dt)/travel_duration,0,1) @@ -118,8 +118,8 @@ func telegraph() -> void: state = "tell" vulnerable = false timer = .95 if phase < 3 else .75 - aim = arena_point(arena.player.position) - body.flip_h=arena.player.position.x>position.x + aim = arena_point(arena.team.nearest(position).position) + body.flip_h=arena.team.nearest(position).position.x>position.x body.position=Vector2.ZERO if phase == 1: move = "summon" if cycle%3==1 else "slam" if cycle%3==2 else "sweep" diff --git a/hoppys-adventure-arcade/modes/beatem_up/enemy.gd b/hoppys-adventure-arcade/modes/beatem_up/enemy.gd index 3e60ff03..8cf1e717 100644 --- a/hoppys-adventure-arcade/modes/beatem_up/enemy.gd +++ b/hoppys-adventure-arcade/modes/beatem_up/enemy.gd @@ -64,7 +64,7 @@ func tick(dt: float) -> void: state = "chase" cooldown = .55 return - var delta_to: Vector2 = arena.player.position-position + var delta_to: Vector2 = arena.team.nearest(position).position-position if state == "tell": body.modulate = Color(1.25,1.05,.65) if timer <= 0: release_attack() @@ -74,7 +74,7 @@ func tick(dt: float) -> void: move_and_slide() position = arena.clamp_ground(position) if delta_to.x*facing >= -20 and absf(delta_to.x) < 90 and absf(delta_to.y) < 40: - arena.player.take_hit(position,"strength_down" if kind=="stale_branch_zombie" else "",290 if kind=="force_push_bandit" else 170) + arena.team.nearest(position).take_hit(position,"strength_down" if kind=="stale_branch_zombie" else "",290 if kind=="force_push_bandit" else 170) if timer <= 0: state = "recover" timer = .6 @@ -91,10 +91,10 @@ func tick(dt: float) -> void: if cooldown <= 0 and absf(delta_to.x) < reach and absf(delta_to.y) < (100 if ranged else 43): state = "tell" timer = data.tell - aim = arena.player.position + aim = arena.team.nearest(position).position pose(data.warning) else: - var target: Vector2 = arena.player.position + var target: Vector2 = arena.team.nearest(position).position if ranged: target.x -= facing*260 if kind=="cve_crawler" and absf(delta_to.x)>150: target.y += 65 if get_index()%2==0 else -65 var move := (target-position).normalized() if target.distance_to(position)>20 else Vector2.ZERO diff --git a/hoppys-adventure-arcade/modes/beatem_up/game.gd b/hoppys-adventure-arcade/modes/beatem_up/game.gd index c4129060..48fca1eb 100644 --- a/hoppys-adventure-arcade/modes/beatem_up/game.gd +++ b/hoppys-adventure-arcade/modes/beatem_up/game.gd @@ -59,6 +59,7 @@ var gate: AnimatedSprite2D var world: Node2D var ground: Node2D var actors: Node2D +var team := preload("res://app/arcade_team.gd").new() var player: CharacterBody2D var boss: Node2D var camera: Camera2D @@ -99,11 +100,12 @@ var merge_button: AnimatedSprite2D var merge_slammed := false var completion_count := 0 var test_mode := false -var last_swing_processed := -1 func _ready() -> void: process_mode = Node.PROCESS_MODE_ALWAYS Catalog.install_input() + LocalParty.refresh_bindings() + add_child(team) rng.randomize() world = Node2D.new() world.process_mode = Node.PROCESS_MODE_PAUSABLE @@ -152,7 +154,6 @@ func start_stage(index: int, cinematic := false) -> void: stage_index = index room = 0 gate_open = false - last_swing_processed = -1 shake = 0 camera.offset = Vector2.ZERO screen_fx.material.set_shader_parameter("phase",0.0) @@ -176,6 +177,7 @@ func start_stage(index: int, cinematic := false) -> void: # Off-screen left: every stage opens with Hoppy running in (stage_flow.gd). player.position = Vector2(Catalog.FLOW.enter_from_x,580) actors.add_child(player) + team.setup(player, _spawn_teammate, 138) camera.position = Vector2(640,360) camera.reset_physics_interpolation() prompt.text = "" @@ -213,6 +215,11 @@ func _on_flow_phase(phase: String) -> void: if phase=="" and state=="stage_enter": begin_play() func enter_room(index: int) -> void: + if index > 0 and team.members.size() > 1: + for fighter in team.members: + fighter.position = Vector2(index * 1280 + 70 + fighter.seat * 40, fighter.position.y) + fighter.hp = maxi(1, fighter.hp) + fighter.reset_physics_interpolation() room = index gate_open = false hazard_clock = 4.0 @@ -279,8 +286,8 @@ func enemy_defeated(enemy: Node2D) -> void: if rng.randf() < .18: drop("coffee" if player.hp<3 else "attack_up",enemy.position) func resolve_swing(source: Node2D) -> void: - if not playing or source.hp <= 0 or source.swing_serial == last_swing_processed: return - last_swing_processed = source.swing_serial + if not playing or source.hp <= 0 or source.swing_serial == source.last_swing_processed: return + source.last_swing_processed = source.swing_serial var weapon: String = source.attack_weapon var def: Dictionary = Catalog.WEAPONS[weapon] if weapon != "" else {"damage":2.0 if source.combo==3 else 1.0,"reach":110.0 if source.combo==3 else 95.0,"depth":46.0,"knock":260.0 if source.combo==3 else 75.0} var damage: float = def.damage @@ -360,19 +367,20 @@ func drop(kind: String, pos: Vector2) -> void: actors.add_child(node) pickups.append({"node":node,"sprite":sprite,"kind":kind,"age":0.0}) -func pickup_weapon() -> void: +func pickup_weapon(fighter: CharacterBody2D = null) -> void: + if fighter == null: fighter = player var closest := -1 var distance := 85.0 for i in pickups.size(): var item: Dictionary = pickups[i] if not Catalog.WEAPONS.has(item.kind): continue - var d: float = item.node.position.distance_to(player.position) + var d: float = item.node.position.distance_to(fighter.position) if d void: clear_threats() toast("BLOCKERS CLEARED — GO RIGHT →",3) # Room 3 has no walk-out: its boss's defeat runs Hoppy off (mini_boss_defeated, the finisher). - if gate_open and room<2 and player.position.x > room_start()+1205: enter_room(room+1) + if gate_open and room<2 and team.front().position.x > room_start()+1205: enter_room(room+1) if not gate_open: hazard_clock -= dt if hazard_clock <= 0: @@ -481,12 +489,13 @@ func _tick_items(dt: float) -> void: var item: Dictionary = pickups[i] item.age += dt item.sprite.position.y = -22+sin(item.age*4)*4 - var distance: float = item.node.position.distance_to(player.position) + var collector := team.nearest(item.node.position) + var distance: float = item.node.position.distance_to(collector.position) if Catalog.WEAPONS.has(item.kind): if distance<85: prompt.text = Prompts.either("E", &"brawl_pickup", true)+" · PICK UP "+item.kind.replace("_"," ").to_upper() - elif distance < 45 and player.height < 20 and player.hp>0: - player.apply_effect(item.kind) - sound("pickup",player.position) + elif distance < 45 and collector.height < 20 and collector.hp>0: + collector.apply_effect(item.kind) + sound("pickup",collector.position) toast(item.kind.replace("_"," ").to_upper(),1.2) item.node.queue_free() pickups.remove_at(i) @@ -496,10 +505,11 @@ func _tick_threats(dt: float) -> void: var b: Dictionary = bullets[i] b.node.position += b.velocity*dt b.life -= dt - var offset: Vector2 = b.node.position-player.position - var contact: bool = absf(offset.x)<32 and absf(offset.y)<25 and player.height<38 + var target := team.nearest(b.node.position) + var offset: Vector2 = b.node.position-target.position + var contact: bool = absf(offset.x)<32 and absf(offset.y)<25 and target.height<38 if contact: - player.take_hit(b.node.position-b.velocity*.1,b.status) + target.take_hit(b.node.position-b.velocity*.1,b.status) if contact or b.life<=0 or b.node.position.x void: "breach": fx("security_kit","breach_shockwave",w.pos,1.5,w.active) "head": fx("hq_kit","head_active",w.pos-Vector2(0,20),1.0,w.active) if w.kind!="signal": sound("kick",w.pos) - var offset: Vector2 = (player.position-w.pos)/w.radius - if w.kind!="signal" and offset.length()<1 and player.height<38: - player.take_hit(w.pos-Vector2(1,0),"confused" if w.kind=="head" else "") + for target in team.members: + if target.hp <= 0: continue + var offset: Vector2 = (target.position-w.pos)/w.radius + if w.kind!="signal" and offset.length()<1 and target.height<38: + target.take_hit(w.pos-Vector2(1,0),"confused" if w.kind=="head" else "") if w.left <= -float(w.active): w.node.queue_free() warnings.remove_at(i) @@ -864,6 +876,7 @@ func knockout_hud_nodes() -> Array[CanvasItem]: return nodes func _update_hud() -> void: + team.update_health() var health := "" for i in 3: health += "♥ " if i void: func _exit_tree() -> void: get_tree().paused = false + +func _spawn_teammate(seat: int) -> CharacterBody2D: + var fighter := Player.new() + fighter.arena = self + fighter.position = clamp_ground(player.position + Vector2(40 * seat, -24 * seat)) + actors.add_child(fighter) + return fighter + +func fighter_down(fighter: CharacterBody2D, source: Vector2) -> void: + var survivor := team.nearest(fighter.position) + if survivor.hp <= 0: + player = fighter + knockout(source) + else: + fighter.show_pose("hurt") + fighter.body.pause() + if player == fighter: player = survivor diff --git a/hoppys-adventure-arcade/modes/beatem_up/mini_boss.gd b/hoppys-adventure-arcade/modes/beatem_up/mini_boss.gd index 3b684253..e44559e7 100644 --- a/hoppys-adventure-arcade/modes/beatem_up/mini_boss.gd +++ b/hoppys-adventure-arcade/modes/beatem_up/mini_boss.gd @@ -123,7 +123,7 @@ func _tick_intro() -> void: if timer <= 0: _rest(0.0) func _tick_chase(dt: float) -> void: - var player: Node2D = arena.player + var player: Node2D = arena.team.nearest(position) var side := -1.0 if player.position.x < position.x else 1.0 _face(player.position.x) var goal := arena_point(player.position-Vector2(side*150,0)) @@ -148,7 +148,7 @@ func _tick_active(dt: float) -> void: if timer <= 0: _land() return position = arena_point(position+Vector2(dash_direction*float(data.dash_speed)*dt,0)) - var player: Node2D = arena.player + var player: Node2D = arena.team.nearest(position) var offset: Vector2 = player.position-position if absf(offset.x) < DASH_REACH and absf(offset.y) < DASH_DEPTH: player.take_hit(position,"",DASH_FORCE) @@ -168,7 +168,7 @@ func telegraph() -> void: move = "slam" if cycle%2 == 1 else "dash" state = "tell" timer = tell_time(move) - var player: Node2D = arena.player + var player: Node2D = arena.team.nearest(position) _face(player.position.x) body.position = Vector2.ZERO if move == "slam": diff --git a/hoppys-adventure-arcade/modes/beatem_up/player.gd b/hoppys-adventure-arcade/modes/beatem_up/player.gd index 00acc94b..1161aa89 100644 --- a/hoppys-adventure-arcade/modes/beatem_up/player.gd +++ b/hoppys-adventure-arcade/modes/beatem_up/player.gd @@ -39,10 +39,14 @@ var swing_fired := false var queued := false var attack_weapon := "" var swing_serial := 0 +var last_swing_processed := -1 var knock := Vector2.ZERO var controlled := true var armed := false +var seat := 0 +var controls := preload("res://app/seat_input.gd").new() + func _ready() -> void: collision_layer = 0 collision_mask = 0 @@ -75,14 +79,14 @@ func tick(dt: float) -> void: if hp <= 0: return var movement := Vector2.ZERO if controlled and input_lock <= 0 and stagger <= 0: - movement = Input.get_vector("move_left","move_right","move_up","move_down") + movement = controls.movement() if effects.has("confused"): movement = -movement if absf(movement.x) > .15: steer = signf(movement.x) if steer != 0 and swing_left <= 0: facing = steer - if Input.is_action_just_pressed("brawl_jump"): jump() - if Input.is_action_just_pressed("brawl_attack"): request_attack() - if Input.is_action_just_pressed("brawl_pickup") and swing_left <= 0 and height < 20: - arena.pickup_weapon() + if controls.pressed(&"brawl_jump"): jump() + if controls.pressed(&"brawl_attack"): request_attack() + if controls.pressed(&"brawl_pickup") and swing_left <= 0 and height < 20: + arena.pickup_weapon(self) if swing_left > 0: swing_left -= dt if not swing_fired and swing_left <= swing_duration * .56: @@ -260,5 +264,5 @@ func take_hit(source: Vector2, status := "", force := 180.0) -> bool: if hp <= 0: held.hide() body.position.x=0 - arena.knockout(source) + arena.fighter_down(self, source) return true diff --git a/hoppys-adventure-arcade/modes/beatem_up/reinvent/boss.gd b/hoppys-adventure-arcade/modes/beatem_up/reinvent/boss.gd index 6a42d02a..9f8315fe 100644 --- a/hoppys-adventure-arcade/modes/beatem_up/reinvent/boss.gd +++ b/hoppys-adventure-arcade/modes/beatem_up/reinvent/boss.gd @@ -79,7 +79,7 @@ func tick(dt: float) -> void: if timer<=0: state="chase";cooldown=.5 else: - var delta_to: Vector2=arena.player.position-position + var delta_to: Vector2=arena.team.nearest(position).position-position facing=-1 if delta_to.x<0 else 1 var distance := 160.0 if kind in ["ai_slop","ten_thousand_line_pr"] else 230.0 if delta_to.length()>distance: @@ -93,7 +93,7 @@ func pose(name: String) -> void: func choose_attack() -> void: action_index+=1 - aim=arena.player.position + aim=arena.team.nearest(position).position state="tell" match kind: "ai_slop": @@ -118,7 +118,7 @@ func choose_attack() -> void: arena.spawn_enemy("security_gap_crawler",arena.clamp_ground(Vector2(arena.room_start()+1080,470))) if phase==3: vector.position=arena.clamp_ground(position+Vector2(-180,90 if position.y<550 else -90)) - vector_aim=arena.player.position+Vector2(0,65 if arena.player.position.y<550 else -65) + vector_aim=arena.team.nearest(position).position+Vector2(0,65 if arena.team.nearest(position).position.y<550 else -65) vector_body.play("dash_warning") queue_redraw() @@ -154,9 +154,10 @@ func release_attack() -> void: vector_body.play("vector_attack") func contact(pos: Vector2) -> void: - var offset: Vector2=arena.player.position-pos - if absf(offset.x)<85 and absf(offset.y)<42: - arena.player.take_hit(pos,"strength_down" if kind=="ai_augmented_hacker" and phase>=2 else "",220) + for target in arena.team.members: + var offset: Vector2 = target.position - pos + if absf(offset.x) < 85 and absf(offset.y) < 42: + target.take_hit(pos,"strength_down" if kind=="ai_augmented_hacker" and phase>=2 else "",220) func take_hit(damage: float, _force: float, _from: Vector2, _finisher := false) -> bool: if dead or shield_active or state=="transition": return false diff --git a/hoppys-adventure-arcade/modes/beatem_up/reinvent/enemy.gd b/hoppys-adventure-arcade/modes/beatem_up/reinvent/enemy.gd index eef112fd..6d6adcbe 100644 --- a/hoppys-adventure-arcade/modes/beatem_up/reinvent/enemy.gd +++ b/hoppys-adventure-arcade/modes/beatem_up/reinvent/enemy.gd @@ -70,14 +70,15 @@ func tick(dt: float) -> void: elif state=="attack": if kind in ["ai_hacker_drone","security_gap_crawler"]: position = arena.clamp_ground(position+aim*400*dt) - var delta_to: Vector2 = arena.player.position-position - if delta_to.x*facing>=-20 and absf(delta_to.x)<95 and absf(delta_to.y)<42: - arena.player.take_hit(position) + for fighter in arena.team.members: + var delta_to: Vector2 = fighter.position-position + if delta_to.x*facing>=-20 and absf(delta_to.x)<95 and absf(delta_to.y)<42: + fighter.take_hit(position) if timer<=0: state="recover"; timer=.65; body.play("idle") elif state=="recover": if timer<=0: state="chase"; cooldown=.65 else: - var delta_to: Vector2 = arena.player.position-position + var delta_to: Vector2 = arena.team.nearest(position).position-position facing = -1 if delta_to.x<0 else 1 var ranged := kind in ["hallucinated_api_gremlin","vulnerability_injector"] var reach := 390.0 if ranged else 300.0 if kind in ["ai_hacker_drone","security_gap_crawler"] else 105.0 @@ -86,7 +87,7 @@ func tick(dt: float) -> void: elif cooldown<=0 and absf(delta_to.x)25 else Vector2.ZERO for other in arena.enemies: @@ -101,7 +102,7 @@ func tick(dt: float) -> void: func start_tell() -> void: state="tell" timer=data.tell - aim=arena.player.position + aim=arena.team.nearest(position).position body.play("attack_warning") func release_attack() -> void: @@ -170,7 +171,7 @@ func finish_death(reward := true) -> void: body.play("defeat") if reward: arena.enemy_defeated(self) if kind=="agent_spawner": - arena.player.effects.erase("overwhelmed") + for fighter in arena.team.members: fighter.effects.erase("overwhelmed") for other in arena.enemies.duplicate(): if is_instance_valid(other) and other.spawner==self: other.finish_death(false) var tween := create_tween() diff --git a/hoppys-adventure-arcade/modes/beatem_up/reinvent/game.gd b/hoppys-adventure-arcade/modes/beatem_up/reinvent/game.gd index 4ae5d1eb..c3537a21 100644 --- a/hoppys-adventure-arcade/modes/beatem_up/reinvent/game.gd +++ b/hoppys-adventure-arcade/modes/beatem_up/reinvent/game.gd @@ -31,6 +31,7 @@ var gate: AnimatedSprite2D var world: Node2D var ground: Node2D var actors: Node2D +var team := preload("res://app/arcade_team.gd").new() var player: CharacterBody2D var boss: Node2D var camera: Camera2D @@ -98,11 +99,12 @@ var victory: VictoryScreen var minimap: Minimap var pause_return_state := "combat" var leaving := false -var last_swing_processed := -1 func _ready() -> void: process_mode = Node.PROCESS_MODE_ALWAYS Catalog.install_input() + LocalParty.refresh_bindings() + add_child(team) rng.randomize() world = Node2D.new() world.process_mode = Node.PROCESS_MODE_PAUSABLE @@ -146,7 +148,7 @@ func start_stage(index: int, cinematic := false) -> void: boss=null;triage_target=null;hammer_target=null stage_index=index;room=0;gate_open=false boss_rewarded=false;army_merged=false;victory_clock=0 - reveal_time=0;surge_cooldown=0;last_swing_processed=-1;shake=0 + reveal_time=0;surge_cooldown=0;shake=0 camera.offset=Vector2.ZERO screen_fx.material.set_shader_parameter("phase",0.0) ground=Node2D.new();world.add_child(ground) @@ -161,6 +163,7 @@ func start_stage(index: int, cinematic := false) -> void: ground.add_child(decor) player=Player.new();player.arena=self;player.position=Vector2(Catalog.FLOW.enter_from_x,580) actors.add_child(player) + team.setup(player, _spawn_teammate, 138) player.shield=capabilities.review camera.position=Vector2(640,360) camera.reset_physics_interpolation() @@ -193,6 +196,11 @@ func _on_flow_phase(phase: String) -> void: if phase=="" and state=="stage_enter": begin_play() func enter_room(index: int) -> void: + if index > 0 and team.members.size() > 1: + for fighter in team.members: + fighter.position = Vector2(index * 1280 + 70 + fighter.seat * 40, fighter.position.y) + fighter.hp = maxi(1, fighter.hp) + fighter.reset_physics_interpolation() clear_threats() for item in pickups: item.node.queue_free() pickups.clear() @@ -245,8 +253,8 @@ func enemy_defeated(enemy: Node2D) -> void: if rng.randf()<.15: drop("health_capsule" if player.hp<3 else "score_coin",enemy.position) func resolve_swing(source: Node2D) -> void: - if not playing or source.hp<=0 or source.swing_serial==last_swing_processed: return - last_swing_processed=source.swing_serial + if not playing or source.hp<=0 or source.swing_serial==source.last_swing_processed: return + source.last_swing_processed=source.swing_serial var weapon: String=source.attack_weapon var def: Dictionary=Catalog.WEAPONS[weapon] if weapon!="" else {"damage":2.0 if source.combo==3 else 1.0,"reach":125.0 if source.combo==3 else 108.0,"depth":50.0,"knock":260.0 if source.combo==3 else 80.0} var damage: float=def.damage @@ -321,7 +329,7 @@ func break_prop(prop: Dictionary) -> void: fx("review_kit","nightmare_wave",prop.node.position,2,.5) "assembly": reward="speed_surge" - player.effects.erase("overwhelmed") + for fighter in team.members: fighter.effects.erase("overwhelmed") for enemy in enemies: if is_instance_valid(enemy) and not enemy.dead and enemy.kind=="agent_spawner" and absf(enemy.position.y-prop.node.position.y)<80: enemy.finish_death() "rack": reward="pr_merger" if room==2 else "security_scanner" @@ -342,19 +350,20 @@ func drop(kind: String, pos: Vector2) -> void: actors.add_child(node) pickups.append({"node":node,"sprite":sprite,"kind":kind,"age":0.0}) -func pickup_weapon() -> void: +func pickup_weapon(fighter: CharacterBody2D = null) -> void: + if fighter == null: fighter = player var closest := -1 var distance := 85.0 for i in pickups.size(): var item: Dictionary = pickups[i] if not Catalog.WEAPONS.has(item.kind): continue - var d: float = item.node.position.distance_to(player.position) + var d: float = item.node.position.distance_to(fighter.position) if d void: clear_projectiles() @@ -448,7 +457,7 @@ func _physics_process(dt: float) -> void: if not playing: return if room<2 and not gate_open and living_enemies()==0: gate_open=true;gate.hide();clear_threats();toast("BLOCKERS CLEARED — GO RIGHT →",3) - if gate_open and player.position.x>room_start()+1205: + if gate_open and team.front().position.x>room_start()+1205: if room<2: enter_room(room+1) if not gate_open: hazard_clock-=dt @@ -467,12 +476,13 @@ func _tick_items(dt: float) -> void: var item: Dictionary = pickups[i] item.age += dt item.sprite.position.y = -22+sin(item.age*4)*4 - var distance: float = item.node.position.distance_to(player.position) + var collector := team.nearest(item.node.position) + var distance: float = item.node.position.distance_to(collector.position) if Catalog.WEAPONS.has(item.kind): if distance<85: prompt.text = Prompts.either("E", &"brawl_pickup", true)+" · PICK UP "+item.kind.replace("_"," ").to_upper() - elif distance < 45 and player.height < 20 and player.hp>0: - player.apply_effect(item.kind) - sound("pickup",player.position) + elif distance < 45 and collector.height < 20 and collector.hp>0: + collector.apply_effect(item.kind) + sound("pickup",collector.position) toast(item.kind.replace("_"," ").to_upper(),1.2) item.node.queue_free() pickups.remove_at(i) @@ -482,12 +492,16 @@ func _tick_threats(dt: float) -> void: var b: Dictionary=bullets[i] b.age+=dt if b.tracking and b.age<1.25: - var desired: Vector2=(player.position-b.node.position).normalized()*260 + var desired: Vector2=(team.nearest(b.node.position).position-b.node.position).normalized()*260 b.velocity=b.velocity.lerp(desired,minf(1,dt*1.8)) b.node.position+=b.velocity*dt;b.life-=dt - var offset: Vector2=b.node.position-player.position - var contact: bool=absf(offset.x)<30 and absf(offset.y)<26 and player.height<38 - if contact: player.take_hit(b.node.position-b.velocity*.1,b.status) + var contact := false + for target in team.members: + var offset: Vector2=b.node.position-target.position + if target.hp>0 and absf(offset.x)<30 and absf(offset.y)<26 and target.height<38: + target.take_hit(b.node.position-b.velocity*.1,b.status) + contact = true + break if contact or b.life<=0 or absf(b.node.position.x-room_start()-640)>820: b.node.queue_free();bullets.remove_at(i) for i in range(warnings.size()-1,-1,-1): @@ -504,10 +518,15 @@ func _tick_threats(dt: float) -> void: "slam": fx("review_kit","falling_stack",w.pos-Vector2(0,65),1,w.active) "nightmare": fx("review_kit","nightmare_wave",w.pos,2,w.active) sound("collapse" if w.kind in ["slam","nightmare"] else "kick",w.pos) - var offset: Vector2=(player.position-w.pos)/w.radius - if offset.length()<1 and player.height<38 and not w.hit: - if w.kind=="fog": player.apply_effect("confused");w.hit=true - else: w.hit=player.take_hit(w.pos-Vector2(1,0)) + for target in team.members: + if target.hp <= 0: continue + var offset: Vector2=(target.position-w.pos)/w.radius + if offset.length() < 1 and target.height < 38 and target.seat not in w.hit_seats: + if w.kind == "fog": + target.apply_effect("confused") + w.hit_seats.append(target.seat) + elif target.take_hit(w.pos - Vector2.RIGHT): + w.hit_seats.append(target.seat) if w.left<=-float(w.active): w.node.queue_free();warnings.remove_at(i) func stage_hazard() -> void: @@ -609,7 +628,8 @@ func boss_defeated() -> void: func show_boss_reward() -> void: match stage_index: 0: - capabilities.review=true;player.shield=true + capabilities.review = true + for fighter in team.members: fighter.shield = true show_cards(["unlock_review"],exit_stage) 1: capabilities.triage=true;capabilities.change_stack=true @@ -765,6 +785,7 @@ func _build_ui() -> void: pause_menu = PauseMenu.create(self, ROUTE, resume, restart, leave) func _update_hud() -> void: + team.update_health() var health := "" for i in 3: health += "♥ " if i void: var ratio := minf(size.x/1280.0,size.y/720.0) card_host.scale=Vector2.ONE*ratio card_host.position=(size-Vector2(1280,720)*ratio)*.5 + +func _spawn_teammate(seat: int) -> CharacterBody2D: + var fighter := Player.new() + fighter.arena = self + fighter.shield = capabilities.review + fighter.position = clamp_ground(player.position + Vector2(40 * seat, -24 * seat)) + actors.add_child(fighter) + return fighter + +func fighter_down(fighter: CharacterBody2D, source: Vector2) -> void: + var survivor := team.nearest(fighter.position) + if survivor.hp <= 0: + player = fighter + knockout(source) + else: + fighter.show_pose("hurt") + fighter.body.pause() + if player == fighter: player = survivor diff --git a/hoppys-adventure-arcade/modes/beatem_up/reinvent/player.gd b/hoppys-adventure-arcade/modes/beatem_up/reinvent/player.gd index 18bf5e86..498382b2 100644 --- a/hoppys-adventure-arcade/modes/beatem_up/reinvent/player.gd +++ b/hoppys-adventure-arcade/modes/beatem_up/reinvent/player.gd @@ -41,6 +41,7 @@ var swing_fired := false var queued := false var attack_weapon := "" var swing_serial := 0 +var last_swing_processed := -1 var knock := Vector2.ZERO var controlled := true var review_charge := 0.0 @@ -53,6 +54,9 @@ var pose_move := Vector2.ZERO ## Drawn unarmed with no carry (knockout.gd sets it while he is airborne); the weapon is kept. var stowed := false +var seat := 0 +var controls := preload("res://app/seat_input.gd").new() + func _ready() -> void: collision_layer = 0 collision_mask = 0 @@ -73,7 +77,7 @@ func _physics_process(dt: float) -> void: func tick(dt: float) -> void: review_cooldown = maxf(0,review_cooldown-dt) - if controlled and Input.is_action_pressed("review_burst") and arena.capabilities.review and hp>0 and stagger<=0: + if controlled and controls.held(&"review_burst") and arena.capabilities.review and hp>0 and stagger<=0: review_charge += dt if review_charge >= .45 and review_cooldown <= 0: activate_review() else: review_charge = 0.0 @@ -90,14 +94,14 @@ func tick(dt: float) -> void: if hp <= 0: return var movement := Vector2.ZERO if controlled and input_lock <= 0 and stagger <= 0: - movement = Input.get_vector("move_left","move_right","move_up","move_down") + movement = controls.movement() if effects.has("confused"): movement = -movement if absf(movement.x) > .15: steer = signf(movement.x) if steer != 0 and swing_left <= 0: facing = steer - if Input.is_action_just_pressed("brawl_jump"): jump() - if Input.is_action_just_pressed("brawl_attack"): request_attack() - if Input.is_action_just_pressed("brawl_pickup") and swing_left <= 0 and height < 20: - arena.pickup_weapon() + if controls.pressed(&"brawl_jump"): jump() + if controls.pressed(&"brawl_attack"): request_attack() + if controls.pressed(&"brawl_pickup") and swing_left <= 0 and height < 20: + arena.pickup_weapon(self) if swing_left > 0: swing_left -= dt if not swing_fired and swing_left <= swing_duration * .56: @@ -310,5 +314,5 @@ func take_hit(source: Vector2, status := "", force := 180.0) -> bool: arena.shake = 8 if hp <= 0: body.position.x=0 - arena.knockout(source) + arena.fighter_down(self, source) return true diff --git a/hoppys-adventure-arcade/modes/platformer/crumbling_branch.gd b/hoppys-adventure-arcade/modes/platformer/crumbling_branch.gd index 3ecd4753..5934736e 100644 --- a/hoppys-adventure-arcade/modes/platformer/crumbling_branch.gd +++ b/hoppys-adventure-arcade/modes/platformer/crumbling_branch.gd @@ -22,8 +22,11 @@ func _show(clip: String) -> void: visual.position = Vector2(-width/2,0) visual.scale = Vector2(width,48)/visual.texture.get_size() -func tick(dt: float, player: CharacterBody2D) -> void: - var on_top := absf(player.position.x-position.x) < width/2+15 and absf(player.position.y-position.y) < 6 and player.is_on_floor() +func tick(dt: float, players: Array[CharacterBody2D]) -> void: + var on_top := false + for player in players: + if player.hp <= 0: continue + on_top = on_top or absf(player.position.x-position.x) < width/2+15 and absf(player.position.y-position.y) < 6 and player.is_on_floor() if state == "intact": if on_top: state = "warning" @@ -44,7 +47,10 @@ func tick(dt: float, player: CharacterBody2D) -> void: visual.position.y = minf(95,clock*140) visual.modulate.a = maxf(0,1-clock*2) # Never rematerialize into Hoppy's body. - var occupied := absf(player.position.x-position.x) < width/2+20 and player.position.y > position.y-10 and player.position.y < position.y+80 + var occupied := false + for player in players: + if player.hp <= 0: continue + occupied = occupied or absf(player.position.x-position.x) < width/2+20 and player.position.y > position.y-10 and player.position.y < position.y+80 if clock >= 3.5 and not occupied: state = "intact" clock = 0 diff --git a/hoppys-adventure-arcade/modes/platformer/deprecated_api.gd b/hoppys-adventure-arcade/modes/platformer/deprecated_api.gd index b3b68138..004648bf 100644 --- a/hoppys-adventure-arcade/modes/platformer/deprecated_api.gd +++ b/hoppys-adventure-arcade/modes/platformer/deprecated_api.gd @@ -41,16 +41,20 @@ func _physics_process(dt: float) -> void: position.x = clampf(position.x + signf(distance)*90*dt, 4350,4820) sprite.flip_h = distance > 0 elif current == "slam": - if absf(player.position.x-position.x) < 190 and player.position.y > position.y-45: - player.damage(position.x) + for target in targets(): + if absf(target.position.x-position.x) < 190 and target.position.y > position.y-45: + target.damage(position.x) elif current == "dash": position.x = clampf(position.x + dash_direction*480*dt, 4320,4820) - if hurtbox.overlaps_body(player): - if player.velocity.y > 120 and player.position.y < position.y-85: + for target in targets(): + if not hurtbox.overlaps_body(target): continue + if target.velocity.y > 120 and target.position.y < position.y-85: take_hit() - player.velocity.y = -440 + target.velocity.y = -440 + # A defeated boss hurts no one else this frame. + if dead: break elif current not in ["vulnerable", "overheat", "slam_stalled", "dash_brake", "cannon_recover", "reboot"]: - player.damage(position.x) + target.damage(position.x) queue_redraw() func _enter_state(index: int) -> void: diff --git a/hoppys-adventure-arcade/modes/platformer/enchanted_enemy.gd b/hoppys-adventure-arcade/modes/platformer/enchanted_enemy.gd index ade87d6e..8e3b0583 100644 --- a/hoppys-adventure-arcade/modes/platformer/enchanted_enemy.gd +++ b/hoppys-adventure-arcade/modes/platformer/enchanted_enemy.gd @@ -38,9 +38,10 @@ func _physics_process(dt: float) -> void: var move := "club" if troll else "jab" sprite.play(move+"_warning" if attack_clock < warning else (move if attack_clock < active_end else "recover")) if attack_clock >= warning and attack_clock < active_end: - var dx := (player.position.x-position.x)*direction - if dx >= -15 and dx < reach and player.position.y > position.y-(55 if troll else 38) and player.position.y < position.y+35: - player.damage(position.x) + for target in targets(): + var dx := (target.position.x-position.x)*direction + if dx >= -15 and dx < reach and target.position.y > position.y-(55 if troll else 38) and target.position.y < position.y+35: + target.damage(position.x) if attack_clock >= active_end + (1.0 if troll else 0.65): attack_clock = -1 cooldown = 1.4 @@ -50,12 +51,15 @@ func _physics_process(dt: float) -> void: sprite.flip_h = cos(phase) > 0 sprite.play("walk") if hit_flash > 0: sprite.play("hurt") - if hurtbox.overlaps_body(player): - if player.velocity.y > 120 and player.position.y < position.y-(65 if troll else 32): + for target in targets(): + if not hurtbox.overlaps_body(target): continue + if target.velocity.y > 120 and target.position.y < position.y-(65 if troll else 32): take_hit() - player.velocity.y = -440 + target.velocity.y = -440 + # A defeated enemy hurts no one else this frame. + if dead: break elif attack_clock < 0 or attack_clock < active_end: - player.damage(position.x) + target.damage(position.x) queue_redraw() func _draw() -> void: diff --git a/hoppys-adventure-arcade/modes/platformer/enchanted_hazard.gd b/hoppys-adventure-arcade/modes/platformer/enchanted_hazard.gd index df5969a1..92e84da0 100644 --- a/hoppys-adventure-arcade/modes/platformer/enchanted_hazard.gd +++ b/hoppys-adventure-arcade/modes/platformer/enchanted_hazard.gd @@ -28,7 +28,7 @@ func _show(clip: String) -> void: visual.position = Vector2(0, -visual.texture.get_height()*visual.scale.y/2) visual.flip_h = kind == "vine" and direction > 0 -func tick(dt: float, player: CharacterBody2D) -> void: +func tick(dt: float, players: Array[CharacterBody2D]) -> void: clock += dt var phase := fmod(clock,4.9) state = "idle" if phase < 2.0 else ("warning" if phase < 2.9 else ("active" if phase < 3.35 else "recover")) @@ -38,7 +38,8 @@ func tick(dt: float, player: CharacterBody2D) -> void: else: clip = {"idle":"vine_idle","warning":"vine_warning","active":"vine_whip","recover":"vine_idle"}[state] _show(clip) - if state == "active" and area.overlaps_body(player): player.damage(position.x) + for player in players: + if state == "active" and area.overlaps_body(player): player.damage(position.x) queue_redraw() func _draw() -> void: diff --git a/hoppys-adventure-arcade/modes/platformer/enemy.gd b/hoppys-adventure-arcade/modes/platformer/enemy.gd index 12bf3021..a28d070c 100644 --- a/hoppys-adventure-arcade/modes/platformer/enemy.gd +++ b/hoppys-adventure-arcade/modes/platformer/enemy.gd @@ -3,7 +3,10 @@ signal defeated(points: int) const Art = preload("res://modes/platformer/art.gd") var kind := "glitch_critter" var hp := 1 +## The teammate this enemy aims at: the nearest living one, which the level updates. var player: CharacterBody2D +## The level's ArcadeTeam once a second player joins, so attacks and touch can hurt every teammate. +var team: Node var origin := Vector2.ZERO var radius := 100.0 var phase := 0.0 @@ -40,15 +43,26 @@ func _physics_process(dt: float) -> void: phase = 0 var cycle := fmod(phase, 3.4) sprite.play("windup" if cycle > 1.7 and cycle < 2.5 else ("slam" if cycle >= 2.5 else "idle")) - if cycle >= 2.5 and cycle < 2.9 and absf(player.position.x - position.x) < 230 and player.position.y > position.y - 40: - player.damage(position.x) + if cycle >= 2.5 and cycle < 2.9: + for target in targets(): + if absf(target.position.x - position.x) < 230 and target.position.y > position.y - 40: + target.damage(position.x) else: position.x = origin.x + sin(phase * (0.8 if kind == "request_reviewer" else 1.3)) * radius sprite.flip_h = cos(phase * (0.8 if kind == "request_reviewer" else 1.3)) > 0 sprite.play("hurt" if hit_flash > 0 else ("patrol" if kind == "request_reviewer" else "scuttle")) # Bay Area Blitz has no stomping: only a swipe hurts a bug; touching one, from any side, hurts Hoppy. - if hurtbox.overlaps_body(player): - player.damage(position.x) + for target in targets(): + if hurtbox.overlaps_body(target): target.damage(position.x) +## Everyone this enemy's attacks and touch can hurt: each living teammate, or `player` alone. +func targets() -> Array[CharacterBody2D]: + var living: Array[CharacterBody2D] = [] + if team == null: + living.append(player) + return living + for actor in team.members: + if actor.hp > 0: living.append(actor) + return living func take_hit() -> void: if dead or hit_flash > 0: return diff --git a/hoppys-adventure-arcade/modes/platformer/legacy_monolith.gd b/hoppys-adventure-arcade/modes/platformer/legacy_monolith.gd index fa0a96dc..721c5b97 100644 --- a/hoppys-adventure-arcade/modes/platformer/legacy_monolith.gd +++ b/hoppys-adventure-arcade/modes/platformer/legacy_monolith.gd @@ -66,17 +66,22 @@ func _physics_process(dt: float) -> void: sprite.flip_h=dx>0 elif current in ["slam","stomp"]: var reach := 175.0 if current == "slam" else 95.0 - if absf(player.position.x-position.x)position.y-42 and player.position.yposition.y-42 and target.position.y-30 and dx<215 and player.position.y>position.y-58 and player.position.y120 and player.position.y-30 and dx<215 and target.position.y>position.y-58 and target.position.y120 and target.position.y0: break + elif not vulnerable(): target.damage(position.x) queue_redraw() func _enter_state(index: int) -> void: diff --git a/hoppys-adventure-arcade/modes/platformer/level.gd b/hoppys-adventure-arcade/modes/platformer/level.gd index aa837969..af57ee7f 100644 --- a/hoppys-adventure-arcade/modes/platformer/level.gd +++ b/hoppys-adventure-arcade/modes/platformer/level.gd @@ -33,6 +33,8 @@ var approach_objective := "" var fight_objective := "" var level_track: AudioStream var boss_track: AudioStream +var foes: Array[Node2D] = [] +var team := preload("res://app/arcade_team.gd").new() var player: CharacterBody2D var camera: Camera2D var score := 0 @@ -69,7 +71,6 @@ var projectiles: Node2D var intro_banner: PanelContainer var banner_style: StyleBoxFlat var banner_title: Label -var previous_feet := Vector2.ZERO var music_fade: Tween var celebration_hop: Tween var knockout: Control @@ -99,15 +100,19 @@ func _sign(title: String, subtitle: String, pos: Vector2) -> void: func _physics_process(dt: float) -> void: if finished or get_tree().paused: return elapsed += dt - if encounter == "approach" and player.position.x >= 4300 and player.is_on_floor(): + var front := team.front() + if team.members.size() > 1: + _follow_team(front) + if encounter == "approach" and front.position.x >= 4300 and front.is_on_floor(): _start_encounter() if encounter == "intro": intro_remaining -= dt if intro_remaining <= 0: encounter = "fight" intro_banner.hide() - player.set_physics_process(true) - player.input_lock = 0.15 + for actor in team.members: + actor.set_physics_process(true) + actor.input_lock = 0.15 boss.active = true _update_hud() for car in cars: @@ -116,32 +121,38 @@ func _physics_process(dt: float) -> void: var item: Dictionary = pickups[i] var area: Area2D = item.node area.position.y = item.origin.y + sin(elapsed * 3 + item.origin.x) * 5 - if area.overlaps_body(player): + for collector in team.members: + if collector.hp <= 0 or not area.overlaps_body(collector): continue match item.kind: "commit_token": score += 25 - "coffee": player.heal(1) - "full_review": player.heal(3) - "approve_shield": player.shield = true - "lgtm_boost": player.boost = 5 + "coffee": collector.heal(1) + "full_review": collector.heal(3) + "approve_shield": collector.shield = true + "lgtm_boost": collector.boost = 5 "auto_fix": for enemy in get_children(): - if enemy is Enemy and enemy != boss and enemy.position.distance_to(player.position) < 350: + if enemy is Enemy and enemy != boss and enemy.position.distance_to(collector.position) < 350: enemy.hp = 1 enemy.take_hit() pickups.remove_at(i) area.queue_free() AudioService.play_ui(1) _update_hud() + break for hazard in hazards: if hazard.kind == "conflict_zone": hazard.node.position.x = hazard.origin.x + sin(elapsed) * 115 - if hazard.node.overlaps_body(player): player.damage(hazard.node.position.x) - var landed_on_exit := absf(player.position.x - 5090) < 49 and previous_feet.y < EXIT_TOP - 0.5 and player.position.y >= EXIT_TOP - 0.5 and player.position.y <= EXIT_TOP + 14 and player.position.y > previous_feet.y - var swiped_exit: bool = absf(player.position.x - 5090) < 85 and player.position.y > 510 and player.attack_time > 0 - previous_feet = player.position - if boss_down and (landed_on_exit or swiped_exit): - exit_sprite.play("exit_complete") - _finish(true) + for actor in team.members: + if hazard.node.overlaps_body(actor): actor.damage(hazard.node.position.x) + for actor in team.members: + if actor.hp <= 0: continue + var landed_on_exit: bool = absf(actor.position.x - 5090) < 49 and actor.previous_feet.y < EXIT_TOP - 0.5 and actor.position.y >= EXIT_TOP - 0.5 and actor.position.y <= EXIT_TOP + 14 and actor.position.y > actor.previous_feet.y + var swiped_exit: bool = absf(actor.position.x - 5090) < 85 and actor.position.y > 510 and actor.attack_time > 0 + actor.previous_feet = actor.position + if boss_down and (landed_on_exit or swiped_exit): + exit_sprite.play("exit_complete") + _finish(true) + break if is_instance_valid(boss) and not boss_down and encounter in ["intro", "fight"]: boss_label.text = boss_title + " " + "●".repeat(boss.hp) + "○".repeat(boss_max_hp - boss.hp) + "\n" + boss.attack_name else: boss_label.text = "" @@ -239,6 +250,7 @@ func _go(route: String) -> void: stage_clear.stop() AppRouter.go(route) func _update_hud() -> void: + team.update_health() for i in hearts.size(): hearts[i].texture = HEART_FULL if i < player.hp else HEART_EMPTY score_label.text = level_title.to_upper() + " / %06d" % score @@ -254,9 +266,10 @@ func _pause() -> void: func is_player_paused() -> bool: return get_tree().paused and pause_menu.is_open() and not finished func _resume() -> void: - player.input_lock = 0.15 - player.buffer = 0 - player.attack_time = 0 + for actor in team.members: + actor.input_lock = 0.15 + actor.buffer = 0 + actor.attack_time = 0 get_tree().paused = false pause_menu.close() func _finish(won: bool) -> void: @@ -376,11 +389,17 @@ func _build_arena() -> void: func _start_encounter() -> void: encounter = "intro" intro_remaining = 1.8 - player.velocity = Vector2.ZERO - player.attack_time = 0 - player.buffer = 0 - player.set_physics_process(false) - player.sprite.play("idle") + for actor in team.members: + if team.members.size() > 1 and (actor.position.x < 4210 or actor.hp <= 0): + actor.position = Vector2(4250 + actor.seat * 45, 590) + actor.dead = false + actor.hp = maxi(1, actor.hp) + actor.reset_physics_interpolation() + actor.velocity = Vector2.ZERO + actor.attack_time = 0 + actor.buffer = 0 + actor.set_physics_process(false) + actor.sprite.play("idle") arena_gates.show() for gate in arena_gates.get_children(): gate.collision_layer = 1 # Detach from Hoppy: a fixed arena view stays fixed during pursuit and jumps. @@ -496,11 +515,10 @@ func _create_player() -> void: func _setup_session() -> void: _hud() - player.health_changed.connect(_update_hud) - player.died.connect(func(): _finish(false)) - player.jumped.connect(func(): _sound("jump")) - player.hurt.connect(func(): _sound("hurt")) - player.swiped.connect(func(): AudioService.play_ui(2)) + add_child(team) + _connect_actor(player) + team.setup(player, _spawn_teammate, 110) + _update_hud() # Hold the hub track paused under the level. Pausing the tree (pause menu, how-to-play card) and # unpausing it un-pauses a pausable player, so the hub music came back on top of the level's. @@ -522,6 +540,7 @@ func _setup_session() -> void: add_child(sound) sfx_players[clip] = sound for child in get_children(): + if child is Enemy: foes.append(child) if not child is CanvasLayer: child.process_mode = Node.PROCESS_MODE_PAUSABLE # The results pause the tree, so the stage-clear stinger has to keep processing. stage_clear = AudioStreamPlayer.new() @@ -532,3 +551,54 @@ func _setup_session() -> void: add_child(stage_clear) # Everything above was placed, not moved: start interpolation from those positions. reset_physics_interpolation() + +func _connect_actor(actor: CharacterBody2D) -> void: + actor.health_changed.connect(_update_hud) + actor.died.connect(_player_down.bind(actor)) + actor.jumped.connect(func(): _sound("jump")) + actor.hurt.connect(func(): _sound("hurt")) + actor.swiped.connect(func(): AudioService.play_ui(2)) + +func _spawn_teammate(seat: int) -> CharacterBody2D: + var actor := Player.new() + actor.process_mode = Node.PROCESS_MODE_PAUSABLE + actor.position = player.position + if elapsed < 1.0: actor.position.x += seat * 56 + actor.z_index = player.z_index + actor.invulnerable = 1.2 + add_child(actor) + _connect_actor(actor) + actor.set_physics_process(not finished and encounter != "intro") + return actor + +func _player_down(actor: CharacterBody2D) -> void: + var survivor := team.front() + if survivor.hp <= 0: + player = actor + _finish(false) + elif actor == player: + player = survivor + if camera.get_parent() != self: + camera.reparent(player) + camera.position = Vector2(0, -245) + _update_hud() + +func _follow_team(front: CharacterBody2D) -> void: + for enemy in foes: + if is_instance_valid(enemy): + # Aim at the nearest teammate; attacks and touch check every teammate (enemy.gd targets()). + enemy.player = team.nearest(enemy.position) + enemy.team = team + if encounter not in ["approach", "cleared"]: return + var left := front.position.x + var span := get_viewport_rect().size.x * 0.78 + for actor in team.members: + if actor.hp <= 0: continue + # Catch up at a safe landing if the party stretches beyond the shared screen. + if front.position.x - actor.position.x > span and front.is_on_floor(): + actor.position = front.position + actor.velocity = Vector2.ZERO + actor.invulnerable = 1.2 + actor.reset_physics_interpolation() + left = minf(left, actor.position.x) + camera.position.x = (left + front.position.x) * 0.5 - player.position.x diff --git a/hoppys-adventure-arcade/modes/platformer/merge_monster.gd b/hoppys-adventure-arcade/modes/platformer/merge_monster.gd index ebd56502..39c26b5b 100644 --- a/hoppys-adventure-arcade/modes/platformer/merge_monster.gd +++ b/hoppys-adventure-arcade/modes/platformer/merge_monster.gd @@ -26,8 +26,9 @@ func _physics_process(dt: float) -> void: elif phase < 2.8: attack_name = "SLAM" sprite.play("slam") - if absf(player.position.x - position.x) < 230 and player.position.y > position.y - 40: - player.damage(position.x) + for target in targets(): + if absf(target.position.x - position.x) < 230 and target.position.y > position.y - 40: + target.damage(position.x) elif phase < 3.6: attack_name = "RECOVERING" sprite.play("idle") @@ -44,8 +45,8 @@ func _physics_process(dt: float) -> void: fired.emit(position + Vector2(0, -90), aim.rotated(angle)) queue_redraw() # Bay Area Blitz has no stomping: only a swipe hurts a bug; touching one, from any side, hurts Hoppy. - if hurtbox.overlaps_body(player): - player.damage(position.x) + for target in targets(): + if hurtbox.overlaps_body(target): target.damage(position.x) func take_hit() -> void: if active: super.take_hit() diff --git a/hoppys-adventure-arcade/modes/platformer/orbital_enemy.gd b/hoppys-adventure-arcade/modes/platformer/orbital_enemy.gd index b7875331..a87210ac 100644 --- a/hoppys-adventure-arcade/modes/platformer/orbital_enemy.gd +++ b/hoppys-adventure-arcade/modes/platformer/orbital_enemy.gd @@ -60,12 +60,15 @@ func _physics_process(dt: float) -> void: position = origin + Vector2(sin(phase) * 35, sin(phase * 2) * 10) sprite.play("hover") if hit_flash > 0: sprite.play("hurt") - if hurtbox.overlaps_body(player): - var top := position.y - (12 if kind == "security_drone" else 38) - if player.velocity.y > 120 and player.position.y < top: + var top := position.y - (12 if kind == "security_drone" else 38) + for target in targets(): + if not hurtbox.overlaps_body(target): continue + if target.velocity.y > 120 and target.position.y < top: take_hit() - player.velocity.y = -440 - else: player.damage(position.x) + target.velocity.y = -440 + # A defeated enemy hurts no one else this frame. + if dead: break + else: target.damage(position.x) queue_redraw() func _draw() -> void: diff --git a/hoppys-adventure-arcade/modes/platformer/orbital_hazard.gd b/hoppys-adventure-arcade/modes/platformer/orbital_hazard.gd index 70191978..b2ac986d 100644 --- a/hoppys-adventure-arcade/modes/platformer/orbital_hazard.gd +++ b/hoppys-adventure-arcade/modes/platformer/orbital_hazard.gd @@ -18,16 +18,18 @@ func _ready() -> void: add_child(area) ## The level calls this before the player tick; pause and retry share its clock ownership. -func tick(dt: float, player: CharacterBody2D) -> void: +func tick(dt: float, players: Array[CharacterBody2D]) -> void: clock += dt var phase := fmod(clock,5.2) state = "off" if phase < 2.0 else ("warning" if phase < 2.9 else ("active" if phase < 4.5 else "cooldown")) if kind == "laser": sprite.play("laser_"+state) - if state=="active" and area.overlaps_body(player): player.damage(position.x) + for player in players: + if state=="active" and area.overlaps_body(player): player.damage(position.x) else: sprite.play("vent_active" if state=="active" else ("vent_warning" if state=="warning" else "vent_closed")) - if state=="active" and area.overlaps_body(player): + for player in players: + if state!="active" or not area.overlaps_body(player): continue player.environmental_acceleration += Vector2(clampf(position.x-player.position.x,-100,100)*7,900) if absf(player.position.x-position.x)<42 and player.position.y>580: player.damage(position.x) diff --git a/hoppys-adventure-arcade/modes/platformer/player.gd b/hoppys-adventure-arcade/modes/platformer/player.gd index a8d4926b..59822593 100644 --- a/hoppys-adventure-arcade/modes/platformer/player.gd +++ b/hoppys-adventure-arcade/modes/platformer/player.gd @@ -33,6 +33,10 @@ var environmental_acceleration := Vector2.ZERO var sprite: AnimatedSprite2D var swipe: Area2D var bubble: Node2D +var previous_feet := Vector2.ZERO +var seat := 0 +var controls := preload("res://app/seat_input.gd").new() + func _ready() -> void: collision_layer = 2 collision_mask = 1 | 8 @@ -59,30 +63,30 @@ func _physics_process(dt: float) -> void: attack_time = maxf(0, attack_time - dt) coyote = 0.12 if is_on_floor() else maxf(0, coyote - dt) buffer = maxf(0, buffer - dt) - if input_lock <= 0 and Input.is_action_just_pressed("jump"): + if input_lock <= 0 and controls.pressed(&"jump"): buffer = 0.14 if buffer > 0 and coyote > 0: jumped.emit() velocity.y = JUMP buffer = 0 coyote = 0 - if not zero_gravity and Input.is_action_just_released("jump") and velocity.y < -240: + if not zero_gravity and controls.released(&"jump") and velocity.y < -240: velocity.y = -240 if zero_gravity: var thrust := 0.0 if input_lock <= 0: - thrust = Input.get_action_strength("move_down") - maxf(Input.get_action_strength("jump"), Input.get_action_strength("move_up")) + thrust = controls.strength(&"move_down") - maxf(controls.strength(&"jump"), controls.strength(&"move_up")) # Normal-gravity jump impulses and fall speed do not carry into assisted zero-g motion. velocity.y = clampf(velocity.y, -230.0, 230.0) velocity.y = move_toward(velocity.y, thrust * 230, (700 if thrust != 0 else 260) * dt) else: velocity.y = minf(900, velocity.y + 1600 * dt) if hurt_time <= 0: - var direction := Input.get_axis("move_left", "move_right") + var direction := controls.horizontal() velocity.x = move_toward(velocity.x, direction * SPEED * (1.35 if boost > 0 else 1.0), 2400 * dt) if direction != 0: facing = signf(direction) - if input_lock <= 0 and Input.is_action_just_pressed("attack") and attack_time <= 0: + if input_lock <= 0 and controls.pressed(&"attack") and attack_time <= 0: attack_time = 0.36 hit_targets.clear() sprite.stop() diff --git a/hoppys-adventure-arcade/project.godot b/hoppys-adventure-arcade/project.godot index ae02e644..dece7b02 100644 --- a/hoppys-adventure-arcade/project.godot +++ b/hoppys-adventure-arcade/project.godot @@ -22,6 +22,7 @@ SaveService="*res://app/save_service.gd" AudioService="*res://app/audio_service.gd" AppRouter="*res://app/app_router.gd" ControllerService="*res://app/controller_service.gd" +LocalParty="*res://app/local_party.gd" [display] diff --git a/hoppys-adventure-arcade/scenes/main_menu/main_menu.gd b/hoppys-adventure-arcade/scenes/main_menu/main_menu.gd index d54f2317..42251f3e 100644 --- a/hoppys-adventure-arcade/scenes/main_menu/main_menu.gd +++ b/hoppys-adventure-arcade/scenes/main_menu/main_menu.gd @@ -66,9 +66,17 @@ func _ready() -> void: ui.add_child(title) title.add_child(Style.label("HOPPY'S ADVENTURE", 44)) title.add_child(Style.label("A R C A D E", 24, Color("f5a568"))) - var subtitle := Style.label("SIX GAMES. ONE HOPPY. PICK A TILE TO PLAY.", 13, Color("afbdc9")) + var subtitle := Style.label("", 13, Color("afbdc9")) subtitle.position = Vector2(77, 128) ui.add_child(subtitle) + var update_party := func() -> void: + if LocalParty.size == 0: + subtitle.text = "PICK A GAME / LOCAL CO-OP · CLICK L3 ON EACH CONTROLLER TO JOIN" + else: + subtitle.text = "%d / 4 JOINED · %s" % [LocalParty.size, "CLICK L3 TO JOIN" if LocalParty.size < 4 else "TEAM READY"] + update_party.call() + LocalParty.changed.connect(update_party) + tree_exiting.connect(func(): LocalParty.changed.disconnect(update_party)) var grid := GridContainer.new() grid.name = "Games" grid.columns = GameCatalog.COLUMNS diff --git a/hoppys-adventure-arcade/scenes/platformer/enchanted_repo.gd b/hoppys-adventure-arcade/scenes/platformer/enchanted_repo.gd index 4e32198e..39875c92 100644 --- a/hoppys-adventure-arcade/scenes/platformer/enchanted_repo.gd +++ b/hoppys-adventure-arcade/scenes/platformer/enchanted_repo.gd @@ -131,9 +131,9 @@ func _physics_process(dt: float) -> void: # Traversal damage cannot intrude on the protected intro or cleared encounter. if encounter=="approach": for hazard in forest_hazards: - hazard.tick(dt,player) + hazard.tick(dt, team.members) if finished: return - for branch in branches: branch.tick(dt,player) + for branch in branches: branch.tick(dt, team.members) super._physics_process(dt) func _start_encounter() -> void: diff --git a/hoppys-adventure-arcade/scenes/platformer/orbital_ops.gd b/hoppys-adventure-arcade/scenes/platformer/orbital_ops.gd index 779789eb..b8ef9198 100644 --- a/hoppys-adventure-arcade/scenes/platformer/orbital_ops.gd +++ b/hoppys-adventure-arcade/scenes/platformer/orbital_ops.gd @@ -144,11 +144,12 @@ func _add_hazard(kind: String, pos: Vector2, offset: float) -> void: func _physics_process(dt: float) -> void: if finished or get_tree().paused: return - player.environmental_acceleration=Vector2.ZERO - player.zero_gravity=ZERO_G.has_point(player.position) + for actor in team.members: + actor.environmental_acceleration = Vector2.ZERO + actor.zero_gravity = ZERO_G.has_point(actor.position) gravity_label.text="ZERO-G • JUMP / UP ↑ DOWN ↓" if player.zero_gravity else "" for hazard in orbital_hazards: - hazard.tick(dt,player) + hazard.tick(dt, team.members) if finished: return for ring in rings: ring.rotation+=dt*.035 super._physics_process(dt) diff --git a/hoppys-adventure-arcade/scenes/runner/player/runner_player.gd b/hoppys-adventure-arcade/scenes/runner/player/runner_player.gd index 66b81d9a..d3a80d12 100644 --- a/hoppys-adventure-arcade/scenes/runner/player/runner_player.gd +++ b/hoppys-adventure-arcade/scenes/runner/player/runner_player.gd @@ -80,6 +80,9 @@ var _super_jump_invuln_remaining := 0.0 ## Set only when the code-built graybox stands in for the frontend visual. var _graybox_material: StandardMaterial3D +var seat := 0 +var controls := preload("res://app/seat_input.gd").new() + func _ready() -> void: add_to_group(&"runner_player") @@ -114,8 +117,8 @@ func _size_capsule(node: CollisionShape3D, radius: float, height: float) -> void func reset() -> void: controls_enabled = false - lane = 1 - target_lane = 1 + lane = [1, 0, 2, 1][seat] + target_lane = lane lane_t = 1.0 lane_from_x = 0.0 queued_lane_dir = 0 @@ -128,7 +131,7 @@ func reset() -> void: fast_falling = false jumped_this_airtime = false velocity = Vector3.ZERO - position = Vector3(lane_x(lane), 0.0, 0.0) + position = Vector3(lane_x(lane), 0.0, -1.8 * seat) _on_floor = true _roll_buffered = false _hurt_remaining = 0.0 @@ -151,10 +154,10 @@ func set_controls_enabled(enabled: bool) -> void: ## Copy the current pressed state into `held` so nothing fires on unpause. func sync_input_state() -> void: - held[&"jump"] = Input.is_action_pressed("jump") or Input.is_action_pressed("move_up") - held[&"roll"] = Input.is_action_pressed("roll") or Input.is_action_pressed("move_down") - held[&"left"] = Input.is_action_pressed("move_left") - held[&"right"] = Input.is_action_pressed("move_right") + held[&"jump"] = controls.held(&"jump") or controls.held(&"move_up") + held[&"roll"] = controls.held(&"roll") or controls.held(&"move_down") + held[&"left"] = controls.held(&"move_left") + held[&"right"] = controls.held(&"move_right") ## Buffer a jump: it fires as soon as the player is grounded (or inside the coyote window). func request_jump() -> void: @@ -236,19 +239,19 @@ func _physics_process(delta: float) -> void: func _read_input() -> void: if not controls_enabled or game == null or game.state != &"running": return - var jump_pressed := Input.is_action_pressed("jump") or Input.is_action_pressed("move_up") + var jump_pressed := controls.held(&"jump") or controls.held(&"move_up") if jump_pressed and not held[&"jump"]: request_jump() held[&"jump"] = jump_pressed - var roll_pressed := Input.is_action_pressed("roll") or Input.is_action_pressed("move_down") + var roll_pressed := controls.held(&"roll") or controls.held(&"move_down") if roll_pressed and not held[&"roll"]: request_roll() held[&"roll"] = roll_pressed - var left_pressed := Input.is_action_pressed("move_left") + var left_pressed := controls.held(&"move_left") if left_pressed and not held[&"left"]: request_lane(-1) held[&"left"] = left_pressed - var right_pressed := Input.is_action_pressed("move_right") + var right_pressed := controls.held(&"move_right") if right_pressed and not held[&"right"]: request_lane(1) held[&"right"] = right_pressed @@ -449,7 +452,7 @@ func _call_hit_manager(method: StringName) -> void: var manager := game.hit_manager if game != null else null if manager == null or not is_instance_valid(manager) or not manager.has_method(method): return - manager.call(method, SUPER_JUMP_SOURCE) + manager.call(method, SUPER_JUMP_SOURCE if seat == 0 else StringName("super_jump_p%d" % (seat + 1))) # --- 6. animation ------------------------------------------------------------------------------- @@ -479,6 +482,7 @@ func _set_anim_state(state: StringName) -> void: _graybox_material.albedo_color = GRAYBOX_TINTS.get(state, GRAYBOX_TINTS[&"run"]) func _emit_action(action: StringName) -> void: + _forward_action(action) if game != null: game.player_action.emit(action) @@ -490,7 +494,7 @@ func _connect_visual_events() -> void: if game == null: return var links := [ - [game.player_action, _forward_action], [game.damage_blocked, _forward_blocked], + [game.damage_blocked, _forward_blocked], [game.power_up_collected, _forward_power_up], [game.power_up_expired, _forward_power_up_end], [game.stage_cleared, _forward_stage_cleared], [game.boss_defeated, _forward_boss_defeated]] for link: Array in links: diff --git a/hoppys-adventure-arcade/scenes/runner/runner_game.gd b/hoppys-adventure-arcade/scenes/runner/runner_game.gd index 0284e968..b64847ed 100644 --- a/hoppys-adventure-arcade/scenes/runner/runner_game.gd +++ b/hoppys-adventure-arcade/scenes/runner/runner_game.gd @@ -219,6 +219,15 @@ static var pending_intro_mode: StringName = &"full" ## Resolved by path rather than $: the arena is a placeholder until the boss scene lands, and a ## project without it at all must still load (contract §11.3). @onready var boss_encounter: Node = get_node_or_null(NodePath(BOSS_ARENA_PATH)) +var teammates: Array[CharacterBody3D] = [] +var runners: Array[CharacterBody3D]: + get: + var all: Array[CharacterBody3D] = [] + if is_instance_valid(player): all.append(player) + all.append_array(teammates) + return all +@onready var local_party := get_node("/root/LocalParty") + @onready var player: CharacterBody3D = $Player @onready var pursuer: Node3D = $Pursuer @onready var camera_rig: Node3D = $CameraRig @@ -256,6 +265,9 @@ func _ready() -> void: boss_encounter, stage_manager, autopilot, player, pursuer, camera_rig, debug_overlay]: if node != null and node.has_method("setup"): node.setup(self) + if player: + local_party.changed.connect(_sync_runners) + _sync_runners() _connect_signals() _mount_frontend() if autostart: @@ -308,12 +320,14 @@ func start_run(run_seed := 0) -> void: player, pursuer, camera_rig, turn_rig]: if node != null and node.has_method("reset"): node.reset() + for runner in teammates: + runner.reset() if spawner != null and spawner.has_method("reset"): spawner.reset(seed) if stage_manager != null and stage_manager.has_method("reset"): stage_manager.reset(seed) - if player != null and player.has_method("set_controls_enabled"): - player.set_controls_enabled(true) + for runner in runners: + if runner.has_method("set_controls_enabled"): runner.set_controls_enabled(true) if checkpoint_retry: _restore_checkpoint(checkpoint) _set_state(&"running") @@ -385,8 +399,8 @@ func resume() -> void: if tree != null: tree.paused = false # Re-sync held input so a key held through the pause menu does not fire on unpause. - if player != null and player.has_method("sync_input_state"): - player.sync_input_state() + for runner in runners: + if runner.has_method("sync_input_state"): runner.sync_input_state() paused_changed.emit(false) ## True while the player has the run paused. The how-to-play card checks this before unpausing. @@ -632,13 +646,14 @@ func _apply_player_controls(manual: bool) -> void: return var held := stage_manager != null and is_instance_valid(stage_manager) \ and &"cinematic_hold" in stage_manager and bool(stage_manager.get(&"cinematic_hold")) - player.set_controls_enabled(manual and state == &"running" and not held) + for runner in runners: + if runner.has_method("set_controls_enabled"): runner.set_controls_enabled(manual and state == &"running" and not held) # --- run loop --- func _physics_process(delta: float) -> void: # RunnerGame processes while paused (it owns the pause menu), so the clock is gated by hand. - if paused: + if paused or (is_inside_tree() and get_tree().paused): return if state == &"running": # The run intro is a cinematic, not run time: the clock and the distance start at GO's @@ -735,12 +750,12 @@ func _on_score_changed(value: int, value_multiplier: float) -> void: func _on_damage_taken(_kind: StringName, _value: int) -> void: if camera_rig != null and is_instance_valid(camera_rig) and camera_rig.has_method("shake"): camera_rig.shake(SHAKE_ON_HIT) - if player != null and is_instance_valid(player) and player.has_method("play_hurt"): - player.play_hurt() + for runner in runners: + if runner.has_method("play_hurt"): runner.play_hurt() func _on_shield_changed(active: bool) -> void: - if player != null and is_instance_valid(player) and player.has_method("apply_shield"): - player.apply_shield(active) + for runner in runners: + if runner.has_method("apply_shield"): runner.apply_shield(active) func _on_power_up_collected(kind: StringName, _duration: float) -> void: _set_aura(kind, true) @@ -749,8 +764,8 @@ func _on_power_up_expired(kind: StringName) -> void: _set_aura(kind, false) func _set_aura(kind: StringName, on: bool) -> void: - if player != null and is_instance_valid(player) and player.has_method("apply_aura"): - player.apply_aura(kind, on) + for runner in runners: + if runner.has_method("apply_aura"): runner.apply_aura(kind, on) func _on_hazards_blasted(count: int) -> void: hazards_blasted_total += count @@ -814,11 +829,9 @@ func _on_caught() -> void: _set_state(&"caught") if autopilot != null and is_instance_valid(autopilot) and autopilot.has_method("set_enabled"): autopilot.set_enabled(false) - if player != null and is_instance_valid(player): - if player.has_method("set_controls_enabled"): - player.set_controls_enabled(false) - if player.has_method("play_dead"): - player.play_dead() + for runner in runners: + if runner.has_method("set_controls_enabled"): runner.set_controls_enabled(false) + if runner.has_method("play_dead"): runner.play_dead() if speed_controller != null and is_instance_valid(speed_controller) and speed_controller.has_method("begin_stop"): speed_controller.begin_stop(CAUGHT_STOP_SECONDS) if camera_rig != null and is_instance_valid(camera_rig) and camera_rig.has_method("shake"): @@ -990,3 +1003,29 @@ func _exit_tree() -> void: var tree := get_tree() if tree != null: tree.paused = false + +## The formation staggers players along the corridor so four can share three lanes. +## Each hurtbox and pickup feeds the run's shared health, pursuit and score. +func _sync_runners() -> void: + while teammates.size() + 1 < local_party.size: + var runner: CharacterBody3D = load("res://scenes/runner/player/runner_player.tscn").instantiate() + runner.seat = teammates.size() + 1 + runner.process_mode = Node.PROCESS_MODE_PAUSABLE + add_child(runner) + runner.controls.names = local_party.bindings(runner.seat) + runner.setup(self) + if runner.has_method("set_controls_enabled"): runner.set_controls_enabled(player.controls_enabled) + runner.reset_physics_interpolation() + teammates.append(runner) + if local_party.size == 0: return + for runner in runners: + runner.controls.names = local_party.bindings(runner.seat) + if runner.has_node("SeatLabel"): continue + var badge := Label3D.new() + badge.name = "SeatLabel" + badge.text = "P%d" % (runner.seat + 1) + badge.billboard = BaseMaterial3D.BILLBOARD_ENABLED + badge.modulate = local_party.COLORS[runner.seat] + badge.position.y = 2.35 + badge.pixel_size = 0.009 + runner.add_child(badge) diff --git a/hoppys-adventure-arcade/tests/local_multiplayer.gd b/hoppys-adventure-arcade/tests/local_multiplayer.gd new file mode 100644 index 00000000..d792fa9c --- /dev/null +++ b/hoppys-adventure-arcade/tests/local_multiplayer.gd @@ -0,0 +1,213 @@ +extends SceneTree +## Exercise the same controller events, hub, route instances and hotplug path as the booth. +const FakePads := preload("res://tests/support/fake_pads.gd") +const IDS := [2, 5, 7, 9, 12] +var pads := FakePads.new() +var party: Node +var router: Node +var failures := 0 + +func _initialize() -> void: + run.call_deferred() + +func check(ok: bool, message: String) -> void: + if not ok: + failures += 1 + push_error(message) + +func frames(count: int) -> void: + for i in count: await physics_frame + +func plug(id: int) -> void: + pads.plug(id, "DualSense Wireless Controller", "identical-dualsense", 0x054c) + party.connection_changed(id, true) + +func unplug(id: int) -> void: + pads.unplug(id) + party.connection_changed(id, false) + +func button(id: int, index: JoyButton, down: bool) -> void: + var event := InputEventJoypadButton.new() + event.device = id + event.button_index = index + event.pressed = down + Input.parse_input_event(event) + Input.flush_buffered_events() + +func tap(id: int, index: JoyButton) -> void: + button(id, index, true) + button(id, index, false) + +func axis(id: int, value: float) -> void: + var event := InputEventJoypadMotion.new() + event.device = id + event.axis = JOY_AXIS_LEFT_X + event.axis_value = value + Input.parse_input_event(event) + Input.flush_buffered_events() + +func visit(route: String) -> void: + var error := change_scene_to_file(router.ROUTES[route]) + if error != OK: + # scene_changed never fires for a scene that fails to load, so stop here instead of waiting on it. + push_error("The %s route doesn't load: %s" % [route, error_string(error)]) + quit(1) + return + await scene_changed + await frames(2) + +func run() -> void: + party = root.get_node("LocalParty") + router = root.get_node("AppRouter") + party.use_hardware(pads) + await visit("hub") + for id in IDS: plug(id) + axis(5, 0.8) + axis(5, 0.0) + check(party.size == 0, "Connecting and stick motion leave all seats free") + for id in IDS: tap(id, JOY_BUTTON_LEFT_STICK) + tap(2, JOY_BUTTON_LEFT_STICK) + check(party.size == 4 and party.roster.role_of(12) == &"", "Four unique join presses fill four seats") + for i in 4: + check(party.roster.device_for(party.ROLES[i]) == IDS[i], "Seats follow join order") + await platformers() + await brawlers() + await runner() + await booth_handoff() + unload_current_scene() + await frames(5) + await root.get_node("AudioService").settle() + print("LOCAL MULTIPLAYER: ", failures, " failure(s)") + quit(1 if failures else 0) + +func platformers() -> void: + for route in ["bay_area_blitz", "orbital_ops", "enchanted_repo"]: + await visit(route) + var level := current_scene + level._resume() + tap(12, JOY_BUTTON_START) + check(not paused, "An unjoined pad cannot pause " + route) + await frames(25) + check(level.team.members.size() == 4, route + " spawns four players") + var xs := PackedFloat32Array() + for actor in level.team.members: xs.append(actor.position.x) + axis(7, 1.0) + button(12, JOY_BUTTON_DPAD_LEFT, true) + await frames(12) + axis(7, 0.0) + button(12, JOY_BUTTON_DPAD_LEFT, false) + for i in 4: + var dx: float = level.team.members[i].position.x - xs[i] + check(dx > 10.0 if i == 2 else absf(dx) < 1.0, "%s: P3 owns its axis, P%d delta %.1f" % [route, i + 1, dx]) + if route == "bay_area_blitz": + button(9, JOY_BUTTON_A, true) + await frames(3) + check(level.team.members[3].velocity.y < -100 and level.player.is_on_floor(), "P4 jumps independently") + button(9, JOY_BUTTON_A, false) + await hotplug(level) + level.team.members[0]._die() + check(not level.finished and level.player.hp > 0, "Survivors keep playing after P1 falls") + for i in range(1, 4): level.team.members[i]._die() + check(level.finished, "The last knockout ends the level") + +func hotplug(level: Node) -> void: + var saved: CharacterBody2D = level.team.members[1] + saved.hp = 2 + var position_before := saved.position + button(5, JOY_BUTTON_DPAD_RIGHT, true) + unplug(5) + unplug(9) + await frames(5) + check(paused and saved.position == position_before, "Disconnect holds the game and avatar") + plug(8) + plug(11) + check(party.roster.is_waiting(&"p2") and party.roster.is_waiting(&"p4"), "Identical pads leave ambiguous seats reserved") + tap(8, JOY_BUTTON_Y) + check(paused and party.roster.device_for(&"p4") == 8, "P4 can reclaim first") + tap(11, JOY_BUTTON_B) + check(not paused and party.roster.device_for(&"p2") == 11, "Last reconnect resumes") + await frames(5) + check(saved == level.team.members[1] and saved.hp == 2 and saved.position == position_before, "A new device ID keeps P2's avatar, health and position, with no stuck direction") + button(5, JOY_BUTTON_DPAD_RIGHT, false) + level._pause() + unplug(7) + plug(13) + check(paused and level.pause_menu.is_open(), "A unique reconnect preserves a player pause") + unplug(13) + plug(7) + level._resume() + unplug(8) + plug(9) + +func brawlers() -> void: + for route in ["code_city_brawl", "heroes_vs_villains"]: + await visit(route) + var game := current_scene + game.test_mode = true + game.begin_play() + await frames(18) + var actors: Array = game.team.members.duplicate() + check(actors.size() == 4, route + " spawns four fighters") + var start: Vector2 = actors[1].position + var p1_start: Vector2 = actors[0].position + button(11, JOY_BUTTON_DPAD_RIGHT, true) + await frames(14) + button(11, JOY_BUTTON_DPAD_RIGHT, false) + check(actors[1].position.x > start.x + 15 and actors[0].position == p1_start, route + " isolates movement") + button(7, JOY_BUTTON_X, true) + await frames(2) + check(actors[2].swing_left > 0 and actors[1].swing_left == 0, route + " isolates attacks") + button(7, JOY_BUTTON_X, false) + var weapon := "review_stamp" if route == "heroes_vs_villains" else "debug_stick" + game.drop(weapon, actors[3].position) + button(9, JOY_BUTTON_Y, true) + await frames(2) + button(9, JOY_BUTTON_Y, false) + check(actors[3].weapon == weapon and actors[0].weapon == "", route + " grants the weapon to its collector") + actors[0].hp = 1 + actors[0].take_hit(actors[0].position - Vector2.RIGHT) + check(game.playing and game.player != actors[0], "P1 knockout hands the camera and fight to a survivor") + game.enter_room(1) + check(actors[0].hp == 1 and actors[0].position.x > 1280, "Next room rallies fallen teammates") + game.start_stage(1) + check(game.team.members.size() == 4 and game.team.members[1] != actors[1], "Fresh stage recreates four fighters") + +func runner() -> void: + await visit("runner_game") + var game := current_scene + game.start_run(42) + await frames(25) + tap(7, JOY_BUTTON_A) + await frames(4) + check(game.player.controls_enabled and game.runners[3].controls_enabled, "Skipping the opening hands control to all runners") + check(game.runners.size() == 4, "Runner has four live hurtboxes") + var first: int = game.player.target_lane + button(11, JOY_BUTTON_DPAD_RIGHT, true) + await frames(4) + button(11, JOY_BUTTON_DPAD_RIGHT, false) + check(game.runners[1].target_lane == 1 and game.player.target_lane == first, "P2 can change lanes while P1 holds") + unplug(7) + var distance: float = game.distance + await frames(4) + check(paused and game.distance == distance, "Runner clock freezes for a disconnected teammate") + plug(7) + check(not paused, "Restored runner resumes") + +func booth_handoff() -> void: + router.set_booth(true) + unplug(9) + button(11, JOY_BUTTON_X, true) + button(11, JOY_BUTTON_X, false) + router.idle_seconds = router.idle_limit + await create_timer(1.0).timeout + check(current_scene.scene_file_path == router.ROUTES.hub and party.size == 0 and not paused, + "Booth idle return frees every seat, including the missing controller") + tap(12, JOY_BUTTON_LEFT_STICK) + check(party.size == 1 and party.roster.device_for(&"p1") == 12, "Next visitor starts as P1") + router.set_booth(false) + party.reset() + await visit("bay_area_blitz") + tap(11, JOY_BUTTON_X) + tap(2, JOY_BUTTON_LEFT_STICK) + check(party.roster.device_for(&"p1") == 11 and party.roster.device_for(&"p2") == 2, "An active solo player keeps P1 on drop-in") + check(current_scene.team.members.size() == 2, "Mid-level join creates the new teammate") diff --git a/hoppys-adventure-arcade/tests/local_multiplayer.gd.uid b/hoppys-adventure-arcade/tests/local_multiplayer.gd.uid new file mode 100644 index 00000000..674681a1 --- /dev/null +++ b/hoppys-adventure-arcade/tests/local_multiplayer.gd.uid @@ -0,0 +1 @@ +uid://cr6ii7g86o3q5 diff --git a/hoppys-adventure-arcade/tests/runner_run_intro.gd b/hoppys-adventure-arcade/tests/runner_run_intro.gd index 9ea61599..93b688f8 100644 --- a/hoppys-adventure-arcade/tests/runner_run_intro.gd +++ b/hoppys-adventure-arcade/tests/runner_run_intro.gd @@ -70,7 +70,7 @@ func _finish() -> void: # return also left up is freed here. var leftovers: Array[Node] = [] for child in root.get_children(): - if child.name in ["SaveService", "AudioService", "AppRouter", "ControllerService"]: + if ProjectSettings.has_setting("autoload/%s" % child.name): continue leftovers.append(child) for child in leftovers: diff --git a/hoppys-adventure-arcade/tests/team_targets.gd b/hoppys-adventure-arcade/tests/team_targets.gd new file mode 100644 index 00000000..69cf8bd9 --- /dev/null +++ b/hoppys-adventure-arcade/tests/team_targets.gd @@ -0,0 +1,161 @@ +extends SceneTree +## A platformer enemy aims at the nearest teammate but its attacks hurt every teammate in reach: the +## Monolith's slam hits P1 standing in it even while a jumping P2 is nearer. Outside a team it checks +## `player` alone, as before co-op. A stomp that defeats an enemy, or breaks the Monolith's armor, +## hurts no teammate touching it in that frame; one it survives still does. +## Run headless with --path --script res://tests/team_targets.gd. +const Monolith := preload("res://modes/platformer/legacy_monolith.gd") +const DeprecatedApi := preload("res://modes/platformer/deprecated_api.gd") +const ForestEnemy := preload("res://modes/platformer/enchanted_enemy.gd") +const OrbitalEnemy := preload("res://modes/platformer/orbital_enemy.gd") +var failures := 0 + +class Teammate extends CharacterBody2D: + var hp := 3 + var hits := 0 + func damage(_source_x: float) -> bool: + hits += 1 + return true + +class Team extends Node: + var members: Array[CharacterBody2D] = [] + +func _initialize() -> void: + call_deferred("run") + +func check(ok: bool, message: String) -> void: + print("PASS: " if ok else "FAIL: ", message) + if not ok: + failures += 1 + +## A teammate on the players' collision layer, which every hurtbox watches. +func teammate(at: Vector2) -> Teammate: + var actor := Teammate.new() + actor.position = at + actor.collision_layer = 2 + actor.collision_mask = 0 + var box := RectangleShape2D.new() + box.size = Vector2(30, 40) + var shape := CollisionShape2D.new() + shape.shape = box + actor.add_child(shape) + root.add_child(actor) + return actor + +## A Monolith mid-slam at (4660, 600), the slam's reach being 175 px either side. +func slamming(aim: CharacterBody2D, team: Node) -> Node2D: + var boss := Monolith.new() + boss.position = Vector2(4660, 600) + boss.player = aim + boss.team = team + root.add_child(boss) + boss.active = true + boss.state_index = Monolith.STATES.find("slam") + boss._physics_process(0.016) + return boss + +## Adds `enemy` at `at`, aiming at `aim`, with its own physics process off, so the test runs +## its frames. +func place(enemy: Node2D, at: Vector2, team: Node, aim: CharacterBody2D) -> void: + enemy.position = at + enemy.player = aim + enemy.team = team + root.add_child(enemy) + enemy.set_physics_process(false) + +## P1 falls onto `enemy` from `top` px above it while P2 stands in its side. After the physics +## frames its hurtbox needs to see them both, one frame of the enemy runs. +func stomp(enemy: Node2D, top: float, p1: Teammate, p2: Teammate) -> void: + p1.position = enemy.position + Vector2(0, -top) + p1.velocity = Vector2(0, 300) + p2.position = enemy.position + Vector2(12, -10) + p2.velocity = Vector2.ZERO + for i in 3: + await physics_frame + p1.hits = 0 + p2.hits = 0 + enemy._physics_process(1.0 / 60) + +func run() -> void: + var p1 := teammate(Vector2(4810, 600)) + var p2 := teammate(Vector2(4660, 500)) + var team := Team.new() + team.members.assign([p1, p2]) + root.add_child(team) + var boss := slamming(p2, team) + check(boss.state() == "slam", "The Monolith is slamming") + check(p1.hits == 1, "The slam hurts P1, who stands in it, though jumping P2 is nearer (%d hit)" % p1.hits) + check(p2.hits == 0, "The slam misses P2, who is above it") + boss.free() + + p1.hits = 0 + p1.hp = 0 + boss = slamming(p2, team) + check(p1.hits == 0, "A teammate who is out takes no more hits") + boss.free() + + p1.hp = 3 + boss = slamming(p1, null) + check(p1.hits == 1 and p2.hits == 0, "Outside a team the slam checks `player` alone") + boss.free() + + var monolith := Monolith.new() + place(monolith, Vector2(4660, 600), team, p1) + monolith.active = true + monolith.hp = 10 + monolith.state_index = Monolith.STATES.find("slam_recover") + await stomp(monolith, 130, p1, p2) + check(monolith.hp == 9 and monolith.break_time > 0, "P1's stomp breaks the Monolith's outer armor") + check(p1.hits == 0 and p2.hits == 0, + "The armor break hurts neither P1 nor P2 beside it (%d, %d hits)" % [p1.hits, p2.hits]) + monolith.free() + + monolith = Monolith.new() + place(monolith, Vector2(4660, 600), team, p1) + monolith.active = true + monolith.hp = 1 + monolith.state_index = Monolith.STATES.find("slam_recover") + await stomp(monolith, 130, p1, p2) + check(monolith.dead and p2.hits == 0, + "The Monolith P1 defeats doesn't hurt P2 beside it (%d hits)" % p2.hits) + monolith.free() + + var api := DeprecatedApi.new() + place(api, Vector2(4600, 600), team, p1) + api.active = true + api.state_index = DeprecatedApi.STATES.find("slam_warning") + await stomp(api, 100, p1, p2) + check(api.hp == 9 and p2.hits == 1, + "A stomp the Deprecated API survives leaves its touch hurting P2 (%d hits)" % p2.hits) + api.free() + + api = DeprecatedApi.new() + place(api, Vector2(4600, 600), team, p1) + api.active = true + api.hp = 1 + api.state_index = DeprecatedApi.STATES.find("slam_warning") + await stomp(api, 100, p1, p2) + check(api.dead and p2.hits == 0, + "The Deprecated API P1 defeats doesn't hurt P2 beside it (%d hits)" % p2.hits) + api.free() + + var gnome := ForestEnemy.new() + gnome.kind = "nitpick_gnome" + place(gnome, Vector2(1200, 600), team, p1) + await stomp(gnome, 45, p1, p2) + check(gnome.dead and p2.hits == 0, + "The gnome P1 defeats doesn't hurt P2 beside it (%d hits)" % p2.hits) + gnome.free() + + var drone := OrbitalEnemy.new() + drone.kind = "security_drone" + place(drone, Vector2(1200, 500), team, p1) + await stomp(drone, 25, p1, p2) + check(drone.dead and p2.hits == 0, + "The drone P1 defeats doesn't hurt P2 beside it (%d hits)" % p2.hits) + drone.free() + + for node in [p1, p2, team]: node.free() + await process_frame + print("Team targets failures: ", failures) + quit(1 if failures else 0) diff --git a/hoppys-adventure-arcade/tests/team_targets.gd.uid b/hoppys-adventure-arcade/tests/team_targets.gd.uid new file mode 100644 index 00000000..32274535 --- /dev/null +++ b/hoppys-adventure-arcade/tests/team_targets.gd.uid @@ -0,0 +1 @@ +uid://bfcu50e4aap14