Updated existing shot code with constants and hard-coded variables. No

magic numbers!
This commit is contained in:
Henry 2026-04-05 12:02:13 +01:00
parent 1794abe50a
commit 0ccdc03bf8
3 changed files with 10 additions and 5 deletions

View file

@ -23,6 +23,7 @@ var weapon_spacing: float = 0.1
@onready var screensize = get_viewport_rect().size
@onready var muzzle_damage = %MuzzleBox
func _process(delta):
var input = Input.get_vector("left", "right", "up","down")
@ -63,7 +64,6 @@ func _process(delta):
is_shooting = false
if is_shooting == true:
print("Spacebar pressed!")
%MuzzleFlash.show()
%Ship/MuzzleFlash.animation = "stock"
@ -87,13 +87,15 @@ func _on_weapon_cooldown_timeout() -> void:
func shoot():
var projectiles: int = 2
var projectiles: int = 3
const PROJECTILE_SPACING: float = 10
const MUZZLE_HEIGHT: int = -23
for b in projectiles:
# Instantiate the bullets
var bullet = weapon_current.instantiate()
get_tree().root.add_child(bullet)
bullet.position = position + Vector2((b * 10) - (projectiles * projectiles),-23)
bullet.position = position + Vector2((b * PROJECTILE_SPACING) - (projectiles * projectiles), MUZZLE_HEIGHT)
# Get weapon speed and spacing for equidistant calculations
weapon_rate = bullet.shot_data.rate