Skip to content

Commit

Permalink
Merge pull request #4016 from KBVE/patch-atomic-updating-the-lasers-0…
Browse files Browse the repository at this point in the history
…2-19-2025-1740011284

[CI] Merge patch-atomic-updating-the-lasers-02-19-2025-1740011284 into dev
  • Loading branch information
h0lybyte authored Feb 20, 2025
2 parents cd9c8d6 + b91f86d commit 0bee5c9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 11 deletions.
4 changes: 3 additions & 1 deletion apps/gamejam/brackeys/13/scenes/game.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=3 format=3 uid="uid://cbrda40vq26pj"]
[gd_scene load_steps=4 format=3 uid="uid://cbrda40vq26pj"]

[ext_resource type="Script" path="res://scripts/game.gd" id="1_oyaqx"]
[ext_resource type="PackedScene" uid="uid://1s5v0llrjq3" path="res://scenes/spaceship.tscn" id="1_rlyye"]
[ext_resource type="Script" path="res://scripts/projectiles.gd" id="3_hgajf"]

[node name="Game" type="Node2D"]
script = ExtResource("1_oyaqx")
Expand All @@ -10,3 +11,4 @@ script = ExtResource("1_oyaqx")
position = Vector2(500, 300)

[node name="Projectiles" type="Node" parent="."]
script = ExtResource("3_hgajf")
2 changes: 2 additions & 0 deletions apps/gamejam/brackeys/13/scenes/laser.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ shape = SubResource("CapsuleShape2D_44da2")
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]
position = Vector2(0, -14.5)
scale = Vector2(0.5, 1.35)

[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]
9 changes: 6 additions & 3 deletions apps/gamejam/brackeys/13/scripts/game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ extends Node2D
@onready var spaceship = $Spaceship
@onready var projectiles = $Projectiles

const LASER_POOL_SIZE = 25

func _ready():
spaceship.connect("laser_shot", _on_spaceship_laser_shot)

func _on_spaceship_laser_shot(laser):
projectiles.add_child(laser)
projectiles.initialize_pool(LASER_POOL_SIZE)

func _on_spaceship_laser_shot(scope_position: Vector2, rotation: float):
projectiles.shoot_laser(scope_position, rotation)
20 changes: 18 additions & 2 deletions apps/gamejam/brackeys/13/scripts/global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extends Node
signal resource_changed(resource_name, new_value)
signal resource_receipt(resource_name, amount, new_value, invoice)
signal starship_stat_changed(stat_name, new_value)
signal starship_data_changed(data_name, new_value)

var resources := {
"gold": 0,
Expand All @@ -17,15 +18,23 @@ var base_starship_stats := {
"max_speed": 400.0,
"rotation_speed": 270.0,
"laser_speed": 550.0,
"overheat": 0.0
"overheat": 0.0,
"laser_ammo": 20.0,
}

var starship_bonuses := {
"acceleration": 0.0,
"max_speed": 0.0,
"rotation_speed": 0.0,
"laser_speed": 0.0,
"overheat": 0.0
"overheat": 0.0,
"laser_ammo": 0.0
}

var starship_data := {
"name": "Explorer-X",
"emergency_rockets_used": false,
"shield_active": false
}

func earn_resource(resource_name: String, amount: int, invoice: String = "Earned"):
Expand Down Expand Up @@ -80,3 +89,10 @@ func set_base_starship_stat(stat_name: String, new_value: float):
return
base_starship_stats[stat_name] = new_value
emit_signal("starship_stat_changed", stat_name, get_starship_stat(stat_name))

func get_starship_data(data_name: String):
return starship_data.get(data_name, null)

func set_starship_data(data_name: String, new_value):
starship_data[data_name] = new_value
emit_signal("starship_data_changed", data_name, new_value)
6 changes: 5 additions & 1 deletion apps/gamejam/brackeys/13/scripts/laser.gd
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()
31 changes: 31 additions & 0 deletions apps/gamejam/brackeys/13/scripts/projectiles.gd
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)
5 changes: 1 addition & 4 deletions apps/gamejam/brackeys/13/scripts/spaceship.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,4 @@ func _physics_process(delta):
global_position.x = 0

func shoot_laser():
var laser = laser_scene.instantiate();
laser.global_position = scope.global_position
laser.rotation = rotation
emit_signal("laser_shot", laser)
emit_signal("laser_shot", scope.global_position, rotation)

0 comments on commit 0bee5c9

Please sign in to comment.