Roughed in basically working equidistant bullet code thanks to Brendan,
Mackenzie, and Sophie.
This commit is contained in:
parent
97606c8233
commit
2594dd6e3d
4 changed files with 26 additions and 36 deletions
BIN
graphics/ship.aseprite
Normal file
BIN
graphics/ship.aseprite
Normal file
Binary file not shown.
|
|
@ -8,18 +8,25 @@ var shield: int = 0: set = shield_set
|
|||
var can_shoot: bool = true
|
||||
var is_shooting: bool = false
|
||||
var previous_position: Vector2
|
||||
var ship_displacement: float
|
||||
var travel: float = 0
|
||||
var bullet_speed: int = 150
|
||||
|
||||
@export var weapon_current : PackedScene
|
||||
|
||||
#var weapon_current = load("res://scenes/stock_weapon.tscn")
|
||||
var weapon_cooldown = Timer
|
||||
var weapon_rate: float = 0.1
|
||||
var weapon_timer: float = 0.0
|
||||
var weapon_spacing: float = 0.1
|
||||
|
||||
@onready var screensize = get_viewport_rect().size
|
||||
|
||||
func _process(delta):
|
||||
var input = Input.get_vector("left", "right", "up","down")
|
||||
|
||||
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
|
||||
|
|
@ -31,9 +38,9 @@ func _process(delta):
|
|||
#$Ship.frame = 1
|
||||
#$Ship/Boosters.animation = "forward"
|
||||
|
||||
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"):
|
||||
|
|
@ -53,15 +60,20 @@ func _process(delta):
|
|||
if Input.is_action_pressed("shoot"):
|
||||
print("Spacebar pressed!")
|
||||
is_shooting = true
|
||||
|
||||
else:
|
||||
is_shooting = false
|
||||
|
||||
if is_shooting == true:
|
||||
weapon_timer += delta
|
||||
print(weapon_timer)
|
||||
if weapon_timer >= weapon_rate:
|
||||
if travel > weapon_spacing:
|
||||
shoot()
|
||||
weapon_timer = 0.0
|
||||
travel -= weapon_spacing
|
||||
|
||||
#weapon_timer += delta
|
||||
#print(weapon_timer)
|
||||
#if weapon_timer >= weapon_rate:
|
||||
#shoot()
|
||||
#weapon_timer = 0.0
|
||||
|
||||
if is_shooting == false: return
|
||||
|
||||
|
|
@ -76,31 +88,16 @@ func _on_weapon_cooldown_timeout() -> void:
|
|||
|
||||
|
||||
func shoot():
|
||||
|
||||
#if not can_shoot: return
|
||||
#if can_shoot:
|
||||
var bullet = weapon_current.instantiate()
|
||||
bullet.position = self.position + Vector2(0,-20)
|
||||
previous_position = self.position
|
||||
bullet.position = position + Vector2(0,-20)
|
||||
#previous_position = position
|
||||
get_tree().root.add_child(bullet)
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
#I track the vertical distance the last bullet traveled relative to the ship:
|
||||
#
|
||||
#travel += bulletSpeed*dt + (Ship.y - prevShipY)
|
||||
#set prevShipY to Ship.y
|
||||
#
|
||||
#when travel > spacing -> fire bullet and
|
||||
#
|
||||
#set travel -= spacing
|
||||
#
|
||||
#(where spacing is the distance you want bullets to be apart, in pixels)
|
||||
|
|
|
|||
|
|
@ -7,3 +7,4 @@ extends Resource
|
|||
@export var rate: float = 0.1
|
||||
@export var cooldown: float = 0.25
|
||||
@export var sprite: Texture2D = preload("res://graphics/shot.png")
|
||||
@export var spacing: float = 50
|
||||
|
|
|
|||
|
|
@ -7,15 +7,7 @@ extends Area2D
|
|||
|
||||
|
||||
func _process(delta):
|
||||
var spacing: int = 100
|
||||
var travel: float
|
||||
travel += shot_data.speed * delta + (player.position.y - player.previous_position.y)
|
||||
player.previous_position.y = player.position.y
|
||||
|
||||
if travel > spacing:
|
||||
print("travel is greater than spacing!")
|
||||
position += shot_data.speed * delta # This works normally
|
||||
travel -= spacing
|
||||
position.y += shot_data.speed * delta # This works normally
|
||||
|
||||
func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
|
||||
queue_free()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue