Skip to content

Commit

Permalink
refactor: allowing to define multiple powers
Browse files Browse the repository at this point in the history
  • Loading branch information
florianvazelle committed Feb 10, 2024
1 parent b5fc686 commit ef304bd
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 87 deletions.
4 changes: 2 additions & 2 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ source/commit="41b766d42997fc9af1af4cb8680329bf02d0833f"

[custom_options]

build_info/commit="e3b934bf067266c1a8ca09db07e5e6308e89346e"
build_info/commit="b5fc686d6a110089b7d0b827a67dcfeefa385d67"
build_info/date="2024/02/10"

[display]
Expand Down Expand Up @@ -79,7 +79,7 @@ wav={
3d_physics/layer_1="Props"
3d_physics/layer_2="ConnectAreas"
3d_physics/layer_3="Marbles"
3d_physics/layer_4="Boosts"
3d_physics/layer_4="Powers"

[physics]

Expand Down
2 changes: 1 addition & 1 deletion scenes/blocks/bumper.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ unique_name_in_owner = true
stream = ExtResource("5_wrpvs")

[node name="ForwardDown" parent="." instance=ExtResource("5")]
transform = Transform3D(-0.999273, 0, 0.0381262, 0, 1, 0, -0.0381262, 0, -0.999273, 0, 2.5, 4)
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 2.5, 4)

[node name="Hopper2" parent="." instance=ExtResource("6")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, -2, -7)
Expand Down
5 changes: 3 additions & 2 deletions scenes/blocks/forward_down.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[ext_resource type="Material" uid="uid://be05svsycj308" path="res://resources/materials/piece.tres" id="2"]
[ext_resource type="ArrayMesh" uid="uid://1na70ao3gxxv" path="res://assets/blocks/forward_down.obj" id="3"]
[ext_resource type="Script" path="res://scripts/blocks/checkpoint.gd" id="4"]
[ext_resource type="PackedScene" uid="uid://768qm8vsl1un" path="res://scenes/boost.tscn" id="5_ppdv3"]
[ext_resource type="PackedScene" uid="uid://768qm8vsl1un" path="res://scenes/power.tscn" id="5_y4uag"]

[sub_resource type="ConcavePolygonShape3D" id="1"]
data = PackedVector3Array(-0.7391, -0.3061, -1, -0.9239, -0.3827, -1, -0.6652, -0.4445, -1, -0.6652, -0.4445, -1, -0.9239, -0.3827, -1, -0.8315, -0.5556, -1, 0.1561, -0.7846, -1, 0.1951, -0.9808, -1, 0.3061, -0.7391, -1, 0.3061, -0.7391, -1, 0.1951, -0.9808, -1, 0.3827, -0.9239, -1, -0.7846, -0.1561, -1, -0.9808, -0.1951, -1, -0.7391, -0.3061, -1, -0.7391, -0.3061, -1, -0.9808, -0.1951, -1, -0.9239, -0.3827, -1, 0, -0.8, -1, 0, -1, -1, 0.1561, -0.7846, -1, 0.1561, -0.7846, -1, 0, -1, -1, 0.1951, -0.9808, -1, 0.7846, -0.1561, -1, 0.9808, -0.1951, -1, 0.8, 0, -1, 0.8, 0, -1, 0.9808, -0.1951, -1, 1, 0, -1, -0.8, 0, -1, -1, 0, -1, -0.7846, -0.1561, -1, -0.7846, -0.1561, -1, -1, 0, -1, -0.9808, -0.1951, -1, -0.1561, -0.7846, -1, -0.1951, -0.9808, -1, 0, -0.8, -1, 0, -0.8, -1, -0.1951, -0.9808, -1, 0, -1, -1, 0.7391, -0.3061, -1, 0.9239, -0.3827, -1, 0.7846, -0.1561, -1, 0.7846, -0.1561, -1, 0.9239, -0.3827, -1, 0.9808, -0.1951, -1, -0.3061, -0.7391, -1, -0.3827, -0.9239, -1, -0.1561, -0.7846, -1, -0.1561, -0.7846, -1, -0.3827, -0.9239, -1, -0.1951, -0.9808, -1, 0.6652, -0.4445, -1, 0.8315, -0.5556, -1, 0.7391, -0.3061, -1, 0.7391, -0.3061, -1, 0.8315, -0.5556, -1, 0.9239, -0.3827, -1, -0.4445, -0.6652, -1, -0.5556, -0.8315, -1, -0.3061, -0.7391, -1, -0.3061, -0.7391, -1, -0.5556, -0.8315, -1, -0.3827, -0.9239, -1, 0.5657, -0.5657, -1, 0.7071, -0.7071, -1, 0.6652, -0.4445, -1, 0.6652, -0.4445, -1, 0.7071, -0.7071, -1, 0.8315, -0.5556, -1, -0.5657, -0.5657, -1, -0.7071, -0.7071, -1, -0.4445, -0.6652, -1, -0.4445, -0.6652, -1, -0.7071, -0.7071, -1, -0.5556, -0.8315, -1, 0.4445, -0.6652, -1, 0.5556, -0.8315, -1, 0.5657, -0.5657, -1, 0.5657, -0.5657, -1, 0.5556, -0.8315, -1, 0.7071, -0.7071, -1, -0.6652, -0.4445, -1, -0.8315, -0.5556, -1, -0.5657, -0.5657, -1, -0.5657, -0.5657, -1, -0.8315, -0.5556, -1, -0.7071, -0.7071, -1, 0.3061, -0.7391, -1, 0.3827, -0.9239, -1, 0.4445, -0.6652, -1, 0.4445, -0.6652, -1, 0.3827, -0.9239, -1, 0.5556, -0.8315, -1, -0.8315, -1.5556, 3, -0.9239, -1.3827, 3, -0.6652, -1.4445, 3, -0.6652, -1.4445, 3, -0.9239, -1.3827, 3, -0.7391, -1.3061, 3, 0.3827, -1.9239, 3, 0.1951, -1.9808, 3, 0.3061, -1.7391, 3, 0.3061, -1.7391, 3, 0.1951, -1.9808, 3, 0.1561, -1.7846, 3, -0.9239, -1.3827, 3, -0.9808, -1.1951, 3, -0.7391, -1.3061, 3, -0.7391, -1.3061, 3, -0.9808, -1.1951, 3, -0.7846, -1.1561, 3, 0.1951, -1.9808, 3, 0, -2, 3, 0.1561, -1.7846, 3, 0.1561, -1.7846, 3, 0, -2, 3, 0, -1.8, 3, 1, -1, 3, 0.9808, -1.1951, 3, 0.8, -1, 3, 0.8, -1, 3, 0.9808, -1.1951, 3, 0.7846, -1.1561, 3, -0.9808, -1.1951, 3, -1, -1, 3, -0.7846, -1.1561, 3, -0.7846, -1.1561, 3, -1, -1, 3, -0.8, -1, 3, 0, -2, 3, -0.1951, -1.9808, 3, 0, -1.8, 3, 0, -1.8, 3, -0.1951, -1.9808, 3, -0.1561, -1.7846, 3, 0.9808, -1.1951, 3, 0.9239, -1.3827, 3, 0.7846, -1.1561, 3, 0.7846, -1.1561, 3, 0.9239, -1.3827, 3, 0.7391, -1.3061, 3, -0.1951, -1.9808, 3, -0.3827, -1.9239, 3, -0.1561, -1.7846, 3, -0.1561, -1.7846, 3, -0.3827, -1.9239, 3, -0.3061, -1.7391, 3, 0.9239, -1.3827, 3, 0.8315, -1.5556, 3, 0.7391, -1.3061, 3, 0.7391, -1.3061, 3, 0.8315, -1.5556, 3, 0.6652, -1.4445, 3, -0.3827, -1.9239, 3, -0.5556, -1.8315, 3, -0.3061, -1.7391, 3, -0.3061, -1.7391, 3, -0.5556, -1.8315, 3, -0.4445, -1.6652, 3, 0.8315, -1.5556, 3, 0.7071, -1.7071, 3, 0.6652, -1.4445, 3, 0.6652, -1.4445, 3, 0.7071, -1.7071, 3, 0.5657, -1.5657, 3, -0.5556, -1.8315, 3, -0.7071, -1.7071, 3, -0.4445, -1.6652, 3, -0.4445, -1.6652, 3, -0.7071, -1.7071, 3, -0.5657, -1.5657, 3, 0.7071, -1.7071, 3, 0.5556, -1.8315, 3, 0.5657, -1.5657, 3, 0.5657, -1.5657, 3, 0.5556, -1.8315, 3, 0.4445, -1.6652, 3, -0.7071, -1.7071, 3, -0.8315, -1.5556, 3, -0.5657, -1.5657, 3, -0.5657, -1.5657, 3, -0.8315, -1.5556, 3, -0.6652, -1.4445, 3, 0.5556, -1.8315, 3, 0.3827, -1.9239, 3, 0.4445, -1.6652, 3, 0.4445, -1.6652, 3, 0.3827, -1.9239, 3, 0.3061, -1.7391, 3, 0.7071, -0.7071, -1, 0.5556, -0.8315, -1, 0.7071, -1.7071, 3, 0.7071, -1.7071, 3, 0.5556, -0.8315, -1, 0.5556, -1.8315, 3, -0.1561, -0.7846, -1, 0, -0.8, -1, -0.1561, -1.7846, 3, -0.1561, -1.7846, 3, 0, -0.8, -1, 0, -1.8, 3, 0.5556, -0.8315, -1, 0.3827, -0.9239, -1, 0.5556, -1.8315, 3, 0.5556, -1.8315, 3, 0.3827, -0.9239, -1, 0.3827, -1.9239, 3, 0, -0.8, -1, 0.1561, -0.7846, -1, 0, -1.8, 3, 0, -1.8, 3, 0.1561, -0.7846, -1, 0.1561, -1.7846, 3, 0.3827, -0.9239, -1, 0.1951, -0.9808, -1, 0.3827, -1.9239, 3, 0.3827, -1.9239, 3, 0.1951, -0.9808, -1, 0.1951, -1.9808, 3, 0.1561, -0.7846, -1, 0.3061, -0.7391, -1, 0.1561, -1.7846, 3, 0.1561, -1.7846, 3, 0.3061, -0.7391, -1, 0.3061, -1.7391, 3, 0.1951, -0.9808, -1, 0, -1, -1, 0.1951, -1.9808, 3, 0.1951, -1.9808, 3, 0, -1, -1, 0, -2, 3, 0.3061, -0.7391, -1, 0.4445, -0.6652, -1, 0.3061, -1.7391, 3, 0.3061, -1.7391, 3, 0.4445, -0.6652, -1, 0.4445, -1.6652, 3, 0, -1, -1, -0.1951, -0.9808, -1, 0, -2, 3, 0, -2, 3, -0.1951, -0.9808, -1, -0.1951, -1.9808, 3, 0.4445, -0.6652, -1, 0.5657, -0.5657, -1, 0.4445, -1.6652, 3, 0.4445, -1.6652, 3, 0.5657, -0.5657, -1, 0.5657, -1.5657, 3, 0.8, 0, -1, 1, 0, -1, 0.8, -1, 3, 0.8, -1, 3, 1, 0, -1, 1, -1, 3, -0.1951, -0.9808, -1, -0.3827, -0.9239, -1, -0.1951, -1.9808, 3, -0.1951, -1.9808, 3, -0.3827, -0.9239, -1, -0.3827, -1.9239, 3, 0.5657, -0.5657, -1, 0.6652, -0.4445, -1, 0.5657, -1.5657, 3, 0.5657, -1.5657, 3, 0.6652, -0.4445, -1, 0.6652, -1.4445, 3, -0.3827, -0.9239, -1, -0.5556, -0.8315, -1, -0.3827, -1.9239, 3, -0.3827, -1.9239, 3, -0.5556, -0.8315, -1, -0.5556, -1.8315, 3, 0.6652, -0.4445, -1, 0.7391, -0.3061, -1, 0.6652, -1.4445, 3, 0.6652, -1.4445, 3, 0.7391, -0.3061, -1, 0.7391, -1.3061, 3, -1, 0, -1, -0.8, 0, -1, -1, -1, 3, -1, -1, 3, -0.8, 0, -1, -0.8, -1, 3, -0.8, 0, -1, -0.7846, -0.1561, -1, -0.8, -1, 3, -0.8, -1, 3, -0.7846, -0.1561, -1, -0.7846, -1.1561, 3, -0.5556, -0.8315, -1, -0.7071, -0.7071, -1, -0.5556, -1.8315, 3, -0.5556, -1.8315, 3, -0.7071, -0.7071, -1, -0.7071, -1.7071, 3, 0.7391, -0.3061, -1, 0.7846, -0.1561, -1, 0.7391, -1.3061, 3, 0.7391, -1.3061, 3, 0.7846, -0.1561, -1, 0.7846, -1.1561, 3, -0.7846, -0.1561, -1, -0.7391, -0.3061, -1, -0.7846, -1.1561, 3, -0.7846, -1.1561, 3, -0.7391, -0.3061, -1, -0.7391, -1.3061, 3, -0.7071, -0.7071, -1, -0.8315, -0.5556, -1, -0.7071, -1.7071, 3, -0.7071, -1.7071, 3, -0.8315, -0.5556, -1, -0.8315, -1.5556, 3, 0.7846, -0.1561, -1, 0.8, 0, -1, 0.7846, -1.1561, 3, 0.7846, -1.1561, 3, 0.8, 0, -1, 0.8, -1, 3, -0.7391, -0.3061, -1, -0.6652, -0.4445, -1, -0.7391, -1.3061, 3, -0.7391, -1.3061, 3, -0.6652, -0.4445, -1, -0.6652, -1.4445, 3, -0.8315, -0.5556, -1, -0.9239, -0.3827, -1, -0.8315, -1.5556, 3, -0.8315, -1.5556, 3, -0.9239, -0.3827, -1, -0.9239, -1.3827, 3, 1, 0, -1, 0.9808, -0.1951, -1, 1, -1, 3, 1, -1, 3, 0.9808, -0.1951, -1, 0.9808, -1.1951, 3, -0.6652, -0.4445, -1, -0.5657, -0.5657, -1, -0.6652, -1.4445, 3, -0.6652, -1.4445, 3, -0.5657, -0.5657, -1, -0.5657, -1.5657, 3, -0.9239, -0.3827, -1, -0.9808, -0.1951, -1, -0.9239, -1.3827, 3, -0.9239, -1.3827, 3, -0.9808, -0.1951, -1, -0.9808, -1.1951, 3, 0.9808, -0.1951, -1, 0.9239, -0.3827, -1, 0.9808, -1.1951, 3, 0.9808, -1.1951, 3, 0.9239, -0.3827, -1, 0.9239, -1.3827, 3, -0.5657, -0.5657, -1, -0.4445, -0.6652, -1, -0.5657, -1.5657, 3, -0.5657, -1.5657, 3, -0.4445, -0.6652, -1, -0.4445, -1.6652, 3, -0.9808, -0.1951, -1, -1, 0, -1, -0.9808, -1.1951, 3, -0.9808, -1.1951, 3, -1, 0, -1, -1, -1, 3, 0.9239, -0.3827, -1, 0.8315, -0.5556, -1, 0.9239, -1.3827, 3, 0.9239, -1.3827, 3, 0.8315, -0.5556, -1, 0.8315, -1.5556, 3, -0.4445, -0.6652, -1, -0.3061, -0.7391, -1, -0.4445, -1.6652, 3, -0.4445, -1.6652, 3, -0.3061, -0.7391, -1, -0.3061, -1.7391, 3, 0.8315, -0.5556, -1, 0.7071, -0.7071, -1, 0.8315, -1.5556, 3, 0.8315, -1.5556, 3, 0.7071, -0.7071, -1, 0.7071, -1.7071, 3, -0.3061, -0.7391, -1, -0.1561, -0.7846, -1, -0.3061, -1.7391, 3, -0.3061, -1.7391, 3, -0.1561, -0.7846, -1, -0.1561, -1.7846, 3)
Expand Down Expand Up @@ -46,5 +46,6 @@ shape = SubResource("2")
[node name="Position3D" type="Marker3D" parent="Positions"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.14304, 1)

[node name="Boost" parent="." instance=ExtResource("5_ppdv3")]
[node name="Power" parent="." instance=ExtResource("5_y4uag")]
transform = Transform3D(3, 0, 0, 0, 3, 0, 0, 0, 3, 0, -0.5, 1)
type = 0
5 changes: 3 additions & 2 deletions scenes/blocks/turn_left_2.tscn

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions scenes/blocks/turn_left_3.tscn

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions scenes/blocks/turn_right_2.tscn

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions scenes/blocks/turn_right_3.tscn

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions scenes/boost.tscn → scenes/power.tscn
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[gd_scene load_steps=7 format=3 uid="uid://768qm8vsl1un"]

[ext_resource type="Shader" path="res://shaders/energy_shield.gdshader" id="1_gmgfm"]
[ext_resource type="Script" path="res://scripts/boost.gd" id="1_rrijl"]
[ext_resource type="AudioStream" uid="uid://5o2mnxsagwq1" path="res://assets/sounds/boost.ogg" id="3_serww"]
[ext_resource type="Script" path="res://scripts/power.gd" id="1_cvq4u"]
[ext_resource type="Shader" path="res://shaders/energy_shield.gdshader" id="2_fwh4g"]
[ext_resource type="AudioStream" uid="uid://5o2mnxsagwq1" path="res://assets/sounds/boost.ogg" id="3_wdakx"]

[sub_resource type="SphereMesh" id="SphereMesh_yntlh"]
radial_segments = 8
rings = 4

[sub_resource type="ShaderMaterial" id="ShaderMaterial_nfirf"]
render_priority = 0
shader = ExtResource("1_gmgfm")
shader = ExtResource("2_fwh4g")
shader_parameter/_shield_color = Color(0, 0, 1, 1)
shader_parameter/_shield_color_brightness = 10.0
shader_parameter/_shield_intensity = 2.0
Expand All @@ -31,8 +31,10 @@ shader_parameter/_impact_anim = 0.0

[sub_resource type="SphereShape3D" id="SphereShape3D_hmxdj"]

[node name="Boost" type="Node3D"]
script = ExtResource("1_rrijl")
[node name="Power" type="Node3D"]
visible = false
script = ExtResource("1_cvq4u")
type = null

[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
mesh = SubResource("SphereMesh_yntlh")
Expand All @@ -41,13 +43,14 @@ surface_material_override/0 = SubResource("ShaderMaterial_nfirf")
[node name="Area3D" type="Area3D" parent="."]
collision_layer = 8
collision_mask = 4
monitoring = false
monitorable = false

[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
shape = SubResource("SphereShape3D_hmxdj")

[node name="AudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="."]
stream = ExtResource("3_serww")
stream = ExtResource("3_wdakx")
unit_size = 1.0

[connection signal="body_entered" from="Area3D" to="." method="_on_area_3d_body_entered"]
4 changes: 2 additions & 2 deletions scenes/race.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

[ext_resource type="Script" path="res://scripts/race.gd" id="1"]

[sub_resource type="Curve3D" id="Curve3D_8pftg"]
[sub_resource type="Curve3D" id="Curve3D_gwdgr"]

[node name="Race" type="Node3D"]
script = ExtResource("1")

[node name="Path" type="Path3D" parent="."]
curve = SubResource("Curve3D_8pftg")
curve = SubResource("Curve3D_gwdgr")
34 changes: 0 additions & 34 deletions scripts/boost.gd

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/constants/collision_layers.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const PROPS := 0
const CONNECTION_AREAS := 1
const MARBLES := 2
const BOOSTS := 3
const POWERS := 3
4 changes: 2 additions & 2 deletions scripts/gui/overlay.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class_name Overlay

extends Control

const Participant := preload("res://scenes/gui/participant.tscn")
const ParticipantScene := preload("res://scenes/gui/participant.tscn")
const Group := preload("res://scripts/constants/groups.gd")

@onready var _ranking := get_node(^"%Ranking") as Ranking
Expand All @@ -18,7 +18,7 @@ func _process(_delta):

func add_marble_rank(marble: Marble) -> void:
# Add the marble to the list of participants
var participant = Participant.instantiate()
var participant = ParticipantScene.instantiate()
participant.set_marble(marble)
_ranking.add_child(participant)
_ranking.add_child(HSeparator.new())
Expand Down
39 changes: 19 additions & 20 deletions scripts/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ extends Node

enum State { MODE_START, MODE_PAUSE, MODE_MARBLE }

const RotationCamera := preload("res://scenes/camera/rotation_camera.tscn")
const CinematicCamera := preload("res://scenes/camera/marble_camera.tscn")
const Race := preload("res://scenes/race.tscn")
const RotationCameraScene := preload("res://scenes/camera/rotation_camera.tscn")
const MarbleCameraScene := preload("res://scenes/camera/marble_camera.tscn")
const Group := preload("res://scripts/constants/groups.gd")
const NameGenerator := preload("res://scripts/utils/name_generator.gd")

const TIME_PERIOD := 5 # 500ms

var _rotation_camera = null
var _cinematic_camera = null
var _marble_camera = null
var _mode: int = State.MODE_START
var _current_marble_index := 0
var _time := 0.0
Expand Down Expand Up @@ -42,17 +41,17 @@ var _positions := []


func _ready() -> void:
_rotation_camera = RotationCamera.instantiate()
_cinematic_camera = CinematicCamera.instantiate()
_rotation_camera = RotationCameraScene.instantiate()
_marble_camera = MarbleCameraScene.instantiate()
reset_position()
set_mode(_mode)


func _exit_tree():
if not _rotation_camera.is_inside_tree():
_rotation_camera.free()
if not _cinematic_camera.is_inside_tree():
_cinematic_camera.free()
if not _marble_camera.is_inside_tree():
_marble_camera.free()


func _unhandled_input(event):
Expand All @@ -72,7 +71,7 @@ func _unhandled_input(event):
_current_marble_index = 0
else:
_current_marble_index += 1
_cinematic_camera.set_target(
_marble_camera.set_target(
visible_marbles[_current_marble_index % marble_count]
)

Expand Down Expand Up @@ -169,7 +168,7 @@ func replace_camera(new_camera, old_cameras) -> void:
# Ensure old cameras are removed from the current scene
for camera in old_cameras:
if camera.is_inside_tree():
remove_from_tree(camera)
Main.remove_from_tree(camera)
# And create a new one
if not new_camera.is_inside_tree():
add_child(new_camera)
Expand All @@ -182,7 +181,7 @@ func _on_timer_timeout():
_race_has_started = true

# Put the camera at the right place for the start
replace_camera(_cinematic_camera, [_rotation_camera])
replace_camera(_marble_camera, [_rotation_camera])


# Set the game mode
Expand Down Expand Up @@ -223,7 +222,7 @@ func set_mode(mode):
_overlay.show()

# Put the camera at the right place for the start
replace_camera(_rotation_camera, [_cinematic_camera])
replace_camera(_rotation_camera, [_marble_camera])

# Focus the rotation camera on the marble start line
_rotation_camera.target = get_highest_piece().global_position + Vector3.UP * 5
Expand All @@ -241,7 +240,7 @@ func set_mode(mode):
break
marble.set_marble_name(marble_name)
_overlay.add_marble_rank(marble)
_cinematic_camera.set_target(marble)
_marble_camera.set_target(marble)

await Fade.fade_in(1, Color.BLACK, "Diamond", false, false).finished
_countdown.connect("countdown_finished", _on_timer_timeout, CONNECT_ONE_SHOT)
Expand All @@ -250,19 +249,19 @@ func set_mode(mode):
else:
_overlay.show()

replace_camera(_cinematic_camera, [_rotation_camera])
replace_camera(_marble_camera, [_rotation_camera])

elif _mode == State.MODE_START:
_overlay.hide()
_pause_menu.open_start_menu()
replace_camera(_rotation_camera, [_cinematic_camera])
replace_camera(_rotation_camera, [_marble_camera])
# Focus the rotation camera on race
_rotation_camera.target = Vector3.ZERO
_rotation_camera.distance_to_target = 50.0

elif _mode == State.MODE_PAUSE:
_pause_menu.open_pause_menu()
replace_camera(_rotation_camera, [_cinematic_camera])
replace_camera(_rotation_camera, [_marble_camera])
# Focus the rotation camera on race
_rotation_camera.target = Vector3.ZERO
_rotation_camera.distance_to_target = 50.0
Expand Down Expand Up @@ -309,7 +308,7 @@ func _process(delta):
_max_checkpoint_count = _ranking._first_marble._checkpoint_count

# Compute the lap (1 lap equals to one chunk)
var lap_count: int = ceil((_max_checkpoint_count + 3) / _race._step_count)
var lap_count := ceili(_max_checkpoint_count / (_race._step_count - 3.0))
# If one more lap was done
if lap_count > _old_lap_count:
# Generate a chunk
Expand All @@ -325,15 +324,15 @@ func _process(delta):
if _mode == State.MODE_PAUSE and _pause_menu.is_quit():
set_mode(State.MODE_START)

if not _cinematic_camera.has_target() or not _cinematic_camera.get_target().visible:
if not _marble_camera.has_target() or not _marble_camera.get_target().visible:
var found = false
for marble in _marbles:
if marble.visible:
found = true
_cinematic_camera.set_target(marble)
_marble_camera.set_target(marble)
break
if not found:
replace_camera(_rotation_camera, [_cinematic_camera])
replace_camera(_rotation_camera, [_marble_camera])


# Handle victory conditions on explosion mode
Expand Down
51 changes: 51 additions & 0 deletions scripts/power.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@tool
extends Node3D

enum PowerType { BOOST }

const Group := preload("res://scripts/constants/groups.gd")
const CollisionLayers := preload("res://scripts/constants/collision_layers.gd")

@export var active: bool:
set = toggle

@export var type: PowerType:
set = set_type

@onready var area: Area3D = get_node(^"Area3D")
@onready var audio: AudioStreamPlayer3D = get_node(^"AudioStreamPlayer3D")
@onready var mesh: MeshInstance3D = get_node(^"MeshInstance3D")


func _ready():
toggle(false)

area.collision_layer = 1 << CollisionLayers.POWERS
area.collision_mask = 1 << CollisionLayers.MARBLES

set_type(type)


func toggle(val) -> void:
active = val
set_visible(val)
area.set_monitoring(val)


func set_type(val) -> void:
type = val

if mesh:
# Change the color accordingly to the type of the power
match type:
PowerType.BOOST:
var material: ShaderMaterial = mesh.get_surface_override_material(0)
material.set_shader_parameter("_shield_color", Color.BLUE)


func _on_area_3d_body_entered(body):
if body.is_in_group(Group.MARBLES):
match type:
PowerType.BOOST:
body.linear_velocity *= 2
audio.play()
Loading

0 comments on commit ef304bd

Please sign in to comment.