-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4016 from KBVE/patch-atomic-updating-the-lasers-0…
…2-19-2025-1740011284 [CI] Merge patch-atomic-updating-the-lasers-02-19-2025-1740011284 into dev
- Loading branch information
Showing
7 changed files
with
66 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
extends Area2D | ||
|
||
|
||
var movement_vector := Vector2(0, -1) | ||
|
||
func _physics_process(delta): | ||
var laser_speed = Global.get_starship_stat("laser_speed") | ||
global_position += movement_vector.rotated(rotation) * laser_speed * delta | ||
|
||
func _on_visible_on_screen_notifier_2d_screen_exited(): | ||
queue_free() | ||
visible = false | ||
if get_parent(): | ||
get_parent()._on_laser_exited(self) | ||
#queue_free() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
extends Node | ||
|
||
const LASER_SCENE = preload("res://scenes/laser.tscn") | ||
|
||
# Shift these to the Q crate later on. | ||
var laser_pool: Array = [] | ||
var active_lasers: Array = [] | ||
|
||
func initialize_pool(size: int): | ||
for i in range(size): | ||
var laser = LASER_SCENE.instantiate() | ||
laser.connect("tree_exited", _on_laser_exited.bind(laser)) | ||
laser.set_deferred("visible", false) | ||
laser_pool.append(laser) | ||
add_child(laser) | ||
|
||
func shoot_laser(global_position: Vector2, rotation: float): | ||
if laser_pool.size() > 0: | ||
var laser = laser_pool.pop_back() | ||
laser.global_position = global_position | ||
laser.rotation = rotation | ||
laser.set_deferred("visible", true) | ||
active_lasers.append(laser) | ||
else: | ||
print("Out of laser energy shots") | ||
|
||
func _on_laser_exited(laser): | ||
if laser in active_lasers: | ||
active_lasers.erase(laser) | ||
laser.set_deferred("visible", false) | ||
laser_pool.append(laser) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters