Bow - UQcsse3200/2026-studio-4 GitHub Wiki

Description

The Bow is a ranged weapon that fires an arrow in the direction the player is aiming. Unlike the Knife and Sword, the arrow travels through the world instead of staying attached to the player.

Implementation

BowWeaponComponent extends WeaponComponent. Firing spawns a hitbox that travels in a straight line, damages the first enemy it hits and disappears, and stops instead of passing through walls, rocks or barrels. If it doesn't hit anything it expires after 1.5 seconds.

Upgrade

Upgrading the bow does not change how an arrow flies. It makes the normal shot hit harder and unlocks a heavy attack on K: three arrows fired at once in a spread. The player chooses which to use — J for a single accurate shot, K to cover a wider angle.

Upgrade state lives in WeaponUpgradeComponent on the player rather than in the bow, and the bonuses are applied when a shot resolves its damage and cooldown. The shared WeaponStatsComponent is never edited, so upgrading the bow cannot buff the Knife or Sword. See Weapon Upgrades for the shared system.

What the upgrade grants:

  • Light attack (J): the same single arrow, same speed and range, dealing ×1.2 damage.
  • Heavy attack (K): three arrows at once — one along the aim direction plus one 15° to each side — each dealing the damage of a normal unupgraded shot.
  • Sprite: every arrow is drawn as a fancier winged blade with a blue gem, cut from the same sprite sheet as the base arrow.

Each arrow is spawned by the same code as the normal shot and checks its own path independently, so a wall blocking the straight shot does not stop the two side arrows. The upgrade's power comes from arrow count rather than per-arrow damage.

A heavy attack sets the shared cooldown to ×2, so the volley cannot be spammed and a normal shot cannot be chained straight out of one. Unlike the sword and knife, the volley has no duration of its own — all three arrows leave at the same instant.

Without the upgrade the bow behaves exactly as it did in Sprint 1, and K does nothing but play the attack sound.

Unit Tests

BowWeaponComponentTest covers the bow in both states.

Unupgraded, it covers the travelling hitbox (world-space, with a ProjectileComponent and scaled damage), refusing to fire through a wall the player is touching, the arrow sprite following the player's live appearance, and K spawning nothing and starting no cooldown.

Upgraded, it covers the boosted damage on the single shot, the heavy attack spawning three arrows in the documented spread, and each arrow's path being checked independently, so a blocked centre arrow still lets the side arrows fly. Two more cover the sprite: the base arrow while unupgraded, the upgraded arrow for the single shot and every volley arrow. A final test reverts the upgrade and confirms Sprint 1 damage returns and K goes inert.

ProjectileComponentTest covers the flight shared by every arrow: straight-line travel, damaging only the first enemy hit, stopping at walls across many distances and frame rates (including a simulated frame hitch), and expiring after its lifetime. See the Weapons Test Plan for the full table.

How to Test

Run the game, open the debug terminal (F1), type weapon bow and press Enter to equip the bow. Type debug on to see hitbox outlines, then close the terminal (F1). Move with WASD, fire with J and heavy attack with K.

Unupgraded. Firing sends a single arrow from the player's edge in the facing direction, its sprite pointing along its flight. It damages the first enemy it touches and disappears, stops at walls, rocks and barrels instead of passing through, and expires after about 1.5 seconds in open space. Standing against a wall and firing into it spawns no arrow at all. Pressing K plays the attack sound but fires nothing, since the heavy attack is locked until the bow is upgraded.

Upgraded. Reopen the terminal and type upgrade bow to apply the upgrade immediately — no pickup or shop needed. Fire with J: still one arrow, now drawn with the upgraded sprite and killing enemies in fewer hits. Press K: three arrows fan out, one straight ahead and one angled to each side, and can hit several enemies at once. Stand facing a wall and press K: the straight shot is blocked while the two angled arrows still fly. Press J straight after a volley and it is blocked until the longer cooldown ends.

Reverting. Type upgrade bow off and fire again. The Sprint 1 arrow, sprite and damage return, and K goes back to playing only the attack sound — confirming the upgrade is fully reversible and the base bow is untouched.

AI Declaration

This page was written with LLM assistance (Claude Code on Opus 5), generated from the bow implementation and its test suite, and reviewed before publishing.