diff --git a/Audio/BGM/Foothpath.mp3 b/Audio/BGM/Foothpath.mp3 new file mode 100644 index 0000000..d8e5ec5 Binary files /dev/null and b/Audio/BGM/Foothpath.mp3 differ diff --git a/Audio/BGM/Foothpath.mp3.import b/Audio/BGM/Foothpath.mp3.import new file mode 100644 index 0000000..d0b2973 --- /dev/null +++ b/Audio/BGM/Foothpath.mp3.import @@ -0,0 +1,19 @@ +[remap] + +importer="mp3" +type="AudioStreamMP3" +uid="uid://dgumak5rfufcr" +path="res://.godot/imported/Foothpath.mp3-f79ae66898319ed316e084d31be1f8ed.mp3str" + +[deps] + +source_file="res://Audio/BGM/Foothpath.mp3" +dest_files=["res://.godot/imported/Foothpath.mp3-f79ae66898319ed316e084d31be1f8ed.mp3str"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/Audio/BGM/SeasidePalace.mp3 b/Audio/BGM/SeasidePalace.mp3 new file mode 100644 index 0000000..de687aa Binary files /dev/null and b/Audio/BGM/SeasidePalace.mp3 differ diff --git a/Audio/BGM/SeasidePalace.mp3.import b/Audio/BGM/SeasidePalace.mp3.import new file mode 100644 index 0000000..0faa063 --- /dev/null +++ b/Audio/BGM/SeasidePalace.mp3.import @@ -0,0 +1,19 @@ +[remap] + +importer="mp3" +type="AudioStreamMP3" +uid="uid://c22yq0xgr51ns" +path="res://.godot/imported/SeasidePalace.mp3-031c623616760663bd8d42dd0ed69671.mp3str" + +[deps] + +source_file="res://Audio/BGM/SeasidePalace.mp3" +dest_files=["res://.godot/imported/SeasidePalace.mp3-031c623616760663bd8d42dd0ed69671.mp3str"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/Audio/SFX/gunshot.mp3 b/Audio/SFX/gunshot.mp3 new file mode 100644 index 0000000..9893129 Binary files /dev/null and b/Audio/SFX/gunshot.mp3 differ diff --git a/Audio/SFX/gunshot.mp3.import b/Audio/SFX/gunshot.mp3.import new file mode 100644 index 0000000..066aebb --- /dev/null +++ b/Audio/SFX/gunshot.mp3.import @@ -0,0 +1,19 @@ +[remap] + +importer="mp3" +type="AudioStreamMP3" +uid="uid://cupjwk5q538g2" +path="res://.godot/imported/gunshot.mp3-5c8edc7db5b7f086bcc103a3b02e3ddc.mp3str" + +[deps] + +source_file="res://Audio/SFX/gunshot.mp3" +dest_files=["res://.godot/imported/gunshot.mp3-5c8edc7db5b7f086bcc103a3b02e3ddc.mp3str"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/Scenes/Gun.tscn b/Scenes/Gun.tscn index a59cf75..ef8ad33 100644 --- a/Scenes/Gun.tscn +++ b/Scenes/Gun.tscn @@ -38,6 +38,7 @@ size = Vector2i(1152, 648) render_target_update_mode = 4 [node name="Camera3D" type="Camera3D" parent="SubViewportContainer/SubViewport"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -38809.9, 0) cull_mask = 1047554 environment = ExtResource("1_3jquc") diff --git a/Scenes/Healthbar.cs b/Scenes/Healthbar.cs deleted file mode 100644 index 50cf6a1..0000000 --- a/Scenes/Healthbar.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Godot; - -public partial class Healthbar : Sprite3D -{ - public override void _Ready() - { - } -} diff --git a/Scenes/Level.tscn b/Scenes/Level.tscn index 6b396ea..b342e85 100644 --- a/Scenes/Level.tscn +++ b/Scenes/Level.tscn @@ -1,20 +1,31 @@ -[gd_scene load_steps=7 format=3 uid="uid://ocor7udqvoec"] +[gd_scene load_steps=9 format=3 uid="uid://ocor7udqvoec"] -[ext_resource type="PackedScene" uid="uid://bi7j4afsxghrj" path="res://Scenes/Player.tscn" id="1_my8b5"] -[ext_resource type="PackedScene" uid="uid://cc5emorildoar" path="res://Scenes/Gun.tscn" id="2_mhg71"] +[ext_resource type="Script" path="res://Scripts/Level1.cs" id="1_gvb28"] [ext_resource type="PackedScene" uid="uid://b03tplah8y1do" path="res://Scenes/target.tscn" id="3_civmh"] [sub_resource type="BoxShape3D" id="BoxShape3D_gyf0l"] -size = Vector3(20, 0.5, 20) +size = Vector3(10, 0.5, 20) -[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_78bnu"] +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_vca8v"] albedo_color = Color(0, 0, 0, 1) [sub_resource type="BoxMesh" id="BoxMesh_v2sg1"] -material = SubResource("StandardMaterial3D_78bnu") -size = Vector3(20, 0.5, 20) +material = SubResource("StandardMaterial3D_vca8v") +size = Vector3(10, 0.5, 20) -[node name="Level" type="Node3D"] +[sub_resource type="BoxShape3D" id="BoxShape3D_ql8hs"] +size = Vector3(10, 5, 1) + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_po5cl"] +albedo_color = Color(0.219608, 1, 1, 1) + +[sub_resource type="BoxMesh" id="BoxMesh_6wms0"] +material = SubResource("StandardMaterial3D_po5cl") +size = Vector3(10, 5, 1) + +[node name="Level" type="Node3D" node_paths=PackedStringArray("_spawnPoint")] +script = ExtResource("1_gvb28") +_spawnPoint = NodePath("Spawn Point") [node name="StaticBody3D" type="StaticBody3D" parent="."] collision_mask = 0 @@ -26,13 +37,24 @@ shape = SubResource("BoxShape3D_gyf0l") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.189965, 0) mesh = SubResource("BoxMesh_v2sg1") -[node name="Player" parent="." instance=ExtResource("1_my8b5")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.269294, 0) - -[node name="Gun" parent="Player" instance=ExtResource("2_mhg71")] -transform = Transform3D(0.979575, 0, 0.201078, 0, 1, 0, -0.201078, 0, 0.979575, 0.074702, 1.59908, -0.498807) - [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] transform = Transform3D(-0.0510635, -0.435165, -0.898901, 0, -0.900076, 0.435734, -0.998695, 0.0222501, 0.045961, -5.60126, 7.19548, 0) [node name="Target" parent="." instance=ExtResource("3_civmh")] + +[node name="Area3D" type="Area3D" parent="."] +collision_layer = 0 +collision_mask = 4 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.54778, -7.99117) +shape = SubResource("BoxShape3D_ql8hs") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Area3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0.000349066, 0, -0.000349066, 1, 0, 2.52005, -7.98064) +mesh = SubResource("BoxMesh_6wms0") + +[node name="Spawn Point" type="Marker3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.712399, 7.37212) + +[connection signal="body_entered" from="Area3D" to="." method="OnCollisionWithLevelLoader"] diff --git a/Scenes/Main.tscn b/Scenes/Main.tscn new file mode 100644 index 0000000..c9a9e69 --- /dev/null +++ b/Scenes/Main.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://dc34fjiv2tppx"] + +[ext_resource type="Script" path="res://Scripts/Main.cs" id="1_n48r1"] + +[node name="Main" type="Node"] +script = ExtResource("1_n48r1") diff --git a/Scenes/MainMenu.tscn b/Scenes/MainMenu.tscn new file mode 100644 index 0000000..39d630f --- /dev/null +++ b/Scenes/MainMenu.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=2 format=3 uid="uid://dri1iuiavxf24"] + +[ext_resource type="Script" path="res://Scripts/MainMenu.cs" id="1_gt0q4"] + +[node name="MainMenu" type="Node2D"] + +[node name="Node2D" type="Node2D" parent="."] +script = ExtResource("1_gt0q4") + +[node name="Button" type="Button" parent="Node2D"] +offset_left = 310.0 +offset_top = 251.0 +offset_right = 835.0 +offset_bottom = 386.0 +text = "Start" + +[connection signal="pressed" from="Node2D/Button" to="Node2D" method="StartButtonPressed"] diff --git a/Scenes/Player.tscn b/Scenes/Player.tscn index 65dd166..4bbaa86 100644 --- a/Scenes/Player.tscn +++ b/Scenes/Player.tscn @@ -1,14 +1,25 @@ -[gd_scene load_steps=5 format=3 uid="uid://bi7j4afsxghrj"] +[gd_scene load_steps=10 format=3 uid="uid://dae1bs2yqqt5l"] [ext_resource type="Script" path="res://Scripts/Player.cs" id="1_jsq3s"] [ext_resource type="Environment" uid="uid://c1i78mwq3ug2f" path="res://Scenes/Enivornment.tres" id="2_t03qe"] +[ext_resource type="AudioStream" uid="uid://cupjwk5q538g2" path="res://Audio/SFX/gunshot.mp3" id="3_5mglu"] +[ext_resource type="Script" path="res://Scripts/SoundEffects.cs" id="4_fmvkw"] +[ext_resource type="PackedScene" uid="uid://cc5emorildoar" path="res://Scenes/Gun.tscn" id="5_sb1dv"] +[ext_resource type="Script" path="res://Scripts/PlayerHUD.cs" id="6_pawgr"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_cxbex"] [sub_resource type="CapsuleMesh" id="CapsuleMesh_7dxig"] +[sub_resource type="LabelSettings" id="LabelSettings_3d4s1"] +font_size = 40 +font_color = Color(0.490196, 0.403922, 0.278431, 1) +outline_size = 3 +outline_color = Color(0, 0, 0, 1) + [node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("_pivot")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.13331, 0) +collision_layer = 5 script = ExtResource("1_jsq3s") _mouseSensitivity = 0.07 _pivot = NodePath("Pivot") @@ -28,7 +39,40 @@ fov = 60.0 transform = Transform3D(0.125, 0, 0, 0, 0.125, 0, 0, 0, 0.125, 0, 0, 0) target_position = Vector3(0, 0, -1000) +[node name="AudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="Pivot/Camera3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.10748, -0.0718701) +stream = ExtResource("3_5mglu") +volume_db = -28.0 +max_db = -5.0 +max_polyphony = 8 +script = ExtResource("4_fmvkw") + [node name="MeshInstance3D" type="MeshInstance3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) visible = false mesh = SubResource("CapsuleMesh_7dxig") + +[node name="Gun" parent="." instance=ExtResource("5_sb1dv")] + +[node name="CanvasLayer" type="CanvasLayer" parent="."] +script = ExtResource("6_pawgr") + +[node name="AmmoLabel" type="Label" parent="CanvasLayer"] +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -149.0 +offset_top = -63.0 +grow_horizontal = 0 +grow_vertical = 0 +size_flags_horizontal = 8 +size_flags_vertical = 8 +text = "Ammo" +label_settings = SubResource("LabelSettings_3d4s1") +horizontal_alignment = 1 +vertical_alignment = 1 + +[connection signal="FireGun" from="." to="Pivot/Camera3D/AudioStreamPlayer3D" method="OnFireGun"] +[connection signal="FireGun" from="." to="CanvasLayer" method="OnFireGun"] diff --git a/Scenes/level_2.tscn b/Scenes/level_2.tscn new file mode 100644 index 0000000..816ba6f --- /dev/null +++ b/Scenes/level_2.tscn @@ -0,0 +1,57 @@ +[gd_scene load_steps=8 format=3 uid="uid://bkuyttbckhl3"] + +[ext_resource type="Script" path="res://Scripts/Level2.cs" id="1_baeon"] + +[sub_resource type="BoxShape3D" id="BoxShape3D_ggo5h"] +size = Vector3(10, 0.5, 20) + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_78bnu"] +albedo_color = Color(0, 0, 0, 1) + +[sub_resource type="BoxMesh" id="BoxMesh_oq36m"] +material = SubResource("StandardMaterial3D_78bnu") +size = Vector3(10, 0.5, 20) + +[sub_resource type="BoxShape3D" id="BoxShape3D_b5rn0"] +size = Vector3(10, 5, 1) + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_kfppx"] +albedo_color = Color(1, 0.494118, 1, 1) + +[sub_resource type="BoxMesh" id="BoxMesh_0mdec"] +material = SubResource("StandardMaterial3D_kfppx") +size = Vector3(10, 5, 1) + +[node name="Level2" type="Node3D" node_paths=PackedStringArray("_spawnPoint")] +script = ExtResource("1_baeon") +_spawnPoint = NodePath("Spawn Point") + +[node name="StaticBody3D" type="StaticBody3D" parent="."] +collision_mask = 0 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"] +shape = SubResource("BoxShape3D_ggo5h") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.189965, 0) +mesh = SubResource("BoxMesh_oq36m") + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(-0.0510635, -0.435165, -0.898901, 0, -0.900076, 0.435734, -0.998695, 0.0222501, 0.045961, -5.60126, 7.19548, 0) + +[node name="Area3D" type="Area3D" parent="."] +collision_layer = 0 +collision_mask = 4 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"] +transform = Transform3D(-0.000924988, 0, 1, 0, 1, 0, -1, 0, -0.000924988, -5.22508, 2.54778, 3.19473) +shape = SubResource("BoxShape3D_b5rn0") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Area3D"] +transform = Transform3D(-0.000924988, -0.000349066, 1, 0, 1, 0.000349066, -1, 3.22882e-07, -0.000924988, -5.21455, 2.52005, 3.19472) +mesh = SubResource("BoxMesh_0mdec") + +[node name="Spawn Point" type="Marker3D" parent="."] +transform = Transform3D(-0.999587, 0, -0.0287242, 0, 1, 0, 0.0287242, 0, -0.999587, 0, 0.712399, -3.24364) + +[connection signal="body_entered" from="Area3D" to="." method="OnCollisionWithLevelLoader"] diff --git a/Scenes/target.tscn b/Scenes/target.tscn index b1c23c1..081e3b3 100644 --- a/Scenes/target.tscn +++ b/Scenes/target.tscn @@ -1,6 +1,9 @@ -[gd_scene load_steps=5 format=3 uid="uid://b03tplah8y1do"] +[gd_scene load_steps=8 format=3 uid="uid://b03tplah8y1do"] [ext_resource type="Script" path="res://Scripts/Target.cs" id="1_ykgyh"] +[ext_resource type="Texture2D" uid="uid://dhcfanxewk34" path="res://Textures/Healthbar/barHorizontal_green_mid 200.png" id="2_66yfs"] +[ext_resource type="Script" path="res://Scripts/Healthbar.cs" id="3_svfp2"] +[ext_resource type="Script" path="res://Scripts/HealthbarProgress.cs" id="4_hb8qi"] [sub_resource type="BoxShape3D" id="BoxShape3D_37aka"] @@ -12,7 +15,7 @@ material = SubResource("StandardMaterial3D_8nuxw") [node name="Target" type="StaticBody3D" node_paths=PackedStringArray("_progressBar")] script = ExtResource("1_ykgyh") -_progressBar = NodePath("ProgressBar") +_progressBar = NodePath("Sprite3D") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.12414, -3.96702) @@ -23,11 +26,20 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.12414, -3.96702) mesh = SubResource("BoxMesh_ni5do") skeleton = NodePath("") -[node name="ProgressBar" type="ProgressBar" parent="."] -offset_left = 460.0 -offset_top = 3.0 -offset_right = 688.0 -offset_bottom = 58.0 -value = 100.0 - [node name="Sprite3D" type="Sprite3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0327015, 3.01463, -3.79129) +billboard = 1 +texture = ExtResource("2_66yfs") +script = ExtResource("3_svfp2") + +[node name="SubViewport" type="SubViewport" parent="Sprite3D"] +disable_3d = true +transparent_bg = true +size = Vector2i(200, 26) +size_2d_override_stretch = true + +[node name="TextureProgressBar" type="TextureProgressBar" parent="Sprite3D/SubViewport"] +offset_right = 40.0 +offset_bottom = 40.0 +texture_progress = ExtResource("2_66yfs") +script = ExtResource("4_hb8qi") diff --git a/Scripts/BGMPlayer.cs b/Scripts/BGMPlayer.cs new file mode 100644 index 0000000..1b56c79 --- /dev/null +++ b/Scripts/BGMPlayer.cs @@ -0,0 +1,17 @@ +using Godot; + +public partial class BGMPlayer : AudioStreamPlayer +{ + public void SetBGMFromFilepath(string path) + { + var audioStream = ResourceLoader.Load(path); + if (Stream != audioStream) + Stream = audioStream; + } + + public void PlayBGM() + { + if (!Playing) + Play(); + } +} diff --git a/Scripts/Healthbar.cs b/Scripts/Healthbar.cs new file mode 100644 index 0000000..fb38a7d --- /dev/null +++ b/Scripts/Healthbar.cs @@ -0,0 +1,16 @@ +using System.Linq; +using Godot; + +public partial class Healthbar : Sprite3D +{ + public override void _Ready() + { + Texture = GetChildren().OfType().Single().GetTexture(); + } + + public void Update(int amount, int full) + { + var progressBar = GetChildren().ElementAt(0).GetChildren().OfType().Single(); + progressBar.UpdateBar(amount, full); + } +} diff --git a/Scripts/HealthbarProgress.cs b/Scripts/HealthbarProgress.cs new file mode 100644 index 0000000..82b5af5 --- /dev/null +++ b/Scripts/HealthbarProgress.cs @@ -0,0 +1,9 @@ +using Godot; + +public partial class HealthbarProgress : TextureProgressBar +{ + public void UpdateBar(int amount, int full) + { + Value = amount; + } +} diff --git a/Scripts/Level1.cs b/Scripts/Level1.cs new file mode 100644 index 0000000..32271bb --- /dev/null +++ b/Scripts/Level1.cs @@ -0,0 +1,25 @@ +using System.Linq; +using Godot; + +public partial class Level1 : Node3D +{ + [Export] + private Marker3D _spawnPoint; + + public override void _Ready() + { + var player = GetTree().Root.GetChildren().OfType().Single(); + player.Transform = _spawnPoint.Transform; + var bgmPlayer = GetNode("/root/BgmPlayer"); + GD.Print(bgmPlayer); + bgmPlayer.SetBGMFromFilepath("res://Audio/BGM/Foothpath.mp3"); + bgmPlayer.PlayBGM(); + } + + public void OnCollisionWithLevelLoader(Node3D node) + { + GD.Print("Entered level loader"); + var sceneHandler = GetNode("/root/SceneHandler"); + sceneHandler.OnLoadScene("res://Scenes/level_2.tscn"); + } +} diff --git a/Scripts/Level2.cs b/Scripts/Level2.cs new file mode 100644 index 0000000..7bf722e --- /dev/null +++ b/Scripts/Level2.cs @@ -0,0 +1,25 @@ +using System.Linq; +using Godot; + +public partial class Level2 : Node3D +{ + [Export] + private Marker3D _spawnPoint; + + public override void _Ready() + { + var player = GetTree().Root.GetChildren().OfType().Single(); + player.Transform = _spawnPoint.Transform; + var bgmPlayer = GetNode("/root/BgmPlayer"); + GD.Print(bgmPlayer); + bgmPlayer.SetBGMFromFilepath("res://Audio/BGM/SeasidePalace.mp3"); + bgmPlayer.PlayBGM(); + } + + public void OnCollisionWithLevelLoader(Node3D node) + { + GD.Print("Entered level loader"); + var sceneHandler = (SceneHandler)GetNode("/root/SceneHandler"); + sceneHandler.OnLoadScene("res://Scenes/Level.tscn"); + } +} diff --git a/Scripts/Main.cs b/Scripts/Main.cs new file mode 100644 index 0000000..0ec9f1b --- /dev/null +++ b/Scripts/Main.cs @@ -0,0 +1,11 @@ +using Godot; + +public partial class Main : Node +{ + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + var mainMenuScene = ResourceLoader.Load("res://Scenes/MainMenu.tscn").Instantiate(); + AddChild(mainMenuScene); + } +} diff --git a/Scripts/MainMenu.cs b/Scripts/MainMenu.cs new file mode 100644 index 0000000..23c354a --- /dev/null +++ b/Scripts/MainMenu.cs @@ -0,0 +1,12 @@ +using Godot; + +public partial class MainMenu : Node2D +{ + public void StartButtonPressed() + { + var sceneHandler = (SceneHandler)GetNode("/root/SceneHandler"); + sceneHandler.OnLoadScene("res://Scenes/Level.tscn"); + var player = ResourceLoader.Load("res://Scenes/Player.tscn").Instantiate(); + GetTree().Root.AddChild(player); + } +} diff --git a/Scripts/Player.cs b/Scripts/Player.cs index 0d8fcf4..50cf452 100644 --- a/Scripts/Player.cs +++ b/Scripts/Player.cs @@ -4,6 +4,8 @@ public partial class Player : CharacterBody3D { [Signal] public delegate void OnHitEventHandler(); + [Signal] + public delegate void FireGunEventHandler(); public const float _speed = 5.0f; public const float _jumpVelocity = 4.5f; @@ -63,10 +65,13 @@ public partial class Player : CharacterBody3D _pivot.Rotation = new Vector3(Mathf.Clamp(_pivot.Rotation.X, Mathf.DegToRad(-80), Mathf.DegToRad(80)), _pivot.Rotation.Y, _pivot.Rotation.Z); } + if (@event.IsActionPressed("fire")) + EmitSignal(SignalName.FireGun); + if (@event.IsActionPressed("fire") && _aimCast.IsColliding()) { EmitSignal(SignalName.OnHit); - _aimCast.GetCollider().Call("OnHitEvent", 3); + _aimCast.GetCollider().Call("OnHitEvent", 10); } } diff --git a/Scripts/PlayerHUD.cs b/Scripts/PlayerHUD.cs new file mode 100644 index 0000000..fd20037 --- /dev/null +++ b/Scripts/PlayerHUD.cs @@ -0,0 +1,18 @@ +using System.Linq; +using Godot; + +public partial class PlayerHUD : CanvasLayer +{ + private int _currentAmmo = 30; + public override void _Ready() + { + var ammoLabel = GetChildren().Single(x => x.Name == "AmmoLabel") as Label; + ammoLabel.Text = $"{_currentAmmo}/30"; + } + + public void OnFireGun() + { + var ammoLabel = GetChildren().Single(x => x.Name == "AmmoLabel") as Label; + ammoLabel.Text = $"{--_currentAmmo}/30"; + } +} diff --git a/Scripts/SceneHandler.cs b/Scripts/SceneHandler.cs new file mode 100644 index 0000000..5aba671 --- /dev/null +++ b/Scripts/SceneHandler.cs @@ -0,0 +1,31 @@ +using Godot; + +public partial class SceneHandler : Node +{ + private Node _root; + + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + _root = GetTree().Root.GetChild(GetChildCount() - 1); + GD.Print(_root.GetChildren()); + } + + public void OnLoadScene(string path) + { + CallDeferred(nameof(DeferredGoToScene), path); + } + + private void DeferredGoToScene(string path) + { + var currentScene = _root.GetChild(_root.GetChildCount() - 1); + + var nextScene = (PackedScene)GD.Load(path); + + _root.RemoveChild(currentScene); + + currentScene = nextScene.Instantiate(); + + _root.AddChild(currentScene); + } +} diff --git a/Scripts/SoundEffects.cs b/Scripts/SoundEffects.cs new file mode 100644 index 0000000..5658649 --- /dev/null +++ b/Scripts/SoundEffects.cs @@ -0,0 +1,9 @@ +using Godot; + +public partial class SoundEffects : AudioStreamPlayer3D +{ + public void OnFireGun() + { + Play(); + } +} diff --git a/Scripts/Target.cs b/Scripts/Target.cs index 3b3b12e..f78b3e7 100644 --- a/Scripts/Target.cs +++ b/Scripts/Target.cs @@ -7,7 +7,7 @@ public partial class Target : StaticBody3D private int _currentHP; [Export] - private ProgressBar _progressBar; + private Healthbar _progressBar; public override void _Ready() { @@ -18,7 +18,7 @@ public partial class Target : StaticBody3D { _currentHP -= damage; GD.Print($"Current HP: {_currentHP}"); - _progressBar.Value = _currentHP; + _progressBar.Update(_currentHP, _maxHP); if (_currentHP <= 0) QueueFree(); diff --git a/project.godot b/project.godot index 640ec09..e3e20d7 100644 --- a/project.godot +++ b/project.godot @@ -11,9 +11,14 @@ config_version=5 [application] config/name="FPS" -run/main_scene="res://Scenes/Level.tscn" +run/main_scene="res://Scenes/Main.tscn" config/features=PackedStringArray("4.1", "C#", "Forward Plus") +[autoload] + +SceneHandler="*res://Scripts/SceneHandler.cs" +BgmPlayer="*res://Scripts/BGMPlayer.cs" + [dotnet] project/assembly_name="FPS"