Adjusted stock shot spacing and added muzzle flash.
This commit is contained in:
parent
01fe64a3e7
commit
b6bef3f13a
6 changed files with 160 additions and 45 deletions
|
|
@ -3,7 +3,8 @@ extends Area2D
|
|||
@export var speed: int = 150
|
||||
@export var shield_max: int = 10
|
||||
|
||||
var velocity: Vector2 = Vector2.ZERO
|
||||
#var ship = %Ship
|
||||
|
||||
var shield: int = 0: set = shield_set
|
||||
var can_shoot: bool = true
|
||||
var is_shooting: bool = false
|
||||
|
|
@ -27,55 +28,42 @@ func _process(delta):
|
|||
ship_displacement = position.y - previous_position.y
|
||||
travel += bullet_speed * delta + (ship_displacement)
|
||||
travel = clamp(travel, 0, 1.9 * weapon_spacing)
|
||||
#TODO: sprite frame change on x axis
|
||||
#if input.x > 0:
|
||||
#$Ship.frame = 2
|
||||
#$Ship/Boosters.animation = "right"
|
||||
#elif input.x < 0:
|
||||
#$Ship.frame = 0
|
||||
#$Ship/Boosters.animation = "left"
|
||||
#else:
|
||||
#$Ship.frame = 1
|
||||
#$Ship/Boosters.animation = "forward"
|
||||
|
||||
# Sprite feedback based one player input
|
||||
if input.x > 0:
|
||||
%Ship.frame = 2
|
||||
%Ship/Thrusters.flip_h = true
|
||||
%Ship/Thrusters.animation = "banked"
|
||||
elif input.x < 0:
|
||||
%Ship.frame = 1
|
||||
%Ship/Thrusters.flip_h = false
|
||||
%Ship/Thrusters.animation = "banked"
|
||||
else:
|
||||
%Ship.frame = 0
|
||||
%Ship/Thrusters.flip_h = false
|
||||
%Ship/Thrusters.animation = "fwd"
|
||||
|
||||
previous_position = position
|
||||
position += input * speed * delta
|
||||
position = position.clamp(Vector2(12,12), screensize - Vector2(12,12))
|
||||
# Update velocity based on input
|
||||
#var direction = Vector2.ZERO
|
||||
#if Input.is_action_pressed("down"):
|
||||
#direction.y += 1
|
||||
#if Input.is_action_pressed("up"):
|
||||
#direction.y -= 1
|
||||
#
|
||||
## Normalize direction and apply speed
|
||||
#if direction.length() > 0:
|
||||
#velocity = direction.normalized() * speed
|
||||
|
||||
# Update velocity
|
||||
#velocity += velocity * delta
|
||||
velocity = input * speed
|
||||
|
||||
|
||||
if Input.is_action_pressed("shoot"):
|
||||
print("Spacebar pressed!")
|
||||
is_shooting = true
|
||||
|
||||
else:
|
||||
is_shooting = false
|
||||
|
||||
if is_shooting == true:
|
||||
print("Spacebar pressed!")
|
||||
%MuzzleFlash.show()
|
||||
%Ship/MuzzleFlash.animation = "stock"
|
||||
|
||||
if travel > weapon_spacing:
|
||||
shoot()
|
||||
travel -= weapon_spacing
|
||||
|
||||
#weapon_timer += delta
|
||||
#print(weapon_timer)
|
||||
#if weapon_timer >= weapon_rate:
|
||||
#shoot()
|
||||
#weapon_timer = 0.0
|
||||
|
||||
if is_shooting == false: return
|
||||
|
||||
if is_shooting == false:
|
||||
%MuzzleFlash.hide()
|
||||
|
||||
func shield_set(_value: int):
|
||||
return
|
||||
|
|
@ -88,16 +76,13 @@ func _on_weapon_cooldown_timeout() -> void:
|
|||
|
||||
|
||||
func shoot():
|
||||
# Instantiate the bullet
|
||||
var bullet = weapon_current.instantiate()
|
||||
bullet.position = position + Vector2(0,-20)
|
||||
#previous_position = position
|
||||
get_tree().root.add_child(bullet)
|
||||
bullet.position = position + Vector2(0,-23)
|
||||
weapon_rate = bullet.shot_data.rate
|
||||
weapon_spacing = bullet.shot_data.spacing
|
||||
bullet_speed = abs(bullet.shot_data.speed)
|
||||
#bullet.global_transform = self.global_transform
|
||||
prints(bullet.shot_data.shot_name, "weapon fired") #Print which weapon is firing
|
||||
#weapon_cooldown = $WeaponCooldown
|
||||
#weapon_cooldown.wait_time = bullet.shot_data.cooldown
|
||||
#weapon_cooldown.start()
|
||||
#can_shoot = not can_shoot
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue