Skip to content

Commit

Permalink
Preload boost particles with workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
krobbi committed Jul 23, 2023
1 parent f309be5 commit 44f5340
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
22 changes: 14 additions & 8 deletions entities/car/car.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ var wheel_position: float = 0.0
var brake_position: float = 0.0
var boost_amount: float = 0.0

@onready var boost_player: AudioStreamPlayer2D = $BoostPlayer
@onready var boost_particles: GPUParticles2D = $BoostParticles
@onready var boost_light: PointLight2D = $BoostLight
@onready var booster: Marker2D = $Booster
@onready var boost_player: AudioStreamPlayer2D = $Booster/BoostPlayer
@onready var boost_particles: GPUParticles2D = $Booster/BoostParticles
@onready var boost_light: PointLight2D = $Booster/BoostLight

func _ready() -> void:
Global.new_game_started.connect(reset)
Expand All @@ -45,20 +46,20 @@ func _physics_process(delta: float) -> void:

apply_speed()
boost_amount = maxf(boost_amount - 0.2 * delta, 0.0)

if boost_amount <= 0.0:
Global.is_boosting = false
boost_particles.emitting = false
boost_light.hide()


func reset() -> void:
boost_amount = 0.0
boost_particles.emitting = false
boost_particles.hide()
boost_light.hide()
booster.position = Vector2(-3.0, 6.0)


func apply_boost() -> void:
boost_amount = 1.0
Global.is_boosting = true
boost_particles.show()
boost_particles.emitting = true
boost_light.show()
boost_player.play()
Expand Down Expand Up @@ -109,6 +110,11 @@ func game_state(delta: float) -> void:

if Global.no_hit_time < 100.0:
Global.no_hit_time += delta

if boost_amount <= 0.0:
Global.is_boosting = false
boost_particles.emitting = false
boost_light.hide()


func stopping_state(delta: float) -> void:
Expand Down
16 changes: 8 additions & 8 deletions entities/car/car.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ scale_min = 0.5
texture = ExtResource("1_xurhx")
offset = Vector2(0, -8)
script = ExtResource("2_tig26")
metadata/_edit_group_ = true

[node name="Hitbox" type="Area2D" parent="."]
position = Vector2(0, -8)
Expand All @@ -37,21 +36,22 @@ metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
shape = SubResource("CapsuleShape2D_2oq7k")

[node name="BoostPlayer" type="AudioStreamPlayer2D" parent="."]
[node name="Booster" type="Marker2D" parent="."]
position = Vector2(152, -184)
metadata/_edit_group_ = true

[node name="BoostPlayer" type="AudioStreamPlayer2D" parent="Booster"]
stream = ExtResource("3_tq5rk")
bus = &"Sound"

[node name="BoostParticles" type="GPUParticles2D" parent="."]
position = Vector2(-3, 6)
emitting = false
[node name="BoostParticles" type="GPUParticles2D" parent="Booster"]
amount = 16
process_material = SubResource("ParticleProcessMaterial_gwiaw")
texture = ExtResource("4_v0txi")
lifetime = 0.3
visibility_rect = Rect2(-10, -10, 20, 50)
local_coords = true

[node name="BoostLight" type="PointLight2D" parent="."]
visible = false
[node name="BoostLight" type="PointLight2D" parent="Booster"]
position = Vector2(0, 14)
texture = ExtResource("5_vubd6")
offset = Vector2(-3, 20)
2 changes: 2 additions & 0 deletions gui/score_counter/score_counter.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[ext_resource type="PackedScene" uid="uid://wrsulnlolt62" path="res://components/distance_clock/distance_clock.tscn" id="3_f6pvt"]

[node name="ScoreCounter" type="PanelContainer"]
light_mask = 0
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
Expand All @@ -18,6 +19,7 @@ script = ExtResource("2_oxw0d")
metadata/_edit_group_ = true

[node name="Label" type="Label" parent="."]
light_mask = 0
layout_direction = 3
layout_mode = 2
text = "0m"
Expand Down

0 comments on commit 44f5340

Please sign in to comment.