From 6431259f7f8b1498208a9ed66371b2a0ea8b811b Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 3 Apr 2026 14:31:03 +0100 Subject: [PATCH] Modified ship thruster spacing when player banks left and right; added logic to enable/disable muzzle damage hitbox upon firing. --- scripts/player.gd | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/player.gd b/scripts/player.gd index 669b58e..9d12920 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -22,6 +22,7 @@ var weapon_timer: float = 0.0 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") @@ -31,24 +32,32 @@ func _process(delta): # Sprite feedback based one player input if input.x > 0: + %Ship/Thrusters.position.x = $Ship.position.x+1 %Ship.frame = 2 %Ship/Thrusters.flip_h = true %Ship/Thrusters.animation = "banked" elif input.x < 0: + %Ship/Thrusters.position.x = $Ship.position.x-1 %Ship.frame = 1 %Ship/Thrusters.flip_h = false %Ship/Thrusters.animation = "banked" else: %Ship.frame = 0 + %Ship/Thrusters.position.x = $Ship.position.x %Ship/Thrusters.flip_h = false %Ship/Thrusters.animation = "fwd" + # Get previous positon for equidistant bullet calculation previous_position = position + + # Move the ship based on input within the screen bounds position += input * speed * delta position = position.clamp(Vector2(12,12), screensize - Vector2(12,12)) + # Enable muzzle damage hitbox upon firing if Input.is_action_pressed("shoot"): is_shooting = true + muzzle_damage.set("disabled", false) else: is_shooting = false @@ -58,12 +67,14 @@ func _process(delta): %MuzzleFlash.show() %Ship/MuzzleFlash.animation = "stock" + # Adjust bullet spacing before firing if travel > weapon_spacing: shoot() travel -= weapon_spacing if is_shooting == false: %MuzzleFlash.hide() + muzzle_damage.set("disabled", true) func shield_set(_value: int): return @@ -80,9 +91,13 @@ func shoot(): var bullet = weapon_current.instantiate() get_tree().root.add_child(bullet) bullet.position = position + Vector2(0,-23) + + # Get weapon speed and spacing for equidistant calculations weapon_rate = bullet.shot_data.rate weapon_spacing = bullet.shot_data.spacing bullet_speed = abs(bullet.shot_data.speed) - prints(bullet.shot_data.shot_name, "weapon fired") #Print which weapon is firing + + # Print which weapon is firing + prints(bullet.shot_data.shot_name, "weapon fired")