lots of features

This commit is contained in:
2023-08-04 11:30:18 -07:00
parent d098cfb017
commit 339cb374b8
27 changed files with 427 additions and 36 deletions

BIN
Audio/BGM/Foothpath.mp3 Normal file

Binary file not shown.

View File

@@ -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

BIN
Audio/BGM/SeasidePalace.mp3 Normal file

Binary file not shown.

View File

@@ -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

BIN
Audio/SFX/gunshot.mp3 Normal file

Binary file not shown.

View File

@@ -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

View File

@@ -38,6 +38,7 @@ size = Vector2i(1152, 648)
render_target_update_mode = 4 render_target_update_mode = 4
[node name="Camera3D" type="Camera3D" parent="SubViewportContainer/SubViewport"] [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 cull_mask = 1047554
environment = ExtResource("1_3jquc") environment = ExtResource("1_3jquc")

View File

@@ -1,8 +0,0 @@
using Godot;
public partial class Healthbar : Sprite3D
{
public override void _Ready()
{
}
}

View File

@@ -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="Script" path="res://Scripts/Level1.cs" id="1_gvb28"]
[ext_resource type="PackedScene" uid="uid://cc5emorildoar" path="res://Scenes/Gun.tscn" id="2_mhg71"]
[ext_resource type="PackedScene" uid="uid://b03tplah8y1do" path="res://Scenes/target.tscn" id="3_civmh"] [ext_resource type="PackedScene" uid="uid://b03tplah8y1do" path="res://Scenes/target.tscn" id="3_civmh"]
[sub_resource type="BoxShape3D" id="BoxShape3D_gyf0l"] [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) albedo_color = Color(0, 0, 0, 1)
[sub_resource type="BoxMesh" id="BoxMesh_v2sg1"] [sub_resource type="BoxMesh" id="BoxMesh_v2sg1"]
material = SubResource("StandardMaterial3D_78bnu") material = SubResource("StandardMaterial3D_vca8v")
size = Vector3(20, 0.5, 20) 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="."] [node name="StaticBody3D" type="StaticBody3D" parent="."]
collision_mask = 0 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) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.189965, 0)
mesh = SubResource("BoxMesh_v2sg1") 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="."] [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) 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="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"]

6
Scenes/Main.tscn Normal file
View File

@@ -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")

17
Scenes/MainMenu.tscn Normal file
View File

@@ -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"]

View File

@@ -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="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="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="CapsuleShape3D" id="CapsuleShape3D_cxbex"]
[sub_resource type="CapsuleMesh" id="CapsuleMesh_7dxig"] [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")] [node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("_pivot")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.13331, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.13331, 0)
collision_layer = 5
script = ExtResource("1_jsq3s") script = ExtResource("1_jsq3s")
_mouseSensitivity = 0.07 _mouseSensitivity = 0.07
_pivot = NodePath("Pivot") _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) transform = Transform3D(0.125, 0, 0, 0, 0.125, 0, 0, 0, 0.125, 0, 0, 0)
target_position = Vector3(0, 0, -1000) 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="."] [node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
visible = false visible = false
mesh = SubResource("CapsuleMesh_7dxig") 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"]

57
Scenes/level_2.tscn Normal file
View File

@@ -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"]

View File

@@ -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="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"] [sub_resource type="BoxShape3D" id="BoxShape3D_37aka"]
@@ -12,7 +15,7 @@ material = SubResource("StandardMaterial3D_8nuxw")
[node name="Target" type="StaticBody3D" node_paths=PackedStringArray("_progressBar")] [node name="Target" type="StaticBody3D" node_paths=PackedStringArray("_progressBar")]
script = ExtResource("1_ykgyh") script = ExtResource("1_ykgyh")
_progressBar = NodePath("ProgressBar") _progressBar = NodePath("Sprite3D")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.12414, -3.96702) 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") mesh = SubResource("BoxMesh_ni5do")
skeleton = NodePath("") 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="."] [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")

17
Scripts/BGMPlayer.cs Normal file
View File

@@ -0,0 +1,17 @@
using Godot;
public partial class BGMPlayer : AudioStreamPlayer
{
public void SetBGMFromFilepath(string path)
{
var audioStream = ResourceLoader.Load<AudioStream>(path);
if (Stream != audioStream)
Stream = audioStream;
}
public void PlayBGM()
{
if (!Playing)
Play();
}
}

16
Scripts/Healthbar.cs Normal file
View File

@@ -0,0 +1,16 @@
using System.Linq;
using Godot;
public partial class Healthbar : Sprite3D
{
public override void _Ready()
{
Texture = GetChildren().OfType<SubViewport>().Single().GetTexture();
}
public void Update(int amount, int full)
{
var progressBar = GetChildren().ElementAt(0).GetChildren().OfType<HealthbarProgress>().Single();
progressBar.UpdateBar(amount, full);
}
}

View File

@@ -0,0 +1,9 @@
using Godot;
public partial class HealthbarProgress : TextureProgressBar
{
public void UpdateBar(int amount, int full)
{
Value = amount;
}
}

25
Scripts/Level1.cs Normal file
View File

@@ -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<CharacterBody3D>().Single();
player.Transform = _spawnPoint.Transform;
var bgmPlayer = GetNode<BGMPlayer>("/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<SceneHandler>("/root/SceneHandler");
sceneHandler.OnLoadScene("res://Scenes/level_2.tscn");
}
}

25
Scripts/Level2.cs Normal file
View File

@@ -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<CharacterBody3D>().Single();
player.Transform = _spawnPoint.Transform;
var bgmPlayer = GetNode<BGMPlayer>("/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");
}
}

11
Scripts/Main.cs Normal file
View File

@@ -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<PackedScene>("res://Scenes/MainMenu.tscn").Instantiate();
AddChild(mainMenuScene);
}
}

12
Scripts/MainMenu.cs Normal file
View File

@@ -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<PackedScene>("res://Scenes/Player.tscn").Instantiate();
GetTree().Root.AddChild(player);
}
}

View File

@@ -4,6 +4,8 @@ public partial class Player : CharacterBody3D
{ {
[Signal] [Signal]
public delegate void OnHitEventHandler(); public delegate void OnHitEventHandler();
[Signal]
public delegate void FireGunEventHandler();
public const float _speed = 5.0f; public const float _speed = 5.0f;
public const float _jumpVelocity = 4.5f; 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); _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()) if (@event.IsActionPressed("fire") && _aimCast.IsColliding())
{ {
EmitSignal(SignalName.OnHit); EmitSignal(SignalName.OnHit);
_aimCast.GetCollider().Call("OnHitEvent", 3); _aimCast.GetCollider().Call("OnHitEvent", 10);
} }
} }

18
Scripts/PlayerHUD.cs Normal file
View File

@@ -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";
}
}

31
Scripts/SceneHandler.cs Normal file
View File

@@ -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);
}
}

9
Scripts/SoundEffects.cs Normal file
View File

@@ -0,0 +1,9 @@
using Godot;
public partial class SoundEffects : AudioStreamPlayer3D
{
public void OnFireGun()
{
Play();
}
}

View File

@@ -7,7 +7,7 @@ public partial class Target : StaticBody3D
private int _currentHP; private int _currentHP;
[Export] [Export]
private ProgressBar _progressBar; private Healthbar _progressBar;
public override void _Ready() public override void _Ready()
{ {
@@ -18,7 +18,7 @@ public partial class Target : StaticBody3D
{ {
_currentHP -= damage; _currentHP -= damage;
GD.Print($"Current HP: {_currentHP}"); GD.Print($"Current HP: {_currentHP}");
_progressBar.Value = _currentHP; _progressBar.Update(_currentHP, _maxHP);
if (_currentHP <= 0) if (_currentHP <= 0)
QueueFree(); QueueFree();

View File

@@ -11,9 +11,14 @@ config_version=5
[application] [application]
config/name="FPS" 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") config/features=PackedStringArray("4.1", "C#", "Forward Plus")
[autoload]
SceneHandler="*res://Scripts/SceneHandler.cs"
BgmPlayer="*res://Scripts/BGMPlayer.cs"
[dotnet] [dotnet]
project/assembly_name="FPS" project/assembly_name="FPS"