lots of features
This commit is contained in:
17
Scripts/BGMPlayer.cs
Normal file
17
Scripts/BGMPlayer.cs
Normal 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
16
Scripts/Healthbar.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
9
Scripts/HealthbarProgress.cs
Normal file
9
Scripts/HealthbarProgress.cs
Normal 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
25
Scripts/Level1.cs
Normal 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
25
Scripts/Level2.cs
Normal 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
11
Scripts/Main.cs
Normal 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
12
Scripts/MainMenu.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
Scripts/PlayerHUD.cs
Normal file
18
Scripts/PlayerHUD.cs
Normal 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
31
Scripts/SceneHandler.cs
Normal 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
9
Scripts/SoundEffects.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Godot;
|
||||
|
||||
public partial class SoundEffects : AudioStreamPlayer3D
|
||||
{
|
||||
public void OnFireGun()
|
||||
{
|
||||
Play();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user