Task #7: four new shed weapons (Potato Cannon, Shurikens, Propane Torch, Alien Ray)
All four go in the main hand alongside the pitchfork and corn shooter, cooldown-based with no ammo, every stat GameConfig-tunable: Potato Cannon is a slow heavy shot, Shurikens a fast cheap throw, Propane Torch a sustained cone DoT while held (shares the pitchfork's cone-hit test), and Alien Ray a fast powerful shot that stays hidden in the shop until enough Alien Goop is collected. FarmProjectiles.fire() gained optional speed/lifetime overrides (backward compatible) so each ranged weapon can fly at its own pace. WeaponModels gained tinted placeholder pivots for the new weapons (no new art), and the number-key switch loop and HUD panel layout were fixed to not go out of bounds now that there are more main weapons than number keys. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
b43af8a680
commit
b9dcd24b5d
9 changed files with 399 additions and 62 deletions
|
|
@ -2,14 +2,17 @@ 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) 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.
|
||||
## * Weapons (Weapon) in two slots: the main weapon in the right hand (the pitchfork, every
|
||||
## scarecrow's from the start; or the corn shooter, Potato Cannon, Shurikens, Propane Torch, or
|
||||
## Alien Ray, every one bought at the supply shed, Upgrades.shop_of "shed"), and pumpkin bombs
|
||||
## in the off-hand (the left, also shed-bought). weapon_next (Tab / d-pad down) cycles through
|
||||
## the main weapons owned; weapon_1..2 (1-2) pick the first two only (Task #7 added more main
|
||||
## weapons than there are number keys — the rest are Tab-cycle only), 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. The Alien Ray stays hidden (GameConfig "hidden") until enough
|
||||
## Alien Goop is collected (Upgrades.revealed).
|
||||
## * 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
|
||||
|
|
@ -28,7 +31,16 @@ 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)
|
||||
## * Both weapons on the scarecrow's model (WeaponModels), an aim marker, and while a pumpkin
|
||||
## potato cannon one slow, heavy potato_cannon_damage shot every potato_cannon_cooldown,
|
||||
## through FarmProjectiles at potato_cannon_speed
|
||||
## shurikens shuriken_count shuriken_damage throws every shuriken_cooldown, fast
|
||||
## (shuriken_speed) and cheap
|
||||
## propane torch a torch_damage tick every torch_tick_interval to every enemy within
|
||||
## torch_range and torch_arc of the aim (up to torch_targets), with a clear
|
||||
## line: a sustained cone while held, like the pitchfork's stab
|
||||
## alien ray one fast, powerful alien_ray_damage shot every alien_ray_cooldown, through
|
||||
## FarmProjectiles at alien_ray_speed
|
||||
## * Every weapon's model on the scarecrow (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 offhand, and
|
||||
|
|
@ -37,7 +49,10 @@ extends Node3D
|
|||
## marker shows.
|
||||
|
||||
enum Device { MOUSE, GAMEPAD }
|
||||
enum Weapon { PITCHFORK, CORN_SHOOTER, PUMPKIN_BOMB }
|
||||
## Task #7 added four shed weapons after Pumpkin Bombs: Potato Cannon, Shurikens, and Propane
|
||||
## Torch go straight in MAIN_WEAPONS like the corn shooter; Alien Ray too, but hidden (GameConfig
|
||||
## "hidden") until enough Alien Goop is collected. All four are cooldown-based, no ammo.
|
||||
enum Weapon { PITCHFORK, CORN_SHOOTER, PUMPKIN_BOMB, POTATO_CANNON, SHURIKENS, PROPANE_TORCH, ALIEN_RAY }
|
||||
|
||||
## A corn shot left the gun (for its sound).
|
||||
signal fired
|
||||
|
|
@ -54,13 +69,20 @@ signal switched(weapon: Weapon)
|
|||
## Lateral offset of the gun from the scarecrow's center line (the prototype's value).
|
||||
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"]
|
||||
## 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 WEAPON_IDS: Array[String] = ["pitchfork", "corn_shooter", "pumpkin_bomb", "potato_cannon", "shurikens",
|
||||
"propane_torch", "alien_ray"]
|
||||
const WEAPON_NAMES: Array[String] = ["Pitchfork", "Corn shooter", "Pumpkin bombs", "Potato cannon", "Shurikens",
|
||||
"Propane torch", "Alien ray"]
|
||||
## The main weapons (Weapon), in the order weapon_next cycles them, and the off-hand ones.
|
||||
## weapon_1.. only picks the first SWITCH_ACTIONS.size() - 1 of MAIN_WEAPONS directly (no new
|
||||
## number-key actions were added for Task #7's four); the rest are reached by cycling.
|
||||
const MAIN_WEAPONS: Array[int] = [Weapon.PITCHFORK, Weapon.CORN_SHOOTER, Weapon.POTATO_CANNON, Weapon.SHURIKENS,
|
||||
Weapon.PROPANE_TORCH, Weapon.ALIEN_RAY]
|
||||
const OFFHAND_WEAPONS: Array[int] = [Weapon.PUMPKIN_BOMB]
|
||||
const SWITCH_ACTIONS: Array[StringName] = [&"weapon_next", &"weapon_1", &"weapon_2"]
|
||||
## Main weapons that fire from the muzzle (SIDE_OFFSET/muzzle_distance), so aiming at a target
|
||||
## needs the same muzzle correction as the corn shooter's (attack_toward, the mouse in _update_aim).
|
||||
const MUZZLE_WEAPONS: Array[int] = [Weapon.CORN_SHOOTER, Weapon.POTATO_CANNON, Weapon.SHURIKENS, Weapon.ALIEN_RAY]
|
||||
## 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
|
||||
|
|
@ -82,6 +104,8 @@ var ground_point := Vector3.ZERO
|
|||
var shots_fired: int = 0
|
||||
var stabs: int = 0
|
||||
var bombs_thrown: int = 0
|
||||
## Propane Torch ticks applied (its own count, like stabs/shots_fired/bombs_thrown).
|
||||
var torch_ticks: int = 0
|
||||
## Seconds until the next pumpkin bomb is in hand (0 = ready).
|
||||
var bomb_left: float = 0.0
|
||||
var remote: RemoteControls
|
||||
|
|
@ -101,8 +125,8 @@ var _shots: FarmProjectiles
|
|||
var _marker: MeshInstance3D
|
||||
var _blast: MeshInstance3D
|
||||
## Ticks until each weapon can attack again (the pumpkin bomb's recharge is bomb_left), kept
|
||||
## through switches so swapping weapons can't skip a wait.
|
||||
var _cooldown := PackedInt32Array([0, 0, 0])
|
||||
## through switches so swapping weapons can't skip a wait. One slot per Weapon.
|
||||
var _cooldown := PackedInt32Array([0, 0, 0, 0, 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).
|
||||
|
|
@ -229,7 +253,9 @@ func tick(dt: float, can_switch: bool) -> void:
|
|||
return
|
||||
if p[&"weapon_next"]:
|
||||
cycle()
|
||||
for k in MAIN_WEAPONS.size():
|
||||
# Only the first SWITCH_ACTIONS.size() - 1 main weapons have a number key (Task #7 added more
|
||||
# MAIN_WEAPONS than keys; the rest are Tab-cycle only).
|
||||
for k in mini(MAIN_WEAPONS.size(), SWITCH_ACTIONS.size() - 1):
|
||||
if p[SWITCH_ACTIONS[k + 1]]:
|
||||
equip(MAIN_WEAPONS[k])
|
||||
|
||||
|
|
@ -276,7 +302,7 @@ func use_offhand() -> bool:
|
|||
## 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:
|
||||
_aim_at(target, weapon == Weapon.CORN_SHOOTER)
|
||||
_aim_at(target, MUZZLE_WEAPONS.has(weapon))
|
||||
return attack()
|
||||
|
||||
|
||||
|
|
@ -288,7 +314,7 @@ func offhand_toward(target: Vector2) -> bool:
|
|||
|
||||
## Attacks so far, with any weapon.
|
||||
func attacks() -> int:
|
||||
return stabs + shots_fired + bombs_thrown
|
||||
return stabs + shots_fired + bombs_thrown + torch_ticks
|
||||
|
||||
|
||||
## Ticks between shots, and a shot's damage, with upgrades.
|
||||
|
|
@ -306,6 +332,24 @@ func stab_ticks() -> int:
|
|||
return maxi(1, roundi(_cfg.pitchfork_interval * Engine.physics_ticks_per_second))
|
||||
|
||||
|
||||
## Ticks between Potato Cannon shots, Shurikens throws, Propane Torch DoT ticks, and Alien Ray
|
||||
## shots (each its own cooldown, GameConfig-tunable, no ammo).
|
||||
func potato_ticks() -> int:
|
||||
return maxi(1, roundi(_cfg.potato_cannon_cooldown * Engine.physics_ticks_per_second))
|
||||
|
||||
|
||||
func shuriken_ticks() -> int:
|
||||
return maxi(1, roundi(_cfg.shuriken_cooldown * Engine.physics_ticks_per_second))
|
||||
|
||||
|
||||
func torch_interval_ticks() -> int:
|
||||
return maxi(1, roundi(_cfg.torch_tick_interval * Engine.physics_ticks_per_second))
|
||||
|
||||
|
||||
func alien_ray_ticks() -> int:
|
||||
return maxi(1, roundi(_cfg.alien_ray_cooldown * Engine.physics_ticks_per_second))
|
||||
|
||||
|
||||
## Where a bomb thrown now lands: the ground point aimed at (GAMEPAD_THROW ahead with the stick),
|
||||
## bomb_min_range .. bomb_range from the scarecrow.
|
||||
func throw_target() -> Vector3:
|
||||
|
|
@ -330,6 +374,18 @@ func _use(w: int) -> bool:
|
|||
Weapon.PUMPKIN_BOMB:
|
||||
if bomb_left > 0.0 or not _throw():
|
||||
return false
|
||||
Weapon.POTATO_CANNON:
|
||||
_cooldown[w] = potato_ticks()
|
||||
_shoot_potato()
|
||||
Weapon.SHURIKENS:
|
||||
_cooldown[w] = shuriken_ticks()
|
||||
_throw_shurikens()
|
||||
Weapon.PROPANE_TORCH:
|
||||
_cooldown[w] = torch_interval_ticks()
|
||||
_torch_tick()
|
||||
Weapon.ALIEN_RAY:
|
||||
_cooldown[w] = alien_ray_ticks()
|
||||
_shoot_alien_ray()
|
||||
_:
|
||||
_cooldown[w] = stab_ticks()
|
||||
_stab()
|
||||
|
|
@ -369,35 +425,92 @@ func _shoot() -> void:
|
|||
func _stab() -> int:
|
||||
stabs += 1
|
||||
models.attack(Weapon.PITCHFORK)
|
||||
var hits := 0
|
||||
if enemies != null:
|
||||
var es := enemies
|
||||
var p := Vector2(_player.global_position.x, _player.global_position.z)
|
||||
var cos_half := cos(deg_to_rad(_cfg.pitchfork_arc) * 0.5)
|
||||
var found: Array = [] # [distance, slot]
|
||||
for d in es.active_count:
|
||||
if es.alive[d] == 0:
|
||||
continue
|
||||
var e := Vector2(es.pos_x[d], es.pos_z[d])
|
||||
var dist := e.distance_to(p)
|
||||
if dist > _cfg.pitchfork_reach + es.t_hit_radius[es.type[d]]:
|
||||
continue
|
||||
if dist > 0.3 and (e - p).dot(aim) < cos_half * dist:
|
||||
continue
|
||||
if _clear_line(p, e):
|
||||
found.append([dist, d])
|
||||
found.sort_custom(func(a: Array, b: Array) -> bool: return a[0] < b[0])
|
||||
for k in mini(found.size(), _cfg.pitchfork_targets):
|
||||
var d: int = found[k][1]
|
||||
var at := Vector3(es.pos_x[d], _cfg.combat_height, es.pos_z[d])
|
||||
var type := es.type[d]
|
||||
if es.apply_hit(d, _cfg.pitchfork_damage):
|
||||
hits += 1
|
||||
struck.emit(at, type)
|
||||
var hits := _cone_hit(_cfg.pitchfork_reach, _cfg.pitchfork_arc, _cfg.pitchfork_targets, _cfg.pitchfork_damage)
|
||||
stabbed.emit(hits)
|
||||
return hits
|
||||
|
||||
|
||||
## The Potato Cannon: one slow, heavy kernel through FarmProjectiles (muzzle_distance / SIDE_OFFSET
|
||||
## like the corn shooter, its own speed, lifetime, and damage).
|
||||
func _shoot_potato() -> void:
|
||||
var origin := Vector3(_player.global_position.x, _cfg.combat_height, _player.global_position.z)
|
||||
var dir := Vector3(aim.x, 0.0, aim.y)
|
||||
var right := Vector3(-aim.y, 0.0, aim.x)
|
||||
var muzzle := origin + dir * _cfg.muzzle_distance + right * SIDE_OFFSET
|
||||
shots_fired += 1
|
||||
_shots.fire(origin, muzzle, dir, _cfg.potato_cannon_damage, _cfg.potato_cannon_speed, _cfg.potato_cannon_lifetime)
|
||||
models.attack(Weapon.POTATO_CANNON)
|
||||
fired.emit()
|
||||
|
||||
|
||||
## The Alien Ray: a fast, powerful shot through FarmProjectiles (hidden until enough Alien Goop is
|
||||
## collected, Upgrades.revealed).
|
||||
func _shoot_alien_ray() -> void:
|
||||
var origin := Vector3(_player.global_position.x, _cfg.combat_height, _player.global_position.z)
|
||||
var dir := Vector3(aim.x, 0.0, aim.y)
|
||||
var right := Vector3(-aim.y, 0.0, aim.x)
|
||||
var muzzle := origin + dir * _cfg.muzzle_distance + right * SIDE_OFFSET
|
||||
shots_fired += 1
|
||||
_shots.fire(origin, muzzle, dir, _cfg.alien_ray_damage, _cfg.alien_ray_speed, _cfg.alien_ray_lifetime)
|
||||
models.attack(Weapon.ALIEN_RAY)
|
||||
fired.emit()
|
||||
|
||||
|
||||
## Shurikens: shuriken_count fast, cheap projectiles through FarmProjectiles, on a short cooldown.
|
||||
func _throw_shurikens() -> void:
|
||||
var origin := Vector3(_player.global_position.x, _cfg.combat_height, _player.global_position.z)
|
||||
var dir := Vector3(aim.x, 0.0, aim.y)
|
||||
var right := Vector3(-aim.y, 0.0, aim.x)
|
||||
var muzzle := origin + dir * _cfg.muzzle_distance + right * SIDE_OFFSET
|
||||
for k in _cfg.shuriken_count:
|
||||
shots_fired += 1
|
||||
_shots.fire(origin, muzzle, dir, _cfg.shuriken_damage, _cfg.shuriken_speed, _cfg.shuriken_lifetime)
|
||||
models.attack(Weapon.SHURIKENS)
|
||||
threw.emit(muzzle)
|
||||
|
||||
|
||||
## The Propane Torch: a sustained cone, like the pitchfork's but its own reach/arc/targets/damage,
|
||||
## applied every torch_tick_interval s while held (DoT: it stops the moment fire is released).
|
||||
func _torch_tick() -> int:
|
||||
torch_ticks += 1
|
||||
models.attack(Weapon.PROPANE_TORCH)
|
||||
var hits := _cone_hit(_cfg.torch_range, _cfg.torch_arc, _cfg.torch_targets, _cfg.torch_damage)
|
||||
stabbed.emit(hits)
|
||||
return hits
|
||||
|
||||
|
||||
## The nearest few enemies within reach of the aim, in arc, and in the clear take damage (the
|
||||
## pitchfork's stab and the Propane Torch's tick share this).
|
||||
func _cone_hit(reach: float, arc_deg: float, max_targets: int, damage: int) -> int:
|
||||
var hits := 0
|
||||
if enemies == null:
|
||||
return hits
|
||||
var es := enemies
|
||||
var p := Vector2(_player.global_position.x, _player.global_position.z)
|
||||
var cos_half := cos(deg_to_rad(arc_deg) * 0.5)
|
||||
var found: Array = [] # [distance, slot]
|
||||
for d in es.active_count:
|
||||
if es.alive[d] == 0:
|
||||
continue
|
||||
var e := Vector2(es.pos_x[d], es.pos_z[d])
|
||||
var dist := e.distance_to(p)
|
||||
if dist > reach + es.t_hit_radius[es.type[d]]:
|
||||
continue
|
||||
if dist > 0.3 and (e - p).dot(aim) < cos_half * dist:
|
||||
continue
|
||||
if _clear_line(p, e):
|
||||
found.append([dist, d])
|
||||
found.sort_custom(func(a: Array, b: Array) -> bool: return a[0] < b[0])
|
||||
for k in mini(found.size(), max_targets):
|
||||
var d: int = found[k][1]
|
||||
var at := Vector3(es.pos_x[d], _cfg.combat_height, es.pos_z[d])
|
||||
var type := es.type[d]
|
||||
if es.apply_hit(d, damage):
|
||||
hits += 1
|
||||
struck.emit(at, type)
|
||||
return hits
|
||||
|
||||
|
||||
func _throw() -> bool:
|
||||
if bombs == null:
|
||||
return false
|
||||
|
|
@ -418,10 +531,28 @@ func _throw() -> bool:
|
|||
func _show_attack() -> void:
|
||||
if _cooldown[weapon] > 0:
|
||||
return
|
||||
_cooldown[weapon] = interval_ticks() if weapon == Weapon.CORN_SHOOTER else stab_ticks()
|
||||
_cooldown[weapon] = _main_weapon_ticks(weapon)
|
||||
models.attack(weapon)
|
||||
|
||||
|
||||
## Ticks between attacks of a main weapon (every one but the pumpkin bomb, which isn't in
|
||||
## MAIN_WEAPONS): what _use() sets _cooldown to, reused by _show_attack() for the partner's replica.
|
||||
func _main_weapon_ticks(w: int) -> int:
|
||||
match w:
|
||||
Weapon.CORN_SHOOTER:
|
||||
return interval_ticks()
|
||||
Weapon.POTATO_CANNON:
|
||||
return potato_ticks()
|
||||
Weapon.SHURIKENS:
|
||||
return shuriken_ticks()
|
||||
Weapon.PROPANE_TORCH:
|
||||
return torch_interval_ticks()
|
||||
Weapon.ALIEN_RAY:
|
||||
return alien_ray_ticks()
|
||||
_:
|
||||
return stab_ticks()
|
||||
|
||||
|
||||
func _clear_line(a: Vector2, b: Vector2) -> bool:
|
||||
if not is_inside_tree():
|
||||
return true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue