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
|
|
@ -30,6 +30,9 @@ var _pz := PackedFloat32Array()
|
|||
var _dx := PackedFloat32Array()
|
||||
var _dz := PackedFloat32Array()
|
||||
var _life := PackedFloat32Array()
|
||||
## Per-shot speed (m/s): cfg.projectile_speed unless fire() was given its own (Task #7's Potato
|
||||
## Cannon, Shurikens, and Alien Ray fly at their own speeds).
|
||||
var _speed := PackedFloat32Array()
|
||||
var _damage := PackedInt32Array()
|
||||
var _cfg: GameConfig
|
||||
var _enemies: EnemySystem
|
||||
|
|
@ -43,7 +46,7 @@ func setup(cfg: GameConfig, enemies: EnemySystem, bounds: Rect2, shooter: RID) -
|
|||
_enemies = enemies
|
||||
_bounds = bounds
|
||||
capacity = cfg.projectile_capacity
|
||||
for a: PackedFloat32Array in [_px, _pz, _dx, _dz, _life]:
|
||||
for a: PackedFloat32Array in [_px, _pz, _dx, _dz, _life, _speed]:
|
||||
a.resize(capacity)
|
||||
a.fill(0.0)
|
||||
_damage.resize(capacity)
|
||||
|
|
@ -73,7 +76,10 @@ func clear() -> void:
|
|||
## Fires from the weapon origin (scarecrow center at combat height) through the muzzle. The
|
||||
## origin -> muzzle segment is tested first, so a barrel poking through a wall resolves there
|
||||
## instead of spawning the shot on the far side. Returns false if the shot was skipped.
|
||||
func fire(origin: Vector3, muzzle: Vector3, dir: Vector3, damage: int = 1) -> bool:
|
||||
## speed/lifetime (<= 0: cfg.projectile_speed / cfg.projectile_lifetime) let a weapon's shot fly at
|
||||
## its own pace (Task #7: the Potato Cannon's slow heavy shot, Shurikens, and the Alien Ray's fast
|
||||
## one), with every other caller unchanged.
|
||||
func fire(origin: Vector3, muzzle: Vector3, dir: Vector3, damage: int = 1, speed: float = -1.0, lifetime: float = -1.0) -> bool:
|
||||
if active_count >= capacity:
|
||||
exhausted += 1
|
||||
return false
|
||||
|
|
@ -87,16 +93,17 @@ func fire(origin: Vector3, muzzle: Vector3, dir: Vector3, damage: int = 1) -> bo
|
|||
_pz[d] = muzzle.z
|
||||
_dx[d] = dir.x
|
||||
_dz[d] = dir.z
|
||||
_life[d] = _cfg.projectile_lifetime
|
||||
_life[d] = lifetime if lifetime > 0.0 else _cfg.projectile_lifetime
|
||||
_damage[d] = damage
|
||||
_speed[d] = speed if speed > 0.0 else _cfg.projectile_speed
|
||||
_renderer.write_new(d, muzzle.x, muzzle.z, dir.x, dir.z, 0.0)
|
||||
return true
|
||||
|
||||
|
||||
func step(dt: float) -> void:
|
||||
var step_len := _cfg.projectile_speed * dt
|
||||
var i := 0
|
||||
while i < active_count:
|
||||
var step_len := _speed[i] * dt
|
||||
var x0 := _px[i]
|
||||
var z0 := _pz[i]
|
||||
var x1 := x0 + _dx[i] * step_len
|
||||
|
|
@ -179,5 +186,6 @@ func _release(i: int) -> void:
|
|||
_dz[i] = _dz[last]
|
||||
_life[i] = _life[last]
|
||||
_damage[i] = _damage[last]
|
||||
_speed[i] = _speed[last]
|
||||
_renderer.move_slot(last, i)
|
||||
active_count -= 1
|
||||
|
|
|
|||
|
|
@ -111,6 +111,10 @@ extends Resource
|
|||
"sprint": {"wood": 8, "straw": 6},
|
||||
"corn_shooter": {"scrap": 10, "wood": 4},
|
||||
"pumpkin_bomb": {"straw": 12, "scrap": 6},
|
||||
"potato_cannon": {"scrap": 14, "wood": 8},
|
||||
"shurikens": {"scrap": 6, "straw": 4},
|
||||
"propane_torch": {"scrap": 12, "straw": 4, "wood": 6},
|
||||
"alien_ray": {"alien_goop": 6, "scrap": 10},
|
||||
"rapid_fire": {"scrap": 12, "wood": 8},
|
||||
"heavy_seeds": {"scrap": 14, "straw": 10},
|
||||
"wide_fear": {"straw": 20, "wood": 4},
|
||||
|
|
@ -137,6 +141,10 @@ extends Resource
|
|||
"rapid_fire": {"name": "Rapid fire", "text": "The corn shooter fires a third faster", "track": "Weapon", "stat": "fire_rate", "mult": 1.333, "requires": "corn_shooter"},
|
||||
"heavy_seeds": {"name": "Heavy seeds", "text": "Each kernel does 2 damage", "track": "Weapon", "stat": "shot_damage", "add": 1, "requires": "corn_shooter"},
|
||||
"pumpkin_bomb": {"name": "Pumpkin bombs", "text": "Throw a pumpkin that bursts, hurting everything within 3 m (one every 4 s)", "track": "Weapon", "shop": "shed"},
|
||||
"potato_cannon": {"name": "Potato cannon", "text": "A slow heavy potato shot that hits hard from afar", "track": "Weapon", "shop": "shed"},
|
||||
"shurikens": {"name": "Shurikens", "text": "Fast, cheap throws for a quick hit", "track": "Weapon", "shop": "shed"},
|
||||
"propane_torch": {"name": "Propane torch", "text": "A short-range jet of flame that burns everything in its cone while held", "track": "Weapon", "shop": "shed"},
|
||||
"alien_ray": {"name": "Alien ray", "text": "A salvaged alien weapon: a fast, powerful beam", "track": "Weapon", "shop": "shed", "hidden": true},
|
||||
"wide_fear": {"name": "Wide fear", "text": "Fear reaches 30% farther", "track": "Fear", "stat": "fear_radius", "mult": 1.3},
|
||||
"quick_fear": {"name": "Quick fear", "text": "Fear recharges 20% faster", "track": "Fear", "stat": "fear_cooldown", "mult": 0.8},
|
||||
"straw_stuffing": {"name": "Straw stuffing", "text": "+2 max health", "track": "Scarecrow", "stat": "scarecrow_max_hp", "add": 2},
|
||||
|
|
@ -227,6 +235,37 @@ extends Resource
|
|||
## Right-stick radial dead zone, and mouse travel (px) that switches aiming back to the mouse.
|
||||
@export var aim_dead_zone: float = 0.3
|
||||
@export var mouse_switch_threshold: float = 12.0
|
||||
## Potato Cannon (the Potato cannon upgrade, bought at the supply shed, Task #7): one heavy potato
|
||||
## every potato_cannon_cooldown s, potato_cannon_damage each, flying slow (potato_cannon_speed m/s)
|
||||
## and not far (potato_cannon_lifetime s) through FarmProjectiles.
|
||||
@export var potato_cannon_cooldown: float = 1.4
|
||||
@export_range(1, 50) var potato_cannon_damage: int = 6
|
||||
@export var potato_cannon_speed: float = 11.0
|
||||
@export var potato_cannon_lifetime: float = 2.5
|
||||
## Shurikens (the Shurikens upgrade, bought at the supply shed): shuriken_count thrown every
|
||||
## shuriken_cooldown s, shuriken_damage each, flying fast (shuriken_speed m/s) and not far
|
||||
## (shuriken_lifetime s).
|
||||
@export var shuriken_cooldown: float = 0.25
|
||||
@export_range(1, 20) var shuriken_damage: int = 1
|
||||
@export var shuriken_speed: float = 34.0
|
||||
@export var shuriken_lifetime: float = 1.0
|
||||
@export_range(1, 6) var shuriken_count: int = 1
|
||||
## Propane Torch (the Propane torch upgrade, bought at the supply shed): a sustained cone while
|
||||
## held, a tick every torch_tick_interval s, torch_damage each to every enemy within torch_range m
|
||||
## and torch_arc degrees of the aim (the nearest torch_targets), with a clear line (ScarecrowCombat,
|
||||
## the same cone test as the pitchfork's).
|
||||
@export var torch_range: float = 3.5
|
||||
@export var torch_arc: float = 55.0
|
||||
@export_range(1, 20) var torch_damage: int = 1
|
||||
@export_range(1, 20) var torch_targets: int = 5
|
||||
@export var torch_tick_interval: float = 0.2
|
||||
## Alien Ray (the Alien ray upgrade, hidden until hidden_reveal_goop Alien Goop is collected): one
|
||||
## heavy shot every alien_ray_cooldown s, alien_ray_damage each, flying fast (alien_ray_speed m/s)
|
||||
## through FarmProjectiles.
|
||||
@export var alien_ray_cooldown: float = 0.9
|
||||
@export_range(1, 80) var alien_ray_damage: int = 9
|
||||
@export var alien_ray_speed: float = 50.0
|
||||
@export var alien_ray_lifetime: float = 2.0
|
||||
|
||||
@export_group("Enemies")
|
||||
@export_range(1, 1024) var enemy_capacity: int = 800
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ 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, its rows, and where its off-hand part starts.
|
||||
const WEAPONS := Rect2(-340.0, -220.0, 304.0, 194.0)
|
||||
## The weapon panel, from the bottom-right corner: its row height, and its width (its height grows
|
||||
## with ScarecrowCombat.MAIN_WEAPONS / OFFHAND_WEAPONS, see _weapons_rect / _offhand_top).
|
||||
const WEAPON_PANEL_WIDTH := 320.0
|
||||
const WEAPON_ROW := 30.0
|
||||
const OFFHAND_TOP := 122.0
|
||||
|
||||
var kit: Scarecrow
|
||||
## This machine's scarecrow's weapons.
|
||||
|
|
@ -137,19 +137,23 @@ func _update_weapons() -> void:
|
|||
return
|
||||
var at := _weapons_rect().position
|
||||
_weapon_title.position = at + Vector2(12.0, 6.0)
|
||||
# weapon_1.. only picks the first SWITCH_ACTIONS.size() - 1 (Task #7 added more main weapons
|
||||
# than there are number keys): only those rows get a number, the rest just their name.
|
||||
var keyed := ScarecrowCombat.SWITCH_ACTIONS.size() - 1
|
||||
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)
|
||||
var text := "%d %s" % [k + 1, ScarecrowCombat.WEAPON_NAMES[w]] if k < keyed else ScarecrowCombat.WEAPON_NAMES[w]
|
||||
_weapon_row(_weapon_rows[k], text, 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)
|
||||
_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)
|
||||
_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).
|
||||
|
|
@ -170,8 +174,15 @@ func _offhand_lit(w: int) -> bool:
|
|||
return w == combat.offhand and not (w == ScarecrowCombat.Weapon.PUMPKIN_BOMB and combat.bomb_left > 0.0)
|
||||
|
||||
|
||||
## Top of the off-hand section, under the main weapon rows and the switch hint (grows with
|
||||
## ScarecrowCombat.MAIN_WEAPONS.size()).
|
||||
func _offhand_top() -> float:
|
||||
return 30.0 + ScarecrowCombat.MAIN_WEAPONS.size() * WEAPON_ROW + 32.0
|
||||
|
||||
|
||||
func _weapons_rect() -> Rect2:
|
||||
return Rect2(size + WEAPONS.position, WEAPONS.size)
|
||||
var height := _offhand_top() + 30.0 + ScarecrowCombat.OFFHAND_WEAPONS.size() * WEAPON_ROW + 12.0
|
||||
return Rect2(size - Vector2(WEAPON_PANEL_WIDTH + 36.0, height + 26.0), Vector2(WEAPON_PANEL_WIDTH, height))
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
|
|
@ -203,7 +214,7 @@ func _draw() -> void:
|
|||
_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)
|
||||
_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))
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ extends RefCounted
|
|||
## the corn shooter (bought at the shed) first ("requires" crosses shops freely).
|
||||
|
||||
## Menu order, grouped by track.
|
||||
const ORDER: Array[String] = ["corn_shooter", "rapid_fire", "heavy_seeds", "pumpkin_bomb", "wide_fear", "quick_fear",
|
||||
const ORDER: Array[String] = ["corn_shooter", "rapid_fire", "heavy_seeds", "pumpkin_bomb", "potato_cannon", "shurikens",
|
||||
"propane_torch", "alien_ray", "wide_fear", "quick_fear",
|
||||
"straw_stuffing", "pouch_upgrade", "sprint", "reinforced_fences", "long_range", "sticky_tar"]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ extends Node3D
|
|||
## hand over the recharge (set_bomb_charge)
|
||||
## attack() plays the weapon's motion (the pumpkin just leaves the hand: the thrown one is
|
||||
## PumpkinBombs').
|
||||
## Task #7's Potato Cannon, Shurikens, Propane Torch, and Alien Ray have no models of their own
|
||||
## yet (visuals stay out of scope): each is a placeholder pivot (_add_placeholder) at the corn
|
||||
## shooter's gun spot, the corn shooter's mesh tinted a different color so they're still tellable
|
||||
## apart in play; it still kicks back like a gun on each attack.
|
||||
|
||||
const PATHS: Array[String] = ["res://assets/weapons/PitchFork.glb", "res://assets/weapons/CornShooter.glb",
|
||||
"res://assets/weapons/PumpkinBomb.glb"]
|
||||
|
|
@ -56,6 +60,13 @@ func setup(model: Node3D, muzzle: Vector3) -> void:
|
|||
_add(1, Transform3D(Basis.from_euler(Vector3(0.0, PI, 0.0)), muzzle + Vector3(0.0, 0.0, tip)))
|
||||
# Pumpkin: in the left hand, in front.
|
||||
_add(2, Transform3D(Basis.IDENTITY, Vector3(-0.42, 1.2, -0.5)))
|
||||
# Potato cannon, shurikens, propane torch, and the alien ray (Task #7): no models yet, so each
|
||||
# is the corn shooter's mesh at the same gun spot, tinted so they're still tellable apart.
|
||||
var gun_rest := Transform3D(Basis.from_euler(Vector3(0.0, PI, 0.0)), muzzle + Vector3(0.0, 0.0, tip))
|
||||
_add_placeholder(3, gun_rest, Color(0.55, 0.38, 0.22)) # potato cannon: earthy brown
|
||||
_add_placeholder(4, gun_rest, Color(0.75, 0.78, 0.82)) # shurikens: steel grey
|
||||
_add_placeholder(5, gun_rest, Color(0.95, 0.45, 0.12)) # propane torch: flame orange
|
||||
_add_placeholder(6, gun_rest, Color(0.35, 0.95, 0.4)) # alien ray: alien green
|
||||
show_weapon(0)
|
||||
show_offhand(-1)
|
||||
|
||||
|
|
@ -73,6 +84,24 @@ func _add(index: int, rest: Transform3D) -> void:
|
|||
_rest.append(rest)
|
||||
|
||||
|
||||
## A placeholder main weapon (Task #7, no model of its own): the corn shooter's mesh, tinted, at
|
||||
## rest. index must follow the order _add was called in (ScarecrowCombat.Weapon).
|
||||
func _add_placeholder(index: int, rest: Transform3D, tint: Color) -> void:
|
||||
var pivot := Node3D.new()
|
||||
pivot.name = ScarecrowCombat.WEAPON_IDS[index]
|
||||
add_child(pivot)
|
||||
var mi := MeshInstance3D.new()
|
||||
mi.mesh = mesh_of(1) # the corn shooter's, reused (no new art for Task #7)
|
||||
mi.scale = Vector3.ONE * SCALES[1]
|
||||
var mat := StandardMaterial3D.new()
|
||||
mat.albedo_color = tint
|
||||
mi.material_override = mat
|
||||
pivot.add_child(mi)
|
||||
pivot.transform = rest
|
||||
_pivots.append(pivot)
|
||||
_rest.append(rest)
|
||||
|
||||
|
||||
## Shows this main weapon (ScarecrowCombat.Weapon) in the right hand, and no other.
|
||||
func show_weapon(index: int) -> void:
|
||||
weapon = index
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue