Phones: dual floating thumbsticks (move right, attack left)
TouchSticks: a finger on the right half of the screen is a move stick where it lands (the move_* actions), one on the left half an attack stick (the aim_* actions, with fire held past the aim dead zone, so the weapon attacks that way each time it's ready). Buttons get their touches first; the sticks only act while the scarecrow can, and a pause or freeze lets them go. On phones a tap is also an emulated left click, so fire and offhand lose their mouse buttons and ScarecrowCombat ignores emulated mouse events for its aim device. A held finger still skips the intro, and a tap skips the farmers' return. Docs: the first device run's numbers (night 20 held 60 FPS) and the sticks. Graph update. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
59aa97c7a3
commit
8c81d815eb
19 changed files with 3917 additions and 3655 deletions
|
|
@ -5,7 +5,7 @@ extends Node3D
|
|||
## and parks in the farmyard by the house with a honk; the two farmers (tinted mannequins) get
|
||||
## out, walk to the house door, wave to the scarecrow waiting by the yard, and cheer. A cutscene
|
||||
## camera follows the car, then frames the yard; the HUD hides behind letterbox bars. Fire,
|
||||
## interact, or Space / Enter / A skips to the end. finished is emitted once it's
|
||||
## interact, Space / Enter / A, or a tap skips to the end. finished is emitted once it's
|
||||
## over (or skipped), and EndPanel shows the final assessment over the scene.
|
||||
## Built when it starts, after the game is over, so nothing is created during play. The car (with
|
||||
## its roof luggage, which sways on the turns and tips forward as it stops), the farmers, the
|
||||
|
|
@ -250,6 +250,7 @@ func _stop_engine() -> void:
|
|||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if not running or done:
|
||||
return
|
||||
if event.is_action_pressed("ui_accept") or event.is_action_pressed("interact") or event.is_action_pressed("fire"):
|
||||
var tap := event is InputEventScreenTouch and (event as InputEventScreenTouch).pressed # phones: taps don't press fire
|
||||
if event.is_action_pressed("ui_accept") or event.is_action_pressed("interact") or event.is_action_pressed("fire") or tap:
|
||||
skip()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ extends Node
|
|||
## over GD-Sync (GDSyncLink), with voice chat. In co-op the menus don't pause the farm; the
|
||||
## host's leaving ends the partner's game (back to this menu, which says why), the partner's
|
||||
## leaving leaves the host alone. [M] mutes the microphone.
|
||||
## * On a phone (MobilePort): no ToonLook, no co-op, and leaving the app pauses. The iOS test
|
||||
## build adds PerfTest (frame times and test buttons).
|
||||
## * On a phone (MobilePort): no ToonLook, no co-op, two thumbsticks (TouchSticks), and leaving
|
||||
## the app pauses. The iOS test build adds PerfTest (frame times and test buttons).
|
||||
## Main processes while paused; the farm doesn't. Tests set save_path and settings_path
|
||||
## before adding it to the tree.
|
||||
|
||||
|
|
@ -132,6 +132,11 @@ func _ready() -> void:
|
|||
var hud_layer := farm.get_node_or_null("Hud")
|
||||
if hud_layer != null:
|
||||
hud_layer.add_child(coop_hud)
|
||||
if MobilePort.active(): # the phone's thumbsticks, over the HUD (hidden with it in the menus)
|
||||
var sticks := TouchSticks.new()
|
||||
sticks.name = "TouchSticks"
|
||||
sticks.setup(sim)
|
||||
hud_layer.add_child(sticks)
|
||||
if sim.audio != null:
|
||||
sim.audio.wire_buttons($Menus)
|
||||
_menu_camera = Camera3D.new()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ extends RefCounted
|
|||
## * active(): a phone (the "mobile" feature). The farm keeps its standard materials (Main
|
||||
## doesn't add ToonLook: the outline needs Forward+, phones run the Mobile renderer), the 3D
|
||||
## view renders at GameSettings.resolution_scale instead of pixelated, co-op is hidden (the
|
||||
## main menu's button and the settings' Co-op section), and leaving the app pauses the game.
|
||||
## main menu's button and the settings' Co-op section), two thumbsticks move and attack
|
||||
## (TouchSticks), and leaving the app pauses the game.
|
||||
## The microphone is never opened (audio/driver/enable_input.mobile in project.godot).
|
||||
## * perf_test(): the iOS preset's "perf_test" feature. Main adds PerfTest (the frame-time
|
||||
## readout and test buttons), and CampaignDebug's jumps work in that release build.
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ const SKIP_HOLD := 1.0
|
|||
const SKIP_FADE := 0.4
|
||||
const REVEAL_FADE := 0.5
|
||||
## What holding skips: Space / Enter / A (ui_accept), E / X (interact), the mouse button / RT
|
||||
## (fire).
|
||||
## (fire), and on a phone, a finger anywhere on the screen.
|
||||
const SKIP_ACTIONS: Array[StringName] = [&"ui_accept", &"interact", &"fire"]
|
||||
## Degrees the lines' shots look under their subject, so it stands in the frame's upper half,
|
||||
## clear of the dialogue box.
|
||||
|
|
@ -158,6 +158,7 @@ var _skipping := false
|
|||
var _revealing := false
|
||||
var _hold: float = 0.0
|
||||
var _armed := false
|
||||
var _fingers := {} # touch index -> true while that finger is down (phones' taps no longer press fire)
|
||||
var _last_frame: int = 0
|
||||
var _talked := false
|
||||
var _line: int = -1
|
||||
|
|
@ -1517,12 +1518,26 @@ func _ground_at(at: Vector3) -> float:
|
|||
return float((hit["position"] as Vector3).y) if not hit.is_empty() else 0.0
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
var touch := event as InputEventScreenTouch
|
||||
if touch != null:
|
||||
if touch.pressed:
|
||||
_fingers[touch.index] = true
|
||||
else:
|
||||
_fingers.erase(touch.index)
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_PAUSED or what == NOTIFICATION_UNPAUSED:
|
||||
_fingers.clear() # a finger lifted while paused never told us
|
||||
|
||||
|
||||
func _poll_skip(delta: float) -> void:
|
||||
var frame := Engine.get_process_frames()
|
||||
if frame > _last_frame + 2:
|
||||
_armed = false # back from a pause: a key still down from the menu doesn't count
|
||||
_last_frame = frame
|
||||
var held := false
|
||||
var held := not _fingers.is_empty()
|
||||
for action in SKIP_ACTIONS:
|
||||
held = held or Input.is_action_pressed(action)
|
||||
if not held or (blocked.is_valid() and bool(blocked.call())):
|
||||
|
|
|
|||
|
|
@ -247,6 +247,8 @@ func _input(event: InputEvent) -> void:
|
|||
if remote != null:
|
||||
return
|
||||
_edges.note(event, SWITCH_ACTIONS)
|
||||
if event is InputEventMouse and event.device == InputEvent.DEVICE_ID_EMULATION:
|
||||
return # a phone's tap (Godot's emulated mouse) isn't the mouse: TouchSticks aims there
|
||||
if event is InputEventMouseMotion:
|
||||
if device == Device.GAMEPAD:
|
||||
_mouse_travel += (event as InputEventMouseMotion).relative.length()
|
||||
|
|
|
|||
148
game/scripts/touch_sticks.gd
Normal file
148
game/scripts/touch_sticks.gd
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
class_name TouchSticks
|
||||
extends Control
|
||||
## The phone's controls (MobilePort; Main adds it over the HUD): two floating thumbsticks. A
|
||||
## finger down on one half of the screen starts that half's stick where it lands; dragging tilts
|
||||
## it (past the rim, the base follows the finger), and lifting the finger lets it go.
|
||||
## * Move (right half): the move_* actions, as far as the stick is tilted. Screen up is
|
||||
## forward, as with WASD.
|
||||
## * Attack (left half): the aim_* actions, as a gamepad's right stick, and fire held while the
|
||||
## stick is tilted past the aim dead zone, so the main weapon attacks that way each time it's
|
||||
## ready.
|
||||
## The sticks only take touches the HUD and the menus don't (their buttons get them first), and
|
||||
## only while the scarecrow can act: not paused (menus, conversations), not frozen (the intro),
|
||||
## not once the vacation is over. A pause or freeze lets both sticks go. Each stick is drawn only
|
||||
## while a finger is on it.
|
||||
## On phones a tap is also a left click (Godot's mouse emulation, which the buttons need), and
|
||||
## the left click is fire: fire and offhand lose their mouse buttons here, so only the attack
|
||||
## stick (or a paired gamepad) attacks.
|
||||
|
||||
enum Stick { MOVE, ATTACK }
|
||||
|
||||
const MOVE_ON_RIGHT := true # the move stick's half of the screen; the attack stick has the other
|
||||
const RADIUS := 150.0 # base to rim, in canvas pixels (the 1920-wide canvas)
|
||||
## Per stick: its left, right, up (forward), and down actions.
|
||||
const ACTIONS: Array = [[&"move_left", &"move_right", &"move_forward", &"move_back"],
|
||||
[&"aim_left", &"aim_right", &"aim_up", &"aim_down"]]
|
||||
const COLORS: Array[Color] = [UiTheme.TEXT, Color(1.0, 0.5, 0.38)]
|
||||
|
||||
var sim: FarmSim
|
||||
## Per stick (Stick): the finger on it (-1: none), its base, and its tilt (length 0-1).
|
||||
var finger: Array[int] = [-1, -1]
|
||||
var base: Array[Vector2] = [Vector2.ZERO, Vector2.ZERO]
|
||||
var tilt: Array[Vector2] = [Vector2.ZERO, Vector2.ZERO]
|
||||
|
||||
|
||||
func setup(p_sim: FarmSim) -> void:
|
||||
sim = p_sim
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE # never in the way of the HUD's own buttons
|
||||
for action: StringName in [&"fire", &"offhand"]:
|
||||
for e in InputMap.action_get_events(action):
|
||||
if e is InputEventMouseButton:
|
||||
InputMap.action_erase_event(action, e)
|
||||
if sim != null:
|
||||
sim.combat.device = ScarecrowCombat.Device.GAMEPAD # aim along the stick, not at the last touch
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_PAUSED or (what == NOTIFICATION_VISIBILITY_CHANGED and not is_visible_in_tree()):
|
||||
let_go()
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if (finger[Stick.MOVE] != -1 or finger[Stick.ATTACK] != -1) and not can_act():
|
||||
let_go()
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
var touch := event as InputEventScreenTouch
|
||||
if touch != null:
|
||||
if touch.pressed:
|
||||
var s := side_of(touch.position)
|
||||
if not can_act() or finger[s] != -1:
|
||||
return
|
||||
finger[s] = touch.index
|
||||
base[s] = touch.position
|
||||
tilt[s] = Vector2.ZERO
|
||||
_apply(s)
|
||||
get_viewport().set_input_as_handled()
|
||||
else:
|
||||
for s in 2:
|
||||
if finger[s] == touch.index:
|
||||
_release(s)
|
||||
get_viewport().set_input_as_handled()
|
||||
return
|
||||
var drag := event as InputEventScreenDrag
|
||||
if drag == null:
|
||||
return
|
||||
for s in 2:
|
||||
if finger[s] != drag.index:
|
||||
continue
|
||||
var d := drag.position - base[s]
|
||||
if d.length() > RADIUS:
|
||||
base[s] += d.normalized() * (d.length() - RADIUS)
|
||||
d = drag.position - base[s]
|
||||
tilt[s] = d / RADIUS
|
||||
_apply(s)
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
## Whether the scarecrow can take orders now (see the class notes).
|
||||
func can_act() -> bool:
|
||||
return sim != null and is_visible_in_tree() and not sim.local_frozen and not sim.campaign.is_over()
|
||||
|
||||
|
||||
## Which stick a finger landing at this point (canvas coordinates) starts.
|
||||
func side_of(at: Vector2) -> Stick:
|
||||
var right := at.x >= size.x * 0.5
|
||||
return Stick.MOVE if right == MOVE_ON_RIGHT else Stick.ATTACK
|
||||
|
||||
|
||||
## Lets both sticks go: their actions and fire released.
|
||||
func let_go() -> void:
|
||||
for s in 2:
|
||||
if finger[s] != -1:
|
||||
_release(s)
|
||||
|
||||
|
||||
func _release(s: int) -> void:
|
||||
finger[s] = -1
|
||||
tilt[s] = Vector2.ZERO
|
||||
_apply(s)
|
||||
|
||||
|
||||
## Presses the stick's actions by its tilt (released at zero), and for the attack stick, fire.
|
||||
func _apply(s: int) -> void:
|
||||
var v := tilt[s]
|
||||
var names: Array = ACTIONS[s]
|
||||
_press(names[0], -v.x)
|
||||
_press(names[1], v.x)
|
||||
_press(names[2], -v.y)
|
||||
_press(names[3], v.y)
|
||||
if s == Stick.ATTACK:
|
||||
var dead := sim.config.aim_dead_zone if sim != null else 0.3
|
||||
if v.length() > dead:
|
||||
Input.action_press(&"fire") # aiming (combat's stick reads past the same dead zone)
|
||||
else:
|
||||
Input.action_release(&"fire")
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _press(action: StringName, strength: float) -> void:
|
||||
if strength > 0.0:
|
||||
Input.action_press(action, minf(strength, 1.0))
|
||||
else:
|
||||
Input.action_release(action)
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
for s in 2:
|
||||
if finger[s] == -1:
|
||||
continue
|
||||
var c := COLORS[s]
|
||||
draw_circle(base[s], RADIUS, Color(c, 0.1))
|
||||
Sketch.circle(self, base[s], RADIUS, Color(c, 0.5), 5.0, 1.0 + s)
|
||||
draw_circle(base[s] + tilt[s] * RADIUS, RADIUS * 0.38, Color(c, 0.45))
|
||||
1
game/scripts/touch_sticks.gd.uid
Normal file
1
game/scripts/touch_sticks.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ca23aop5nwkja
|
||||
Loading…
Add table
Add a link
Reference in a new issue