Modified ship thruster spacing when player banks left and right; added

logic to enable/disable muzzle damage hitbox upon firing.
This commit is contained in:
Henry 2026-04-03 14:31:03 +01:00
parent 8196e664cd
commit 6431259f7f

View file

@ -22,6 +22,7 @@ var weapon_timer: float = 0.0
var weapon_spacing: float = 0.1 var weapon_spacing: float = 0.1
@onready var screensize = get_viewport_rect().size @onready var screensize = get_viewport_rect().size
@onready var muzzle_damage = %MuzzleBox
func _process(delta): func _process(delta):
var input = Input.get_vector("left", "right", "up","down") var input = Input.get_vector("left", "right", "up","down")
@ -31,24 +32,32 @@ func _process(delta):
# Sprite feedback based one player input # Sprite feedback based one player input
if input.x > 0: if input.x > 0:
%Ship/Thrusters.position.x = $Ship.position.x+1
%Ship.frame = 2 %Ship.frame = 2
%Ship/Thrusters.flip_h = true %Ship/Thrusters.flip_h = true
%Ship/Thrusters.animation = "banked" %Ship/Thrusters.animation = "banked"
elif input.x < 0: elif input.x < 0:
%Ship/Thrusters.position.x = $Ship.position.x-1
%Ship.frame = 1 %Ship.frame = 1
%Ship/Thrusters.flip_h = false %Ship/Thrusters.flip_h = false
%Ship/Thrusters.animation = "banked" %Ship/Thrusters.animation = "banked"
else: else:
%Ship.frame = 0 %Ship.frame = 0
%Ship/Thrusters.position.x = $Ship.position.x
%Ship/Thrusters.flip_h = false %Ship/Thrusters.flip_h = false
%Ship/Thrusters.animation = "fwd" %Ship/Thrusters.animation = "fwd"
# Get previous positon for equidistant bullet calculation
previous_position = position previous_position = position
# Move the ship based on input within the screen bounds
position += input * speed * delta position += input * speed * delta
position = position.clamp(Vector2(12,12), screensize - Vector2(12,12)) position = position.clamp(Vector2(12,12), screensize - Vector2(12,12))
# Enable muzzle damage hitbox upon firing
if Input.is_action_pressed("shoot"): if Input.is_action_pressed("shoot"):
is_shooting = true is_shooting = true
muzzle_damage.set("disabled", false)
else: else:
is_shooting = false is_shooting = false
@ -58,12 +67,14 @@ func _process(delta):
%MuzzleFlash.show() %MuzzleFlash.show()
%Ship/MuzzleFlash.animation = "stock" %Ship/MuzzleFlash.animation = "stock"
# Adjust bullet spacing before firing
if travel > weapon_spacing: if travel > weapon_spacing:
shoot() shoot()
travel -= weapon_spacing travel -= weapon_spacing
if is_shooting == false: if is_shooting == false:
%MuzzleFlash.hide() %MuzzleFlash.hide()
muzzle_damage.set("disabled", true)
func shield_set(_value: int): func shield_set(_value: int):
return return
@ -80,9 +91,13 @@ func shoot():
var bullet = weapon_current.instantiate() var bullet = weapon_current.instantiate()
get_tree().root.add_child(bullet) get_tree().root.add_child(bullet)
bullet.position = position + Vector2(0,-23) bullet.position = position + Vector2(0,-23)
# Get weapon speed and spacing for equidistant calculations
weapon_rate = bullet.shot_data.rate weapon_rate = bullet.shot_data.rate
weapon_spacing = bullet.shot_data.spacing weapon_spacing = bullet.shot_data.spacing
bullet_speed = abs(bullet.shot_data.speed) 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")