updates
This commit is contained in:
parent
4298caf5cb
commit
2e6638b744
19 changed files with 484 additions and 185 deletions
|
|
@ -27,6 +27,12 @@ signal failed(text: String)
|
|||
|
||||
const SEARCH_EVERY := 2.0
|
||||
const GAME_PORT := 42400
|
||||
## What a LAN host's computer has to let in (GD-Sync's LocalServer: announcements on
|
||||
## 42354..42373, games on 42400..42419).
|
||||
const LAN_PORTS := "UDP 42354-42373 and 42400-42419"
|
||||
## Seconds to wait for the host to answer a join. A firewall in the way drops the request
|
||||
## without a word, so this is the only way to tell.
|
||||
const JOIN_TIMEOUT := 10.0
|
||||
const GAME_TAG := "harvest-season"
|
||||
|
||||
var gdsync: Node
|
||||
|
|
@ -40,6 +46,7 @@ var status := ""
|
|||
var _after_connect := "" # "host" or "search"
|
||||
var _join_target := ""
|
||||
var _search_left: float = 0.0
|
||||
var _join_left: float = 0.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -96,6 +103,7 @@ func join(lobby: String) -> void:
|
|||
return
|
||||
_join_target = lobby
|
||||
stage = Stage.JOINING
|
||||
_join_left = JOIN_TIMEOUT
|
||||
_say("Joining %s..." % lobby)
|
||||
gdsync.lobby_join(lobby)
|
||||
|
||||
|
|
@ -169,6 +177,21 @@ func _process(delta: float) -> void:
|
|||
if _search_left <= 0.0:
|
||||
_search_left = SEARCH_EVERY
|
||||
gdsync.get_public_lobbies()
|
||||
elif stage == Stage.JOINING:
|
||||
_join_left -= delta
|
||||
if _join_left <= 0.0:
|
||||
_join_timed_out()
|
||||
|
||||
|
||||
## No answer to a join: give up and say why it's most likely.
|
||||
func _join_timed_out() -> void:
|
||||
var target := _join_target
|
||||
var lan := mode == Mode.LAN
|
||||
leave()
|
||||
if lan:
|
||||
failed.emit("No answer from %s. The host's firewall is probably blocking the game (it needs %s open), or the address is wrong. Or both of you pick Online." % [target, LAN_PORTS])
|
||||
else:
|
||||
failed.emit("No answer from %s through GD-Sync. Check your connection and try again." % target)
|
||||
|
||||
|
||||
func _begin(p_mode: Mode, p_name: String) -> bool:
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ func _ready() -> void:
|
|||
if upgrade_panel != null:
|
||||
upgrade_panel.setup(campaign, structures, player)
|
||||
interactions.upgrade_panel = upgrade_panel
|
||||
upgrade_panel.bought.connect(func(id: String) -> void: # a new weapon goes into the hand
|
||||
upgrade_panel.bought.connect(func(id: String) -> void: # a new weapon goes into its hand
|
||||
var w := ScarecrowCombat.WEAPON_IDS.find(id)
|
||||
if w > 0:
|
||||
combat.equip(w))
|
||||
|
|
|
|||
|
|
@ -202,6 +202,8 @@ func to_menu() -> void:
|
|||
if sim.coop.is_client():
|
||||
_leave_as_partner("")
|
||||
return
|
||||
if sim.local_frozen:
|
||||
sim.freeze_local(false) # the co-op pause menu's freeze (resume() never runs from here)
|
||||
sim.coop.stop()
|
||||
lobby.leave()
|
||||
var c := sim.campaign
|
||||
|
|
|
|||
|
|
@ -8,20 +8,28 @@ extends RefCounted
|
|||
## kit classes (Scarecrow, Interactions, ScarecrowCombat) read this instead of the local Input
|
||||
## when their remote is set.
|
||||
|
||||
const ACTIONS: Array[StringName] = [&"fire", &"fear", &"patch", &"interact"]
|
||||
const ACTIONS: Array[StringName] = [&"fire", &"fear", &"patch", &"interact", &"offhand"]
|
||||
|
||||
var aim := Vector2(0.0, -1.0)
|
||||
var aim_point := Vector3.ZERO
|
||||
var ground_point := Vector3.ZERO
|
||||
## ScarecrowCombat.Device of the partner's aim, and its ScarecrowCombat.Weapon (-1: none said).
|
||||
## ScarecrowCombat.Device of the partner's aim, and its main ScarecrowCombat.Weapon (-1: none
|
||||
## said).
|
||||
var device: int = 0
|
||||
var weapon: int = -1
|
||||
var build_active := false
|
||||
var ui_open := false
|
||||
|
||||
var _held := 0
|
||||
var _presses := PackedInt32Array([0, 0, 0, 0])
|
||||
var _seen := PackedInt32Array([0, 0, 0, 0])
|
||||
var _presses := RemoteControls.counts()
|
||||
var _seen := RemoteControls.counts()
|
||||
|
||||
|
||||
## A count per action, all 0.
|
||||
static func counts() -> PackedInt32Array:
|
||||
var c := PackedInt32Array()
|
||||
c.resize(ACTIONS.size())
|
||||
return c
|
||||
|
||||
|
||||
func held(action: StringName) -> bool:
|
||||
|
|
@ -63,8 +71,8 @@ func release() -> void:
|
|||
|
||||
## The local side: an input record for the actions held now and every press so far.
|
||||
class Sender:
|
||||
var presses := PackedInt32Array([0, 0, 0, 0])
|
||||
var _was := PackedInt32Array([0, 0, 0, 0])
|
||||
var presses := RemoteControls.counts()
|
||||
var _was := RemoteControls.counts()
|
||||
|
||||
## Counts presses from input events (taps between two frames still count).
|
||||
func note(event: InputEvent) -> void:
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ func refresh() -> void:
|
|||
_title.text = "The farmers are away"
|
||||
lines.append("Keep the farm safe for %d nights until they come home: the crops, the animals in the pen, and the supplies in the shed." % nights)
|
||||
lines.append("By day, gather wood, scrap, and straw (hold E), store them at the barn, and build defenses (B). There's more to gather off the farm, to the north, east, and south.")
|
||||
lines.append("At night, stab thieves with your pitchfork (left mouse), scare them off (Q), and pick up anything they drop. A dropped animal runs off: walk up to it and lead it back to the pen. The workbench sells a corn shooter and pumpkin bombs (switch weapons with Tab or 1-3).")
|
||||
lines.append("At night, stab thieves with your pitchfork (left mouse), scare them off (Q), and pick up anything they drop. A dropped animal runs off: walk up to it and lead it back to the pen. The workbench sells a corn shooter (switch weapons with Tab or 1-2) and pumpkin bombs (throw them with right mouse).")
|
||||
else:
|
||||
var e: Dictionary = s.night_log[s.night_log.size() - 1]
|
||||
_title.text = "Morning of day %d of %d" % [s.night, nights]
|
||||
|
|
|
|||
|
|
@ -2,17 +2,24 @@ class_name ScarecrowCombat
|
|||
extends Node3D
|
||||
## The scarecrow's weapons, ported from the prototype's PlayerInput + WeaponController (Step 4
|
||||
## finished the kit; the weapons came after Step 11):
|
||||
## * Three weapons (Weapon): the pitchfork, every scarecrow's from the start; the corn shooter
|
||||
## and pumpkin bombs, bought at the workbench (Upgrades "corn_shooter", "pumpkin_bomb").
|
||||
## weapon_next (Tab / d-pad down) cycles through the ones owned, weapon_1..3 (1-3) pick one,
|
||||
## both only outside build mode (where those keys pick structures) and with no menu open.
|
||||
## One no longer owned (a retry from before it was bought) goes back to the pitchfork.
|
||||
## * Three weapons (Weapon) in two slots: the main weapon in the right hand, the pitchfork
|
||||
## (every scarecrow's from the start) or the corn shooter, and pumpkin bombs in the off-hand
|
||||
## (the left); the corn shooter and the bombs are bought at the workbench (Upgrades
|
||||
## "corn_shooter", "pumpkin_bomb"). weapon_next (Tab / d-pad down) cycles through the main
|
||||
## weapons owned, weapon_1..2 (1-2) pick one, both only outside build mode (where those keys
|
||||
## pick structures) and with no menu open. The off-hand holds the off-hand weapon owned
|
||||
## (OFFHAND_WEAPONS; there's no pick while there's only one). A main weapon no longer owned (a
|
||||
## retry from before it was bought) goes back to the pitchfork, an off-hand one out of the hand.
|
||||
## * Aim with the mouse (the cursor projected onto the combat-height plane through the follow
|
||||
## camera, corrected for the gun's side offset so shots pass through the cursor; bombs land
|
||||
## on the ground point under the cursor) or the right stick (camera-relative, radial dead
|
||||
## zone, last aim kept). The active device switches only on deliberate input: mouse travel
|
||||
## past a threshold or a click, stick deflection past the dead zone or the trigger.
|
||||
## * Attack with the fire action, needing a fresh press after every reset; holding it repeats:
|
||||
## * Attack with the main weapon with fire (LMB / RT), and use the off-hand with offhand
|
||||
## (RMB / LT), each on its own, both at once too. Each needs a fresh press after every reset
|
||||
## (FarmSim resets on entering and leaving build mode, where the right mouse button is cancel),
|
||||
## and offhand also after any tick the scarecrow couldn't attack (a menu open, patching; in
|
||||
## co-op the partner's build mode, which its own machine toggles). Holding either repeats:
|
||||
## pitchfork a stab every pitchfork_interval: the nearest pitchfork_targets enemies
|
||||
## within pitchfork_reach and pitchfork_arc of the aim, with a clear line,
|
||||
## take pitchfork_damage
|
||||
|
|
@ -21,12 +28,13 @@ extends Node3D
|
|||
## pumpkin bomb one every bomb_cooldown, thrown at the aim point (bomb_min_range ..
|
||||
## bomb_range away; GAMEPAD_THROW ahead with the stick), bursting where it
|
||||
## lands (PumpkinBombs)
|
||||
## * The weapon in hand on the scarecrow's model (WeaponModels), and an aim marker (with bombs:
|
||||
## on the ground where one would land, ringed by its blast).
|
||||
## * Both weapons on the scarecrow's model (WeaponModels), an aim marker, and while a pumpkin
|
||||
## bomb is ready a ring on the ground where one would land, as wide as its blast.
|
||||
## While attacking, the model faces the aim.
|
||||
## Co-op: the partner's weapons on the host read its RemoteControls (aim, fire, and its pick of
|
||||
## weapon come from the partner's game); on the partner's machine its own only aims and shows the
|
||||
## attack motions (replica: the host attacks), and only the local player's aim marker shows.
|
||||
## Co-op: the partner's weapons on the host read its RemoteControls (aim, fire and offhand, and
|
||||
## its pick of main weapon come from the partner's game); on the partner's machine its own only
|
||||
## aims and shows the attack motions (replica: the host attacks), and only the local player's aim
|
||||
## marker shows.
|
||||
|
||||
enum Device { MOUSE, GAMEPAD }
|
||||
enum Weapon { PITCHFORK, CORN_SHOOTER, PUMPKIN_BOMB }
|
||||
|
|
@ -38,7 +46,8 @@ signal stabbed(hits: int)
|
|||
signal struck(at: Vector3, enemy_type: int)
|
||||
## A pumpkin bomb thrown (where it will land).
|
||||
signal threw(at: Vector3)
|
||||
## Any attack (co-op: the partner's machine shows its motion), and a change of weapon.
|
||||
## Any attack, with either hand (co-op: the partner's machine shows its motion), and a change of
|
||||
## main weapon.
|
||||
signal attacked(weapon: Weapon)
|
||||
signal switched(weapon: Weapon)
|
||||
|
||||
|
|
@ -47,14 +56,23 @@ const SIDE_OFFSET := 0.35
|
|||
## Upgrade ids that unlock the weapons (the pitchfork needs none), and what they're called.
|
||||
const WEAPON_IDS: Array[String] = ["pitchfork", "corn_shooter", "pumpkin_bomb"]
|
||||
const WEAPON_NAMES: Array[String] = ["Pitchfork", "Corn shooter", "Pumpkin bombs"]
|
||||
const SWITCH_ACTIONS: Array[StringName] = [&"weapon_next", &"weapon_1", &"weapon_2", &"weapon_3"]
|
||||
## The main weapons (Weapon), in the order weapon_next cycles and weapon_1.. pick them, and the
|
||||
## off-hand ones.
|
||||
const MAIN_WEAPONS: Array[int] = [Weapon.PITCHFORK, Weapon.CORN_SHOOTER]
|
||||
const OFFHAND_WEAPONS: Array[int] = [Weapon.PUMPKIN_BOMB]
|
||||
const SWITCH_ACTIONS: Array[StringName] = [&"weapon_next", &"weapon_1", &"weapon_2"]
|
||||
## How far ahead a bomb lands when aiming with the stick, and how high it leaves the hand.
|
||||
const GAMEPAD_THROW := 7.0
|
||||
const THROW_HEIGHT := 1.6
|
||||
## Opacity of the bomb's landing ring, and while offhand is held.
|
||||
const BLAST_ALPHA := 0.45
|
||||
const BLAST_HELD_ALPHA := 0.9
|
||||
const WORLD_LAYER := 1
|
||||
|
||||
var device: Device = Device.MOUSE
|
||||
## The main weapon, and the off-hand one (-1: none owned).
|
||||
var weapon: Weapon = Weapon.PITCHFORK
|
||||
var offhand: int = -1
|
||||
## Last valid horizontal aim direction (unit, XZ).
|
||||
var aim := Vector2(0.0, -1.0)
|
||||
## World point the mouse aims at (combat-height plane), and the ground point under the cursor;
|
||||
|
|
@ -86,6 +104,10 @@ var _blast: MeshInstance3D
|
|||
## through switches so swapping weapons can't skip a wait.
|
||||
var _cooldown := PackedInt32Array([0, 0, 0])
|
||||
var _needs_release := true
|
||||
var _offhand_needs_release := true
|
||||
## Ticks so far (tick), and the last one the scarecrow could attack in (step).
|
||||
var _ticks: int = 0
|
||||
var _stepped: int = 0
|
||||
var _mouse_travel: float = 0.0
|
||||
var _edges := ActionEdges.new()
|
||||
var _ray := PhysicsRayQueryParameters3D.new()
|
||||
|
|
@ -104,10 +126,12 @@ func setup(cfg: GameConfig, player: PlayerCharacter, camera: Camera3D, shots: Fa
|
|||
_build_marker()
|
||||
|
||||
|
||||
## Requires a fresh fire press, so a held button can't fire into a new morning or a retry.
|
||||
## Requires fresh fire and offhand presses, so a held button can't attack into a new morning or a
|
||||
## retry.
|
||||
func reset() -> void:
|
||||
_cooldown.fill(0)
|
||||
_needs_release = true
|
||||
_offhand_needs_release = true
|
||||
|
||||
|
||||
## A new morning (also after a retry): a pumpkin bomb back in hand.
|
||||
|
|
@ -116,6 +140,11 @@ func ready_for_morning() -> void:
|
|||
bomb_left = 0.0
|
||||
|
||||
|
||||
## Whether the weapon goes in the off-hand rather than the hand.
|
||||
static func is_offhand(w: int) -> bool:
|
||||
return OFFHAND_WEAPONS.has(w)
|
||||
|
||||
|
||||
## Whether this scarecrow has the weapon: the pitchfork always, the others once bought.
|
||||
func owns(w: int) -> bool:
|
||||
if w == Weapon.PITCHFORK:
|
||||
|
|
@ -123,27 +152,33 @@ func owns(w: int) -> bool:
|
|||
return w > 0 and w < WEAPON_IDS.size() and campaign != null and Upgrades.owned(campaign.state, WEAPON_IDS[w])
|
||||
|
||||
|
||||
## Takes the weapon in hand if it's owned. Returns whether it's in hand now.
|
||||
## Takes the weapon up if it's owned: a main weapon into the hand, an off-hand one into the
|
||||
## off-hand. Returns whether it's there now.
|
||||
func equip(w: int) -> bool:
|
||||
if not owns(w):
|
||||
return false
|
||||
if w != weapon:
|
||||
if is_offhand(w):
|
||||
_set_offhand(w)
|
||||
elif w != weapon:
|
||||
show_weapon(w)
|
||||
switched.emit(weapon)
|
||||
return true
|
||||
|
||||
|
||||
## The next weapon owned after the one in hand.
|
||||
## The next main weapon owned after the one in hand.
|
||||
func cycle() -> void:
|
||||
for k in range(1, WEAPON_IDS.size()):
|
||||
if equip((weapon + k) % WEAPON_IDS.size()):
|
||||
var at := MAIN_WEAPONS.find(weapon)
|
||||
for k in range(1, MAIN_WEAPONS.size()):
|
||||
if equip(MAIN_WEAPONS[(at + k) % MAIN_WEAPONS.size()]):
|
||||
return
|
||||
|
||||
|
||||
## Shows the weapon in hand without the ownership check (co-op: the other scarecrow's, as its
|
||||
## machine says).
|
||||
## Shows the main weapon in hand without the ownership check (co-op: the other scarecrow's, as
|
||||
## its machine says). An off-hand weapon doesn't go into the hand.
|
||||
func show_weapon(w: int) -> void:
|
||||
var next := clampi(w, 0, WEAPON_IDS.size() - 1) as Weapon
|
||||
if not MAIN_WEAPONS.has(w):
|
||||
return
|
||||
var next := w as Weapon
|
||||
if next == weapon and models.weapon == next:
|
||||
return # (a snapshot saying so again mustn't cut an attack's motion short)
|
||||
weapon = next
|
||||
|
|
@ -165,18 +200,24 @@ func _input(event: InputEvent) -> void:
|
|||
_to_gamepad()
|
||||
elif event is InputEventJoypadMotion:
|
||||
var jm := event as InputEventJoypadMotion
|
||||
if jm.axis == JOY_AXIS_TRIGGER_RIGHT and jm.axis_value > 0.5:
|
||||
if (jm.axis == JOY_AXIS_TRIGGER_RIGHT or jm.axis == JOY_AXIS_TRIGGER_LEFT) and jm.axis_value > 0.5:
|
||||
_to_gamepad()
|
||||
|
||||
|
||||
## Every tick, attacking or not (building, patching): the bomb's recharge, and the pick of
|
||||
## weapon (the switch actions count only when can_switch: outside build mode, no menu open; the
|
||||
## partner's pick comes from its game).
|
||||
## Every tick, attacking or not (building, patching): the bomb's recharge, the off-hand weapon,
|
||||
## and the pick of main weapon (the switch actions count only when can_switch: outside build
|
||||
## mode, no menu open; the partner's pick comes from its game).
|
||||
func tick(dt: float, can_switch: bool) -> void:
|
||||
_ticks += 1
|
||||
bomb_left = maxf(bomb_left - dt, 0.0)
|
||||
models.set_bomb_charge(1.0 - bomb_left / _cfg.bomb_cooldown if _cfg.bomb_cooldown > 0.0 else 1.0)
|
||||
if not owns(weapon):
|
||||
equip(Weapon.PITCHFORK)
|
||||
if not owns(offhand):
|
||||
_set_offhand(-1)
|
||||
for w in OFFHAND_WEAPONS:
|
||||
if equip(w):
|
||||
break
|
||||
if remote != null:
|
||||
if remote.weapon >= 0:
|
||||
equip(remote.weapon)
|
||||
|
|
@ -188,64 +229,63 @@ func tick(dt: float, can_switch: bool) -> void:
|
|||
return
|
||||
if p[&"weapon_next"]:
|
||||
cycle()
|
||||
for k in WEAPON_IDS.size():
|
||||
for k in MAIN_WEAPONS.size():
|
||||
if p[SWITCH_ACTIONS[k + 1]]:
|
||||
equip(k)
|
||||
equip(MAIN_WEAPONS[k])
|
||||
|
||||
|
||||
## One physics tick while the scarecrow can attack: update the aim, then attack with the weapon
|
||||
## in hand if fire is held and it's ready.
|
||||
## One physics tick while the scarecrow can attack: update the aim, then attack with the main
|
||||
## weapon if fire is held, and use the off-hand one if offhand is held, each if it's ready.
|
||||
func step(_dt: float) -> void:
|
||||
_update_aim()
|
||||
var held := remote.held(&"fire") if remote != null else Input.is_action_pressed("fire")
|
||||
var held := _held(&"fire")
|
||||
var off_held := _held(&"offhand")
|
||||
for i in _cooldown.size():
|
||||
_cooldown[i] = maxi(_cooldown[i] - 1, 0)
|
||||
if _ticks - _stepped > 1:
|
||||
_offhand_needs_release = true # couldn't attack last tick (a menu, the partner's build mode)
|
||||
_stepped = _ticks
|
||||
if replica:
|
||||
if held:
|
||||
_player.face_aim(aim, 0.35)
|
||||
_show_attack()
|
||||
return
|
||||
if _needs_release:
|
||||
if held:
|
||||
return
|
||||
if _needs_release and not held:
|
||||
_needs_release = false
|
||||
if not held:
|
||||
return
|
||||
_player.face_aim(aim, 0.35)
|
||||
attack()
|
||||
if _offhand_needs_release and not off_held:
|
||||
_offhand_needs_release = false
|
||||
if off_held and not _offhand_needs_release:
|
||||
_player.face_aim(aim, 0.35)
|
||||
use_offhand()
|
||||
if held and not _needs_release:
|
||||
_player.face_aim(aim, 0.35)
|
||||
attack()
|
||||
|
||||
|
||||
## The weapon in hand attacks along the aim, if it's ready. Returns whether it did.
|
||||
## The main weapon attacks along the aim, if it's ready. Returns whether it did.
|
||||
func attack() -> bool:
|
||||
if _cooldown[weapon] > 0:
|
||||
return false
|
||||
match weapon:
|
||||
Weapon.CORN_SHOOTER:
|
||||
_cooldown[weapon] = interval_ticks()
|
||||
_shoot()
|
||||
Weapon.PUMPKIN_BOMB:
|
||||
if bomb_left > 0.0 or not _throw():
|
||||
return false
|
||||
_:
|
||||
_cooldown[weapon] = stab_ticks()
|
||||
_stab()
|
||||
attacked.emit(weapon)
|
||||
return true
|
||||
return _use(weapon)
|
||||
|
||||
|
||||
## A scripted attack (the soak's scarecrow, tests): aims at target and attacks if ready.
|
||||
## The off-hand weapon is used (a pumpkin bomb thrown at the aim point), if one is ready.
|
||||
## Returns whether it was.
|
||||
func use_offhand() -> bool:
|
||||
return offhand >= 0 and _use(offhand)
|
||||
|
||||
|
||||
## A scripted attack (the soak's scarecrow, tests): aims at target and attacks with the main
|
||||
## weapon if it's ready.
|
||||
func attack_toward(target: Vector2) -> bool:
|
||||
var p := Vector2(_player.global_position.x, _player.global_position.z)
|
||||
var to := target - p
|
||||
if to.length() > 1e-3:
|
||||
aim = PlayerInput.muzzle_corrected_aim(to, to.normalized()) if weapon == Weapon.CORN_SHOOTER else to.normalized()
|
||||
aim_point = Vector3(target.x, _cfg.combat_height, target.y)
|
||||
ground_point = Vector3(target.x, 0.0, target.y)
|
||||
device = Device.MOUSE
|
||||
_player.face_aim(aim, 0.35)
|
||||
_aim_at(target, weapon == Weapon.CORN_SHOOTER)
|
||||
return attack()
|
||||
|
||||
|
||||
## The same with the off-hand weapon (a pumpkin bomb thrown at target).
|
||||
func offhand_toward(target: Vector2) -> bool:
|
||||
_aim_at(target, false)
|
||||
return use_offhand()
|
||||
|
||||
|
||||
## Attacks so far, with any weapon.
|
||||
func attacks() -> int:
|
||||
return stabs + shots_fired + bombs_thrown
|
||||
|
|
@ -276,6 +316,44 @@ func throw_target() -> Vector3:
|
|||
return Vector3(at.x, 0.0, at.y)
|
||||
|
||||
|
||||
func _held(action: StringName) -> bool:
|
||||
return remote.held(action) if remote != null else Input.is_action_pressed(action)
|
||||
|
||||
|
||||
func _use(w: int) -> bool:
|
||||
if _cooldown[w] > 0:
|
||||
return false
|
||||
match w:
|
||||
Weapon.CORN_SHOOTER:
|
||||
_cooldown[w] = interval_ticks()
|
||||
_shoot()
|
||||
Weapon.PUMPKIN_BOMB:
|
||||
if bomb_left > 0.0 or not _throw():
|
||||
return false
|
||||
_:
|
||||
_cooldown[w] = stab_ticks()
|
||||
_stab()
|
||||
attacked.emit(w)
|
||||
return true
|
||||
|
||||
|
||||
func _set_offhand(w: int) -> void:
|
||||
if w != offhand:
|
||||
offhand = w
|
||||
models.show_offhand(w)
|
||||
|
||||
|
||||
func _aim_at(target: Vector2, from_muzzle: bool) -> void:
|
||||
var p := Vector2(_player.global_position.x, _player.global_position.z)
|
||||
var to := target - p
|
||||
if to.length() > 1e-3:
|
||||
aim = PlayerInput.muzzle_corrected_aim(to, to.normalized()) if from_muzzle else to.normalized()
|
||||
aim_point = Vector3(target.x, _cfg.combat_height, target.y)
|
||||
ground_point = Vector3(target.x, 0.0, target.y)
|
||||
device = Device.MOUSE
|
||||
_player.face_aim(aim, 0.35)
|
||||
|
||||
|
||||
func _shoot() -> void:
|
||||
var origin := Vector3(_player.global_position.x, _cfg.combat_height, _player.global_position.z)
|
||||
var dir := Vector3(aim.x, 0.0, aim.y)
|
||||
|
|
@ -324,7 +402,7 @@ func _throw() -> bool:
|
|||
if bombs == null:
|
||||
return false
|
||||
var p := _player.global_position
|
||||
var hand := Vector3(p.x - aim.y * 0.4, THROW_HEIGHT, p.z + aim.x * 0.4)
|
||||
var hand := Vector3(p.x + aim.y * 0.4, THROW_HEIGHT, p.z - aim.x * 0.4) # the left
|
||||
var to := throw_target()
|
||||
if not bombs.throw(hand, to, _cfg.bomb_damage, _cfg.bomb_radius):
|
||||
return false
|
||||
|
|
@ -335,10 +413,11 @@ func _throw() -> bool:
|
|||
return true
|
||||
|
||||
|
||||
## The partner's machine: the attack motion on the weapon's own cadence (the host attacks).
|
||||
## The partner's machine: the main weapon's attack motion on its own cadence (the host attacks;
|
||||
## its throws show the bomb, and empty the off-hand).
|
||||
func _show_attack() -> void:
|
||||
if weapon == Weapon.PUMPKIN_BOMB or _cooldown[weapon] > 0:
|
||||
return # the host's throw shows the bomb, and empties the hand
|
||||
if _cooldown[weapon] > 0:
|
||||
return
|
||||
_cooldown[weapon] = interval_ticks() if weapon == Weapon.CORN_SHOOTER else stab_ticks()
|
||||
models.attack(weapon)
|
||||
|
||||
|
|
@ -390,24 +469,26 @@ func _to_gamepad() -> void:
|
|||
func _process(_delta: float) -> void:
|
||||
if _player == null:
|
||||
return
|
||||
var bomb := weapon == Weapon.PUMPKIN_BOMB
|
||||
_marker.visible = show_marker
|
||||
_blast.visible = show_marker and bomb
|
||||
if bomb:
|
||||
var at := throw_target()
|
||||
_marker.global_position = Vector3(at.x, 0.12, at.z)
|
||||
_blast.global_position = Vector3(at.x, 0.1, at.z)
|
||||
elif device == Device.MOUSE:
|
||||
if device == Device.MOUSE:
|
||||
_marker.global_position = Vector3(aim_point.x, _cfg.combat_height, aim_point.z)
|
||||
else:
|
||||
var p := _player.get_global_transform_interpolated().origin
|
||||
_marker.global_position = Vector3(p.x + aim.x * 3.0, _cfg.combat_height, p.z + aim.y * 3.0)
|
||||
# A pumpkin bomb ready in the off-hand: where it would land, brighter while offhand is held.
|
||||
var bomb := offhand == Weapon.PUMPKIN_BOMB and bomb_left == 0.0
|
||||
_blast.visible = show_marker and bomb
|
||||
if _blast.visible:
|
||||
var at := throw_target()
|
||||
_blast.global_position = Vector3(at.x, 0.1, at.z)
|
||||
var held := remote == null and Input.is_action_pressed("offhand")
|
||||
(_blast.material_override as StandardMaterial3D).albedo_color.a = BLAST_HELD_ALPHA if held else BLAST_ALPHA
|
||||
|
||||
|
||||
func _build_marker() -> void:
|
||||
_marker = _ring(0.2, 0.3, Color(1.0, 0.85, 0.25))
|
||||
_marker.name = "AimMarker"
|
||||
_blast = _ring(_cfg.bomb_radius - 0.08, _cfg.bomb_radius, Color(1.0, 0.55, 0.12, 0.8))
|
||||
_blast = _ring(_cfg.bomb_radius - 0.08, _cfg.bomb_radius, Color(1.0, 0.55, 0.12, BLAST_ALPHA))
|
||||
_blast.name = "BlastMarker"
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,17 +4,19 @@ extends Control
|
|||
## sweeps full while it cools down and flashes when it is ready again, the patch hint with its
|
||||
## progress, and once the Sprint upgrade is bought a sprint line (ready, seconds left, or
|
||||
## recharging); plus a red screen tint when the scarecrow is hit. Bottom-right, the weapons:
|
||||
## the three by number, the one in hand marked, the ones not bought yet greyed out (from the
|
||||
## workbench), the pumpkin bomb's recharge, and how to switch.
|
||||
## the main ones by number, the one in hand marked, and how to switch; under them the off-hand
|
||||
## (pumpkin bombs, marked when one is ready, else its recharge) and its button. The ones not
|
||||
## bought yet are greyed out (from the workbench).
|
||||
|
||||
const PIP := Vector2(22.0, 16.0)
|
||||
const PIP_GAP := 5.0
|
||||
const FEAR_RADIUS := 26.0
|
||||
## Extra height of the panel for the sprint line.
|
||||
const SPRINT_ROW := 30.0
|
||||
## The weapon panel, from the bottom-right corner, and its rows.
|
||||
const WEAPONS := Rect2(-340.0, -176.0, 304.0, 150.0)
|
||||
## The weapon panel, from the bottom-right corner, its rows, and where its off-hand part starts.
|
||||
const WEAPONS := Rect2(-340.0, -220.0, 304.0, 194.0)
|
||||
const WEAPON_ROW := 30.0
|
||||
const OFFHAND_TOP := 122.0
|
||||
|
||||
var kit: Scarecrow
|
||||
## This machine's scarecrow's weapons.
|
||||
|
|
@ -31,6 +33,8 @@ var _sprint_label: Label
|
|||
var _weapon_title: Label
|
||||
var _weapon_rows: Array[Label] = []
|
||||
var _weapon_hint: Label
|
||||
var _offhand_title: Label
|
||||
var _offhand_rows: Array[Label] = []
|
||||
var _hit: float = 0.0
|
||||
var _ready_flash: float = 0.0
|
||||
|
||||
|
|
@ -72,11 +76,15 @@ func _ready() -> void:
|
|||
_patch_label = _label(20)
|
||||
_sprint_label = _label(20)
|
||||
_weapon_title = _label(18)
|
||||
_weapon_title.text = "Weapon"
|
||||
for i in ScarecrowCombat.WEAPON_NAMES.size():
|
||||
_weapon_title.text = "Main weapon"
|
||||
for i in ScarecrowCombat.MAIN_WEAPONS.size():
|
||||
_weapon_rows.append(_label(20))
|
||||
_weapon_hint = _label(16)
|
||||
_weapon_hint.text = "Switch: Tab / 1-3 / d-pad down"
|
||||
_weapon_hint.text = "Switch: Tab / 1-2 / d-pad down"
|
||||
_offhand_title = _label(18)
|
||||
_offhand_title.text = "Off-hand right mouse / LT"
|
||||
for i in ScarecrowCombat.OFFHAND_WEAPONS.size():
|
||||
_offhand_rows.append(_label(20))
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
|
|
@ -123,29 +131,42 @@ func _process(delta: float) -> void:
|
|||
|
||||
func _update_weapons() -> void:
|
||||
var shown := combat != null
|
||||
_weapon_title.visible = shown
|
||||
_weapon_hint.visible = shown
|
||||
for l in _weapon_rows:
|
||||
for l: Label in [_weapon_title, _weapon_hint, _offhand_title] + _weapon_rows + _offhand_rows:
|
||||
l.visible = shown
|
||||
if not shown:
|
||||
return
|
||||
var at := _weapons_rect().position
|
||||
_weapon_title.position = at + Vector2(12.0, 6.0)
|
||||
for i in _weapon_rows.size():
|
||||
var l := _weapon_rows[i]
|
||||
var text := "%d %s" % [i + 1, ScarecrowCombat.WEAPON_NAMES[i]]
|
||||
var color := Color(0.95, 0.95, 0.95)
|
||||
if not combat.owns(i):
|
||||
text += " (workbench)"
|
||||
color = Color(0.55, 0.55, 0.55)
|
||||
elif i == ScarecrowCombat.Weapon.PUMPKIN_BOMB and combat.bomb_left > 0.0:
|
||||
text += " %.0f s" % ceilf(combat.bomb_left)
|
||||
if i == combat.weapon:
|
||||
color = Color(1.0, 0.85, 0.3)
|
||||
l.text = text
|
||||
l.add_theme_color_override("font_color", color)
|
||||
l.position = at + Vector2(30.0, 30.0 + i * WEAPON_ROW)
|
||||
for k in _weapon_rows.size():
|
||||
var w := ScarecrowCombat.MAIN_WEAPONS[k]
|
||||
_weapon_row(_weapon_rows[k], "%d %s" % [k + 1, ScarecrowCombat.WEAPON_NAMES[w]], w, w == combat.weapon)
|
||||
_weapon_rows[k].position = at + Vector2(30.0, 30.0 + k * WEAPON_ROW)
|
||||
_weapon_hint.position = at + Vector2(12.0, 30.0 + _weapon_rows.size() * WEAPON_ROW + 2.0)
|
||||
_offhand_title.position = at + Vector2(12.0, OFFHAND_TOP + 6.0)
|
||||
for k in _offhand_rows.size():
|
||||
var w := ScarecrowCombat.OFFHAND_WEAPONS[k]
|
||||
var text := ScarecrowCombat.WEAPON_NAMES[w]
|
||||
if w == ScarecrowCombat.Weapon.PUMPKIN_BOMB and combat.owns(w) and combat.bomb_left > 0.0:
|
||||
text += " %.0f s" % ceilf(combat.bomb_left)
|
||||
_weapon_row(_offhand_rows[k], text, w, _offhand_lit(w))
|
||||
_offhand_rows[k].position = at + Vector2(30.0, OFFHAND_TOP + 30.0 + k * WEAPON_ROW)
|
||||
|
||||
|
||||
## A weapon's row: greyed out until it's bought, gold when it's in hand (lit).
|
||||
func _weapon_row(l: Label, text: String, w: int, lit: bool) -> void:
|
||||
var color := Color(0.95, 0.95, 0.95)
|
||||
if not combat.owns(w):
|
||||
text += " (workbench)"
|
||||
color = Color(0.55, 0.55, 0.55)
|
||||
elif lit:
|
||||
color = Color(1.0, 0.85, 0.3)
|
||||
l.text = text
|
||||
l.add_theme_color_override("font_color", color)
|
||||
|
||||
|
||||
## Whether the off-hand weapon is in the off-hand and ready (a pumpkin bomb not recharging).
|
||||
func _offhand_lit(w: int) -> bool:
|
||||
return w == combat.offhand and not (w == ScarecrowCombat.Weapon.PUMPKIN_BOMB and combat.bomb_left > 0.0)
|
||||
|
||||
|
||||
func _weapons_rect() -> Rect2:
|
||||
|
|
@ -178,15 +199,23 @@ func _draw() -> void:
|
|||
if combat != null:
|
||||
var w := _weapons_rect()
|
||||
draw_rect(w, Color(0.0, 0.0, 0.0, 0.42))
|
||||
var row := Rect2(w.position + Vector2(6.0, 32.0 + combat.weapon * WEAPON_ROW), Vector2(w.size.x - 12.0, WEAPON_ROW - 2.0))
|
||||
draw_rect(row, Color(1.0, 0.85, 0.3, 0.18))
|
||||
draw_rect(Rect2(row.position, Vector2(4.0, row.size.y)), Color(1.0, 0.85, 0.3))
|
||||
_draw_lit_row(w, 32.0 + ScarecrowCombat.MAIN_WEAPONS.find(combat.weapon) * WEAPON_ROW)
|
||||
var off := ScarecrowCombat.OFFHAND_WEAPONS.find(combat.offhand)
|
||||
if off >= 0 and _offhand_lit(combat.offhand):
|
||||
_draw_lit_row(w, OFFHAND_TOP + 32.0 + off * WEAPON_ROW)
|
||||
if kit.patching:
|
||||
var bar := Rect2(base + Vector2(FEAR_RADIUS * 2.0 + 14.0, 92.0), Vector2(210.0, 8.0))
|
||||
draw_rect(bar, Color(0.1, 0.1, 0.1, 0.9))
|
||||
draw_rect(Rect2(bar.position, Vector2(bar.size.x * kit.patch_elapsed / kit.config.patch_time, bar.size.y)), Color(0.45, 1.0, 0.4))
|
||||
|
||||
|
||||
## The marked row of the weapon panel w, top pixels down.
|
||||
func _draw_lit_row(w: Rect2, top: float) -> void:
|
||||
var row := Rect2(w.position + Vector2(6.0, top), Vector2(w.size.x - 12.0, WEAPON_ROW - 2.0))
|
||||
draw_rect(row, Color(1.0, 0.85, 0.3, 0.18))
|
||||
draw_rect(Rect2(row.position, Vector2(4.0, row.size.y)), Color(1.0, 0.85, 0.3))
|
||||
|
||||
|
||||
func _base() -> Vector2:
|
||||
return Vector2(36.0, size.y - 126.0 - (SPRINT_ROW if _sprint_shown() else 0.0))
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@ signal closed
|
|||
const BINDINGS := [
|
||||
["Move", []],
|
||||
["Aim", []],
|
||||
["Shoot", ["fire"]],
|
||||
["Attack (main weapon)", ["fire"]],
|
||||
["Throw a pumpkin bomb (off-hand)", ["offhand"]],
|
||||
["Switch main weapon", ["weapon_1", "weapon_2", "weapon_next"]],
|
||||
["Fear", ["fear"]],
|
||||
["Patch up (hold)", ["patch"]],
|
||||
["Gather / repair / workbench", ["interact"]],
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ const TEXT := {
|
|||
"store": "Your pouch only holds so much: walk onto the barn's apron (the Supply Shed) to store what you carry.",
|
||||
"build": "Press [B / d-pad up] to build. Pick a fence [1], place it with left mouse / RT. Thieves have to break through fences.",
|
||||
"dusk": "Dusk: thieves come at nightfall, from every side of the farm.",
|
||||
"shoot": "Aim with the mouse or the right stick and hold left mouse / RT to stab with your pitchfork. The workbench sells a corn shooter and pumpkin bombs: switch with [Tab / 1-3].",
|
||||
"shoot": "Aim with the mouse or the right stick and hold left mouse / RT to stab with your pitchfork. The workbench sells a corn shooter (switch with [Tab / 1-2]) and pumpkin bombs for your off-hand: throw them with [right mouse / LT].",
|
||||
"fear": "Crowded? [Q / LB] Fear scares off everything nearby, and they drop what they carry.",
|
||||
"recover": "Something was dropped! Walk over it to bring it home. A dropped animal follows you back to the pen.",
|
||||
"patch": "Hurt? Hold [F / Y] to patch up with straw. Health carries over to the next night.",
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
class_name WeaponModels
|
||||
extends Node3D
|
||||
## The scarecrow's weapons as it holds them (ScarecrowCombat), from the models in
|
||||
## assets/weapons/, on the scarecrow's model (which faces -Z), only the one in use showing. The
|
||||
## Blender exports sit far from the origin, so each mesh is re-centered (mesh_of) and posed here:
|
||||
## assets/weapons/, on the scarecrow's model (which faces -Z): the main weapon in use in the
|
||||
## right hand, the off-hand one in the left. The Blender exports sit far from the origin, so each
|
||||
## mesh is re-centered (mesh_of) and posed here:
|
||||
## pitchfork held low like a spear at the right side, tines forward; a stab thrusts it out
|
||||
## corn shooter at the gun's spot, its corn-cob muzzle at the gameplay muzzle point; each shot
|
||||
## kicks it back
|
||||
## pumpkin bomb in the right hand; after a throw the next one grows back in the hand over the
|
||||
## recharge (set_bomb_charge)
|
||||
## pumpkin bomb in the left hand (the off-hand); after a throw the next one grows back in the
|
||||
## hand over the recharge (set_bomb_charge)
|
||||
## attack() plays the weapon's motion (the pumpkin just leaves the hand: the thrown one is
|
||||
## PumpkinBombs').
|
||||
|
||||
|
|
@ -26,6 +27,7 @@ const KICK := 0.09
|
|||
static var _meshes := {}
|
||||
|
||||
var weapon: int = 0
|
||||
var offhand: int = -1
|
||||
var _pivots: Array[Node3D] = []
|
||||
var _rest: Array[Transform3D] = []
|
||||
var _attack_t := -1.0
|
||||
|
|
@ -42,8 +44,8 @@ static func mesh_of(index: int) -> Mesh:
|
|||
return _meshes[index]
|
||||
|
||||
|
||||
## Builds the three under model. muzzle: the gameplay muzzle point on the model (the corn
|
||||
## shooter's tip goes there).
|
||||
## Builds the three under model, the pitchfork in hand and the off-hand empty. muzzle: the
|
||||
## gameplay muzzle point on the model (the corn shooter's tip goes there).
|
||||
func setup(model: Node3D, muzzle: Vector3) -> void:
|
||||
name = "Weapons"
|
||||
model.add_child(self)
|
||||
|
|
@ -52,9 +54,10 @@ func setup(model: Node3D, muzzle: Vector3) -> void:
|
|||
# Corn shooter: its tip (the mesh's +Z end, 0.59 m out) turned forward onto the muzzle point.
|
||||
var tip := 0.589 * SCALES[1]
|
||||
_add(1, Transform3D(Basis.from_euler(Vector3(0.0, PI, 0.0)), muzzle + Vector3(0.0, 0.0, tip)))
|
||||
# Pumpkin: in the right hand, in front.
|
||||
_add(2, Transform3D(Basis.IDENTITY, Vector3(0.42, 1.2, -0.5)))
|
||||
# Pumpkin: in the left hand, in front.
|
||||
_add(2, Transform3D(Basis.IDENTITY, Vector3(-0.42, 1.2, -0.5)))
|
||||
show_weapon(0)
|
||||
show_offhand(-1)
|
||||
|
||||
|
||||
func _add(index: int, rest: Transform3D) -> void:
|
||||
|
|
@ -70,19 +73,25 @@ func _add(index: int, rest: Transform3D) -> void:
|
|||
_rest.append(rest)
|
||||
|
||||
|
||||
## Shows only this weapon (ScarecrowCombat.Weapon).
|
||||
## Shows this main weapon (ScarecrowCombat.Weapon) in the right hand, and no other.
|
||||
func show_weapon(index: int) -> void:
|
||||
weapon = index
|
||||
_attack_t = -1.0
|
||||
for i in _pivots.size():
|
||||
for i in ScarecrowCombat.MAIN_WEAPONS:
|
||||
_pivots[i].visible = i == index
|
||||
_pivots[i].transform = _rest[i]
|
||||
_apply_charge()
|
||||
|
||||
|
||||
## The weapon's attack motion: a stab or a kick.
|
||||
## Shows this off-hand weapon in the left hand (-1: none).
|
||||
func show_offhand(index: int) -> void:
|
||||
offhand = index
|
||||
for i in ScarecrowCombat.OFFHAND_WEAPONS:
|
||||
_pivots[i].visible = i == index
|
||||
|
||||
|
||||
## The main weapon's attack motion: a stab or a kick.
|
||||
func attack(index: int) -> void:
|
||||
if index == weapon and index < 2:
|
||||
if index == weapon:
|
||||
_attack_t = 0.0
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue