From 5d2b9ca2470a83a5aaa4fe70e7b082d577a56d79 Mon Sep 17 00:00:00 2001 From: Zenny Date: Sat, 21 Dec 2024 16:41:16 -0800 Subject: [PATCH] Exp system implementation (not yet affecting stats) --- src/enemy/EnemyStatResource.cs | 3 ++ src/enemy/enemy_types/michael/Michael.tscn | 1 + src/enemy/enemy_types/sproingy/Sproingy.tscn | 1 + src/game/Game.cs | 6 ++++ src/inventory_menu/InventoryMenu.cs | 2 +- src/inventory_menu/InventoryMenu.tscn | 6 ++-- src/player/Player.cs | 32 ++++++++++++++++++++ src/player/Player.tscn | 2 +- src/player/PlayerData.cs | 3 +- src/vfx/shaders/PixelMelt.gdshader | 2 +- 10 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/enemy/EnemyStatResource.cs b/src/enemy/EnemyStatResource.cs index 0fc7420e..82c26f82 100644 --- a/src/enemy/EnemyStatResource.cs +++ b/src/enemy/EnemyStatResource.cs @@ -23,6 +23,9 @@ namespace GameJamDungeon [Export] public int MaxDefense { get; set; } + [Export] + public int ExpFromDefeat { get; set; } + [Export] public double Luck { get; set; } = 0.05f; diff --git a/src/enemy/enemy_types/michael/Michael.tscn b/src/enemy/enemy_types/michael/Michael.tscn index 79d82ac1..a461d5c8 100644 --- a/src/enemy/enemy_types/michael/Michael.tscn +++ b/src/enemy/enemy_types/michael/Michael.tscn @@ -12,6 +12,7 @@ CurrentAttack = 20 CurrentDefense = 11 MaxAttack = 20 MaxDefense = 11 +ExpFromDefeat = 10 Luck = 0.05 TelluricResistance = 0.0 AeolicResistance = 0.0 diff --git a/src/enemy/enemy_types/sproingy/Sproingy.tscn b/src/enemy/enemy_types/sproingy/Sproingy.tscn index b6ac278e..2f62f1e2 100644 --- a/src/enemy/enemy_types/sproingy/Sproingy.tscn +++ b/src/enemy/enemy_types/sproingy/Sproingy.tscn @@ -12,6 +12,7 @@ CurrentAttack = 20 CurrentDefense = 10 MaxAttack = 20 MaxDefense = 10 +ExpFromDefeat = 8 Luck = 0.05 TelluricResistance = 0.0 AeolicResistance = 0.0 diff --git a/src/game/Game.cs b/src/game/Game.cs index 9577295d..374baf7d 100644 --- a/src/game/Game.cs +++ b/src/game/Game.cs @@ -173,6 +173,12 @@ public partial class Game : Node3D, IGame } private void OnEnemyDefeated(Vector3 vector, EnemyStatResource resource) + { + GameRepo.PlayerData.SetCurrentExp(GameRepo.PlayerData.CurrentExp.Value + resource.ExpFromDefeat); + DropRestorative(vector); + } + + private void DropRestorative(Vector3 vector) { var restorativeScene = GD.Load("res://src/items/restorative/Restorative.tscn"); var restorative = restorativeScene.Instantiate(); diff --git a/src/inventory_menu/InventoryMenu.cs b/src/inventory_menu/InventoryMenu.cs index b71729b3..450cd73d 100644 --- a/src/inventory_menu/InventoryMenu.cs +++ b/src/inventory_menu/InventoryMenu.cs @@ -244,7 +244,7 @@ public partial class InventoryMenu : Control, IInventoryMenu private void PopulatePlayerInfo() { - FloorLabel.Text = $"Level {GameRepo.CurrentFloor:D2}"; + FloorLabel.Text = $"Floor {GameRepo.CurrentFloor:D2}"; if (ItemSlots.Any()) { diff --git a/src/inventory_menu/InventoryMenu.tscn b/src/inventory_menu/InventoryMenu.tscn index 5d493982..703873ad 100644 --- a/src/inventory_menu/InventoryMenu.tscn +++ b/src/inventory_menu/InventoryMenu.tscn @@ -158,8 +158,8 @@ tracks/1/keys = { [sub_resource type="AnimationLibrary" id="AnimationLibrary_eivo2"] _data = { -"RESET": SubResource("Animation_dg155"), -"status_up": SubResource("Animation_7by7u") +&"RESET": SubResource("Animation_dg155"), +&"status_up": SubResource("Animation_7by7u") } [node name="InventoryMenu" type="Control"] @@ -552,5 +552,5 @@ layout_mode = 2 [node name="AnimationPlayer" type="AnimationPlayer" parent="."] unique_name_in_owner = true libraries = { -"": SubResource("AnimationLibrary_eivo2") +&"": SubResource("AnimationLibrary_eivo2") } diff --git a/src/player/Player.cs b/src/player/Player.cs index 9811eae8..11897140 100644 --- a/src/player/Player.cs +++ b/src/player/Player.cs @@ -3,6 +3,7 @@ using Chickensoft.GodotNodeInterfaces; using Chickensoft.Introspection; using Chickensoft.SaveFileBuilder; using Godot; +using Godot.Collections; namespace GameJamDungeon { @@ -18,6 +19,8 @@ namespace GameJamDungeon public void ApplyCentralImpulseToPlayer(Vector3 velocity); + public void LevelUp(); + event Player.InventoryButtonPressedEventHandler InventoryButtonPressed; event Player.MinimapButtonHeldEventHandler MinimapButtonHeld; event Player.PauseButtonPressedEventHandler PauseButtonPressed; @@ -81,9 +84,21 @@ namespace GameJamDungeon private float _knockbackStrength = 0.0f; private Vector3 _knockbackDirection = Vector3.Zero; + private Dictionary _expToNextLevel; + public void Initialize() { AnimationPlayer.AnimationFinished += OnAnimationFinished; + _expToNextLevel = new Dictionary + { + { 2, 12 }, + { 3, 39 }, + { 4, 87 }, + { 5, 162 }, + { 6, 270 }, + { 7, 417 }, + { 8, 609 } + }; } public void Setup() @@ -128,6 +143,7 @@ namespace GameJamDungeon PlayerData.Inventory.EquippedAccessory.Sync += EquippedAccessory_Sync; PlayerData.CurrentHP.Sync += CurrentHP_Sync; + PlayerData.CurrentExp.Sync += CurrentEXP_Sync; HealthTimer.WaitTime = _healthTimerWaitTime; } @@ -170,6 +186,16 @@ namespace GameJamDungeon SetPhysicsProcess(true); } + public void LevelUp() + { + var nextLevel = PlayerData.CurrentLevel.Value + 1; + var expToNextLevel = _expToNextLevel[nextLevel]; + var newCurrentExp = Mathf.Max(PlayerData.CurrentExp.Value - PlayerData.ExpToNextLevel.Value, 0); + PlayerData.SetCurrentLevel(nextLevel); + PlayerData.SetExpToNextLevel(expToNextLevel); + PlayerData.SetCurrentExp(newCurrentExp); + } + public override void _UnhandledInput(InputEvent @event) { if (@event.IsActionPressed(GameInputs.Inventory)) @@ -316,5 +342,11 @@ namespace GameJamDungeon if (newHealth <= 0) Kill(); } + + private void CurrentEXP_Sync(int newExp) + { + if (PlayerData.CurrentExp.Value >= PlayerData.ExpToNextLevel.Value) + LevelUp(); + } } } diff --git a/src/player/Player.tscn b/src/player/Player.tscn index 43fe03dc..0cb0237b 100644 --- a/src/player/Player.tscn +++ b/src/player/Player.tscn @@ -20,7 +20,7 @@ MaximumHP = 100 CurrentVT = 90 MaximumVT = 90 CurrentExp = 0 -ExpToNextLevel = 100 +ExpToNextLevel = 10 CurrentLevel = 1 CurrentAttack = 50 CurrentDefense = 12 diff --git a/src/player/PlayerData.cs b/src/player/PlayerData.cs index 2ced939d..99b76bfa 100644 --- a/src/player/PlayerData.cs +++ b/src/player/PlayerData.cs @@ -63,8 +63,7 @@ namespace GameJamDungeon } public void SetCurrentExp(int newValue) { - var clampedValue = Mathf.Clamp(newValue, 0, ExpToNextLevel.Value); - _currentExp.OnNext(clampedValue); + _currentExp.OnNext(newValue); } public void SetCurrentLevel(int newValue) { diff --git a/src/vfx/shaders/PixelMelt.gdshader b/src/vfx/shaders/PixelMelt.gdshader index b8ac5643..2c123e75 100644 --- a/src/vfx/shaders/PixelMelt.gdshader +++ b/src/vfx/shaders/PixelMelt.gdshader @@ -20,7 +20,7 @@ void fragment() { uv.y += progress / UV.y; else uv.y -= progress / UV.y; - + // Created jagged edges for each pixel on the x-axis uv.y -= progress * meltiness * psuedo_rand(UV.x - mod(UV.x, TEXTURE_PIXEL_SIZE.x));