From 9201ab67cf1390aaa944dc6c08633084f4ecdcdd Mon Sep 17 00:00:00 2001 From: LifeHckr Date: Mon, 7 Apr 2025 16:34:26 -0700 Subject: [PATCH] Handle Multiple Enemies Added handling for multiple enemies in a fight These changes can be made for a fight at the Config level Enemies now will finish their damage animation before becoming invisible and signaling for death. --- Classes/MidiMaestro/SongTemplate.cs | 4 +- Classes/Notes/Note.cs | 10 ++- Globals/FunkEngineNameSpace.cs | 10 ++- Globals/Scribe.cs | 29 +++++--- Globals/StageProducer.cs | 4 +- Scenes/BattleDirector/BattleScene.tscn | 21 ++++-- .../BattleDirector/Scripts/BattleDirector.cs | 67 ++++++++++++++----- Scenes/ChestScene/ChestScene.cs | 5 +- Scenes/ChestScene/ChestScene.tscn | 12 ++-- Scenes/Puppets/Enemies/BossBlood/Boss1.tscn | 21 +++--- .../Puppets/Enemies/Parasifly/Parasifly.tscn | 3 +- Scenes/Puppets/Enemies/TheGWS/GWS.tscn | 3 +- Scenes/Puppets/PlayerPuppet.tscn | 3 +- Scenes/Puppets/Scripts/PuppetTemplate.cs | 24 ++++--- 14 files changed, 150 insertions(+), 66 deletions(-) diff --git a/Classes/MidiMaestro/SongTemplate.cs b/Classes/MidiMaestro/SongTemplate.cs index bb967a59..cea1ba68 100644 --- a/Classes/MidiMaestro/SongTemplate.cs +++ b/Classes/MidiMaestro/SongTemplate.cs @@ -8,7 +8,7 @@ public struct SongTemplate public string Name; public readonly string AudioLocation; public string MIDILocation; - public readonly string EnemyScenePath; + public readonly string[] EnemyScenePath; public SongData SongData; public SongTemplate( @@ -16,7 +16,7 @@ public SongTemplate( string name = "", string audioLocation = "", string midiLocation = "", - string enemyScenePath = "" + string[] enemyScenePath = null ) { Name = name; diff --git a/Classes/Notes/Note.cs b/Classes/Notes/Note.cs index ef8bf758..57c463d7 100644 --- a/Classes/Notes/Note.cs +++ b/Classes/Notes/Note.cs @@ -12,6 +12,7 @@ public partial class Note : Resource, IDisplayable public string Name { get; set; } private int _baseVal; public float CostModifier { get; private set; } + public Targetting TargetType { get; private set; } private Action NoteEffect; public const double TimingMax = 0.5d; //The max range for a note to be timed is its beat +/- this const @@ -27,7 +28,8 @@ public Note( PuppetTemplate owner = null, int baseVal = 1, Action noteEffect = null, - float costModifier = 1.0f + float costModifier = 1.0f, + Targetting targetType = Targetting.First ) { Id = id; @@ -38,13 +40,17 @@ public Note( ?? ( (BD, source, timing) => { - BD.GetTarget(this).TakeDamage((int)timing * source._baseVal); + Array.ForEach( + BD.GetTargets(source), //Ok, sure + enemy => enemy.TakeDamage((int)timing * source._baseVal) + ); } ); _baseVal = baseVal; Texture = texture; Tooltip = tooltip; CostModifier = costModifier; + TargetType = targetType; } public void OnHit(BattleDirector BD, Timing timing) diff --git a/Globals/FunkEngineNameSpace.cs b/Globals/FunkEngineNameSpace.cs index 9901b057..f52af3de 100644 --- a/Globals/FunkEngineNameSpace.cs +++ b/Globals/FunkEngineNameSpace.cs @@ -34,7 +34,7 @@ public struct BattleConfig { public Stages RoomType; public MapGrid.Room BattleRoom; - public string EnemyScenePath; + public string[] EnemyScenePath; public SongTemplate CurSong; } @@ -222,6 +222,12 @@ public enum Timing Perfect = 4, } +public enum Targetting +{ + First, + All, +} + public enum BattleEffectTrigger { NotePlaced, @@ -262,7 +268,7 @@ public Room[] GetRooms() public class Room { public int Idx { get; private set; } - public int[] Children { get; private set; } = Array.Empty(); + public int[] Children { get; private set; } = []; public int X { get; private set; } public int Y { get; private set; } public Stages Type { get; private set; } diff --git a/Globals/Scribe.cs b/Globals/Scribe.cs index b148aab8..913cfe03 100644 --- a/Globals/Scribe.cs +++ b/Globals/Scribe.cs @@ -33,7 +33,7 @@ public partial class Scribe : Node { if (timing == Timing.Miss) return; - director.Enemy.TakeDamage((int)timing * note.GetBaseVal()); + director.GetFirstEnemy()?.TakeDamage((int)timing * note.GetBaseVal()); } ), new Note( @@ -47,7 +47,7 @@ public partial class Scribe : Node { if (timing == Timing.Miss) return; - director.Enemy.TakeDamage(note.GetBaseVal() * (int)timing); + director.GetFirstEnemy()?.TakeDamage(note.GetBaseVal() * (int)timing); } ), new Note( @@ -76,7 +76,7 @@ public partial class Scribe : Node if (timing == Timing.Miss) return; director.Player.Heal((int)timing * note.GetBaseVal()); - director.Enemy.TakeDamage((int)timing * note.GetBaseVal()); + director.GetFirstEnemy()?.TakeDamage((int)timing * note.GetBaseVal()); } ), new Note( @@ -90,7 +90,7 @@ public partial class Scribe : Node { if (timing == Timing.Miss) return; - director.Enemy.TakeDamage((int)timing + note.GetBaseVal()); + director.GetFirstEnemy()?.TakeDamage((int)timing + note.GetBaseVal()); }, 0.25f ), @@ -171,7 +171,7 @@ public partial class Scribe : Node ), }; - public static readonly SongTemplate[] SongDictionary = new[] + public static readonly SongTemplate[] SongDictionary = new[] //Generalize and make pools for areas/room types { new SongTemplate( new SongData @@ -182,7 +182,8 @@ public partial class Scribe : Node }, "Song1", "Audio/Song1.ogg", - "Audio/Midi/Song1.mid" + "Audio/Midi/Song1.mid", + [P_BossBlood.LoadPath] ), new SongTemplate( new SongData @@ -194,7 +195,19 @@ public partial class Scribe : Node "Song2", "Audio/Song2.ogg", "Audio/Midi/Song2.mid", - P_Parasifly.LoadPath + [P_Parasifly.LoadPath] + ), + new SongTemplate( + new SongData + { + Bpm = 60, + SongLength = -1, + NumLoops = 1, + }, + "Song2", + "Audio/Song2.ogg", + "Audio/Midi/Song2.mid", + [P_Parasifly.LoadPath, P_Parasifly.LoadPath] ), new SongTemplate( new SongData @@ -206,7 +219,7 @@ public partial class Scribe : Node "Song3", "Audio/Song3.ogg", "Audio/Midi/Song3.mid", - P_TheGWS.LoadPath + [P_TheGWS.LoadPath] ), }; diff --git a/Globals/StageProducer.cs b/Globals/StageProducer.cs index 64de9178..7aada393 100644 --- a/Globals/StageProducer.cs +++ b/Globals/StageProducer.cs @@ -195,12 +195,12 @@ private BattleConfig MakeBattleConfig(Stages nextRoom, int nextRoomIdx) switch (nextRoom) { case Stages.Battle: - int songIdx = stageRng.RandiRange(1, 2); + int songIdx = stageRng.RandiRange(1, 3); result.CurSong = Scribe.SongDictionary[songIdx]; result.EnemyScenePath = Scribe.SongDictionary[songIdx].EnemyScenePath; break; case Stages.Boss: - result.EnemyScenePath = P_BossBlood.LoadPath; + result.EnemyScenePath = Scribe.SongDictionary[0].EnemyScenePath; result.CurSong = Scribe.SongDictionary[0]; break; case Stages.Chest: diff --git a/Scenes/BattleDirector/BattleScene.tscn b/Scenes/BattleDirector/BattleScene.tscn index 6af6318e..379f741e 100644 --- a/Scenes/BattleDirector/BattleScene.tscn +++ b/Scenes/BattleDirector/BattleScene.tscn @@ -1,8 +1,8 @@ [gd_scene load_steps=10 format=3 uid="uid://b0mrgr7h0ty1y"] -[ext_resource type="Script" path="res://Scenes/BattleDirector/Scripts/BattleDirector.cs" id="1_jmdo1"] -[ext_resource type="Script" path="res://Scenes/UI/Scripts/MenuModule.cs" id="2_ka0ws"] -[ext_resource type="Script" path="res://Scenes/BattleDirector/Scripts/Conductor.cs" id="3_elcaj"] +[ext_resource type="Script" uid="uid://bttu0wmy2fp64" path="res://Scenes/BattleDirector/Scripts/BattleDirector.cs" id="1_jmdo1"] +[ext_resource type="Script" uid="uid://pl57giqyhckb" path="res://Scenes/UI/Scripts/MenuModule.cs" id="2_ka0ws"] +[ext_resource type="Script" uid="uid://tg14hkh1n7iv" path="res://Scenes/BattleDirector/Scripts/Conductor.cs" id="3_elcaj"] [ext_resource type="PackedScene" uid="uid://duhiilcv4tat3" path="res://Scenes/BattleDirector/NotePlacementBar.tscn" id="4_qk7om"] [ext_resource type="PackedScene" uid="uid://dfevfib11kou1" path="res://Scenes/ChartViewport/ChartViewport.tscn" id="5_r2xh0"] [ext_resource type="Texture2D" uid="uid://qhwve7fik4do" path="res://SharedAssets/BackGround_Full.png" id="6_0jtpx"] @@ -17,9 +17,10 @@ gradient = SubResource("Gradient_8uy3a") fill_from = Vector2(1, 0) fill_to = Vector2(0.738532, 1) -[node name="ProtoBattleDirector" type="Node2D" node_paths=PackedStringArray("CD", "CM", "NPB", "Audio", "_focusedButton")] +[node name="ProtoBattleDirector" type="Node2D" node_paths=PackedStringArray("PuppetMarkers", "CD", "CM", "NPB", "Audio", "_focusedButton")] process_mode = 1 script = ExtResource("1_jmdo1") +PuppetMarkers = [NodePath("PlayerMarker"), NodePath("Enemy1Marker"), NodePath("Enemy2Marker"), NodePath("Enemy3Marker")] CD = NodePath("Conductor") CM = NodePath("SubViewport") NPB = NodePath("NotePlacementBar") @@ -37,6 +38,18 @@ CurSceneNode = NodePath("..") script = ExtResource("3_elcaj") CM = NodePath("../SubViewport") +[node name="PlayerMarker" type="Marker2D" parent="."] +position = Vector2(158, 125) + +[node name="Enemy1Marker" type="Marker2D" parent="."] +position = Vector2(350, 125) + +[node name="Enemy2Marker" type="Marker2D" parent="."] +position = Vector2(450, 125) + +[node name="Enemy3Marker" type="Marker2D" parent="."] +position = Vector2(550, 125) + [node name="NotePlacementBar" parent="." instance=ExtResource("4_qk7om")] offset_top = 183.0 offset_bottom = 183.0 diff --git a/Scenes/BattleDirector/Scripts/BattleDirector.cs b/Scenes/BattleDirector/Scripts/BattleDirector.cs index 0115775f..88ab9e13 100644 --- a/Scenes/BattleDirector/Scripts/BattleDirector.cs +++ b/Scenes/BattleDirector/Scripts/BattleDirector.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using FunkEngine; using Godot; using Melanchall.DryWetMidi.Interaction; @@ -12,7 +13,10 @@ public partial class BattleDirector : Node2D public static readonly string LoadPath = "res://Scenes/BattleDirector/BattleScene.tscn"; public PlayerPuppet Player; - public EnemyPuppet Enemy; + private EnemyPuppet[] _enemies; + + [Export] + public Marker2D[] PuppetMarkers = new Marker2D[4]; //[0] is always player [Export] private Conductor CD; @@ -49,14 +53,31 @@ private bool PlayerAddNote(ArrowType type, Beat beat) return true; } - public PuppetTemplate GetTarget(Note note) + public PuppetTemplate[] GetTargets(Note note) + { + if (!note.IsPlayerNote()) + return [Player]; + switch (note.TargetType) + { + case Targetting.First: + if (GetFirstEnemy() != null) + return [GetFirstEnemy()]; + return []; + case Targetting.All: + return _enemies.Where(x => x.GetCurrentHealth() > 0).ToArray(); + } + return null; + } + + public PuppetTemplate GetFirstEnemy() { - if (note.Owner == Player) + foreach (var enemy in _enemies) { - return Enemy; + if (enemy.GetCurrentHealth() > 0) + return enemy; } - return Player; + return null; } #endregion @@ -99,7 +120,7 @@ public override void _Ready() private void InitPlayer() { Player = GD.Load(PlayerPuppet.LoadPath).Instantiate(); - AddChild(Player); + PuppetMarkers[0].AddChild(Player); Player.Defeated += CheckBattleStatus; EventizeRelics(); NPB.Setup(StageProducer.PlayerStats); @@ -108,11 +129,19 @@ private void InitPlayer() private void InitEnemies() { //TODO: Refine - Enemy = GD.Load(StageProducer.Config.EnemyScenePath) - .Instantiate(); - AddChild(Enemy); - Enemy.Defeated += CheckBattleStatus; - AddEnemyEffects(); + _enemies = new EnemyPuppet[StageProducer.Config.EnemyScenePath.Length]; + for (int i = 0; i < StageProducer.Config.EnemyScenePath.Length; i++) + { + EnemyPuppet enemy = GD.Load(StageProducer.Config.EnemyScenePath[0]) + .Instantiate(); + if (_enemies.Length == 1) + PuppetMarkers[2].AddChild(enemy); + else + PuppetMarkers[i + 1].AddChild(enemy); + enemy.Defeated += CheckBattleStatus; + _enemies[i] = enemy; + AddEnemyEffects(enemy); + } } public override void _Process(double delta) @@ -207,10 +236,15 @@ private void CheckBattleStatus(PuppetTemplate puppet) //Called when a puppet die OnBattleLost(); return; } - if (puppet == Enemy) + if (puppet is EnemyPuppet && IsBattleWon()) OnBattleWon(); //will have to adjust this to account for when we have multiple enemies at once } + private bool IsBattleWon() + { + return GetFirstEnemy() == null; + } + private void OnBattleWon() { Audio.StreamPaused = true; @@ -258,9 +292,9 @@ private void AddEvent(IBattleEvent bEvent) } } - private void AddEnemyEffects() + private void AddEnemyEffects(EnemyPuppet enemy) { - foreach (var effect in Enemy.GetBattleEvents()) + foreach (var effect in enemy.GetBattleEvents()) { AddEvent(effect); } @@ -347,6 +381,9 @@ public void InvokeChartLoop(int incLoop) private void DebugKillEnemy() { - Enemy.TakeDamage(1000); + foreach (EnemyPuppet enemy in _enemies) + { + enemy.TakeDamage(1000); + } } } diff --git a/Scenes/ChestScene/ChestScene.cs b/Scenes/ChestScene/ChestScene.cs index 96e1b977..8d32acbf 100644 --- a/Scenes/ChestScene/ChestScene.cs +++ b/Scenes/ChestScene/ChestScene.cs @@ -12,10 +12,13 @@ public partial class ChestScene : Node2D [Export] public Button ChestButton; + [Export] + public Marker2D PlayerMarker; + public override void _Ready() { _player = GD.Load(PlayerPuppet.LoadPath).Instantiate(); - AddChild(_player); + PlayerMarker.AddChild(_player); ChestButton.Pressed += GetLoot; } diff --git a/Scenes/ChestScene/ChestScene.tscn b/Scenes/ChestScene/ChestScene.tscn index d81450a4..796342d5 100644 --- a/Scenes/ChestScene/ChestScene.tscn +++ b/Scenes/ChestScene/ChestScene.tscn @@ -1,9 +1,9 @@ [gd_scene load_steps=9 format=3 uid="uid://c4vmb783d3v03"] -[ext_resource type="Script" path="res://Scenes/ChestScene/ChestScene.cs" id="1_ardd2"] +[ext_resource type="Script" uid="uid://cetn71kolbrmg" path="res://Scenes/ChestScene/ChestScene.cs" id="1_ardd2"] [ext_resource type="AudioStream" uid="uid://be5ial13ynf3o" path="res://Audio/Song1.ogg" id="2_x78jo"] -[ext_resource type="Script" path="res://Scenes/UI/Scripts/MenuModule.cs" id="3_5uvci"] -[ext_resource type="Shader" path="res://SharedAssets/StarryNight.gdshader" id="5_whthd"] +[ext_resource type="Script" uid="uid://pl57giqyhckb" path="res://Scenes/UI/Scripts/MenuModule.cs" id="3_5uvci"] +[ext_resource type="Shader" uid="uid://dp36iuuy414k1" path="res://SharedAssets/StarryNight.gdshader" id="5_whthd"] [ext_resource type="Texture2D" uid="uid://qhwve7fik4do" path="res://SharedAssets/BackGround_Full.png" id="6_37nar"] [ext_resource type="Texture2D" uid="uid://d0ywqw1j1k71v" path="res://Scenes/ChestScene/Assets/Chest.png" id="6_58hf4"] [ext_resource type="Texture2D" uid="uid://dbjotl0v1ymia" path="res://SharedAssets/BattleFrame1.png" id="7_kkck7"] @@ -15,10 +15,11 @@ shader_parameter/bg_bottom_color = Vector4(0.028, 0.008, 0.184, 0) shader_parameter/gradient_ratio = 1.0 shader_parameter/time_scale = 1.0 -[node name="ChestScene" type="Node2D" node_paths=PackedStringArray("ChestButton")] +[node name="ChestScene" type="Node2D" node_paths=PackedStringArray("ChestButton", "PlayerMarker")] process_mode = 1 script = ExtResource("1_ardd2") ChestButton = NodePath("ChestButton") +PlayerMarker = NodePath("PlayerMarker") [node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] stream = ExtResource("2_x78jo") @@ -28,6 +29,9 @@ autoplay = true script = ExtResource("3_5uvci") CurSceneNode = NodePath("..") +[node name="PlayerMarker" type="Marker2D" parent="."] +position = Vector2(158, 125) + [node name="BackGround" type="TextureRect" parent="."] z_index = -1 offset_right = 640.0 diff --git a/Scenes/Puppets/Enemies/BossBlood/Boss1.tscn b/Scenes/Puppets/Enemies/BossBlood/Boss1.tscn index 23d842c9..421588d7 100644 --- a/Scenes/Puppets/Enemies/BossBlood/Boss1.tscn +++ b/Scenes/Puppets/Enemies/BossBlood/Boss1.tscn @@ -1,10 +1,18 @@ [gd_scene load_steps=8 format=3 uid="uid://bi5iqbwpsd381"] -[ext_resource type="Script" path="res://Scenes/Puppets/Enemies/BossBlood/P_BossBlood.cs" id="1_qj2oj"] +[ext_resource type="Script" uid="uid://bpyrrnhvisxgv" path="res://Scenes/Puppets/Enemies/BossBlood/P_BossBlood.cs" id="1_qj2oj"] [ext_resource type="Texture2D" uid="uid://veedngaorx3l" path="res://Scenes/Puppets/Enemies/BossBlood/Assets/Boss1.png" id="2_mul30"] [ext_resource type="Texture2D" uid="uid://b2iptr3o8rg4t" path="res://Scenes/Puppets/Enemies/BossBlood/Assets/Boss1EmissionShape.tres" id="3_yxnso"] [ext_resource type="PackedScene" uid="uid://bgomxovxs7sr8" path="res://Scenes/Puppets/HealthBar.tscn" id="4_ffkxf"] +[sub_resource type="Gradient" id="Gradient_s7p55"] +offsets = PackedFloat32Array(0) +colors = PackedColorArray(0.641048, 0.0406094, 0.0473231, 1) + +[sub_resource type="GradientTexture1D" id="GradientTexture1D_16sp0"] +gradient = SubResource("Gradient_s7p55") +width = 1 + [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_3jiu6"] emission_shape = 4 emission_point_texture = ExtResource("3_yxnso") @@ -14,19 +22,10 @@ scale_min = 4.0 scale_max = 4.0 turbulence_noise_strength = 14.2 -[sub_resource type="Gradient" id="Gradient_s7p55"] -offsets = PackedFloat32Array(0) -colors = PackedColorArray(0.641048, 0.0406094, 0.0473231, 1) - -[sub_resource type="GradientTexture1D" id="GradientTexture1D_16sp0"] -gradient = SubResource("Gradient_s7p55") -width = 1 - [node name="EnemPuppet" type="Node2D" node_paths=PackedStringArray("HealthBar", "Sprite")] script = ExtResource("1_qj2oj") HealthBar = NodePath("ProgressBar") Sprite = NodePath("Sprite") -StartPos = Vector2(500, 125) InitScale = Vector2(2, 2) [node name="Sprite" type="Sprite2D" parent="."] @@ -37,10 +36,10 @@ texture = ExtResource("2_mul30") z_index = -1 position = Vector2(-32, -32) amount = 4 -process_material = SubResource("ParticleProcessMaterial_3jiu6") texture = SubResource("GradientTexture1D_16sp0") lifetime = 2.0 trail_lifetime = 10.0 +process_material = SubResource("ParticleProcessMaterial_3jiu6") [node name="ProgressBar" parent="." instance=ExtResource("4_ffkxf")] offset_left = -75.0 diff --git a/Scenes/Puppets/Enemies/Parasifly/Parasifly.tscn b/Scenes/Puppets/Enemies/Parasifly/Parasifly.tscn index 16d9e161..252c3d1c 100644 --- a/Scenes/Puppets/Enemies/Parasifly/Parasifly.tscn +++ b/Scenes/Puppets/Enemies/Parasifly/Parasifly.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=4 format=3 uid="uid://uvlux4t6h5de"] -[ext_resource type="Script" path="res://Scenes/Puppets/Enemies/Parasifly/P_Parasifly.cs" id="1_ci2ca"] +[ext_resource type="Script" uid="uid://btaqgieybx0ep" path="res://Scenes/Puppets/Enemies/Parasifly/P_Parasifly.cs" id="1_ci2ca"] [ext_resource type="Texture2D" uid="uid://pngu3pw1pu4o" path="res://Scenes/Puppets/Enemies/Parasifly/Assets/Parasifly.png" id="2_g4o48"] [ext_resource type="PackedScene" uid="uid://bgomxovxs7sr8" path="res://Scenes/Puppets/HealthBar.tscn" id="3_f74ri"] @@ -8,7 +8,6 @@ script = ExtResource("1_ci2ca") HealthBar = NodePath("ProgressBar") Sprite = NodePath("Sprite") -StartPos = Vector2(500, 125) [node name="Sprite" type="Sprite2D" parent="."] position = Vector2(0, -12) diff --git a/Scenes/Puppets/Enemies/TheGWS/GWS.tscn b/Scenes/Puppets/Enemies/TheGWS/GWS.tscn index 47fd865d..1859a3e3 100644 --- a/Scenes/Puppets/Enemies/TheGWS/GWS.tscn +++ b/Scenes/Puppets/Enemies/TheGWS/GWS.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=4 format=3 uid="uid://d1puw6fvmkrb5"] -[ext_resource type="Script" path="res://Scenes/Puppets/Enemies/TheGWS/P_TheGWS.cs" id="1_dlike"] +[ext_resource type="Script" uid="uid://3axgcdtdevtx" path="res://Scenes/Puppets/Enemies/TheGWS/P_TheGWS.cs" id="1_dlike"] [ext_resource type="Texture2D" uid="uid://ci0a2h2eatjht" path="res://Scenes/Puppets/Enemies/TheGWS/Assets/GhostWolfSnake.png" id="2_77v4w"] [ext_resource type="PackedScene" uid="uid://bgomxovxs7sr8" path="res://Scenes/Puppets/HealthBar.tscn" id="3_mr0it"] @@ -8,7 +8,6 @@ script = ExtResource("1_dlike") HealthBar = NodePath("ProgressBar") Sprite = NodePath("Sprite") -StartPos = Vector2(500, 125) [node name="Sprite" type="Sprite2D" parent="."] position = Vector2(0, -54) diff --git a/Scenes/Puppets/PlayerPuppet.tscn b/Scenes/Puppets/PlayerPuppet.tscn index 56b14d44..13610852 100644 --- a/Scenes/Puppets/PlayerPuppet.tscn +++ b/Scenes/Puppets/PlayerPuppet.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=4 format=3 uid="uid://eus17omen6yk"] -[ext_resource type="Script" path="res://Scenes/Puppets/Scripts/PlayerPuppet.cs" id="1_f4rea"] +[ext_resource type="Script" uid="uid://kkb4qp3s86n3" path="res://Scenes/Puppets/Scripts/PlayerPuppet.cs" id="1_f4rea"] [ext_resource type="Texture2D" uid="uid://b6fkei0i83vte" path="res://SharedAssets/Character1.png" id="2_affso"] [ext_resource type="PackedScene" uid="uid://bgomxovxs7sr8" path="res://Scenes/Puppets/HealthBar.tscn" id="3_rechw"] @@ -8,7 +8,6 @@ script = ExtResource("1_f4rea") HealthBar = NodePath("ProgressBar") Sprite = NodePath("Sprite") -StartPos = Vector2(158, 125) [node name="Sprite" type="Sprite2D" parent="."] texture = ExtResource("2_affso") diff --git a/Scenes/Puppets/Scripts/PuppetTemplate.cs b/Scenes/Puppets/Scripts/PuppetTemplate.cs index d30edc3d..1f053c4a 100644 --- a/Scenes/Puppets/Scripts/PuppetTemplate.cs +++ b/Scenes/Puppets/Scripts/PuppetTemplate.cs @@ -16,15 +16,14 @@ public partial class PuppetTemplate : Node2D [Export] public Sprite2D Sprite; - [Export] - public Vector2 StartPos; //158, 126 - [Export] public Vector2 InitScale = Vector2.One; [Export] public bool HideHealth; + private Vector2 _startPos; + protected int MaxHealth = 100; protected int CurrentHealth = 100; @@ -35,7 +34,7 @@ public partial class PuppetTemplate : Node2D public override void _Ready() { HealthBar.SetHealth(MaxHealth, CurrentHealth); - Position = StartPos; + _startPos = Position; Sprite.Scale = InitScale; HealthBar.Visible = !HideHealth; @@ -71,14 +70,14 @@ private void ProcessShake(double delta) _shakeStrength = (float)Mathf.Lerp(_shakeStrength, 0, _shakeFade * delta); } Position = - StartPos + _startPos + new Vector2( (float)GD.RandRange(-_shakeStrength, _shakeStrength), (float)GD.RandRange(-_shakeStrength, _shakeStrength) ); } - protected virtual void DamageAnimate(int amount) + protected virtual Tween DamageAnimate(int amount) { //TODO: Make animate in time with bpm float damageAnimDir = (GetViewportRect().Size / 2 - Position).Normalized().X; float scalar = (float)amount / MaxHealth; @@ -105,7 +104,14 @@ protected virtual void DamageAnimate(int amount) _baseAnimDuration ) .AsRelative(); - tween.Chain().TweenProperty(this, "position", StartPos, 2 * _baseAnimDuration); + tween.Chain().TweenProperty(this, "position", _startPos, 2 * _baseAnimDuration); + return tween; + } + + protected virtual void Kill() + { + Defeated?.Invoke(this); + Visible = false; } #endregion @@ -115,10 +121,10 @@ public virtual void TakeDamage(int amount) if (CurrentHealth <= 0 || amount == 0) return; //Only check if hp would change CurrentHealth = HealthBar.ChangeHP(-amount); - DamageAnimate(amount); + Tween deathTween = DamageAnimate(amount); if (CurrentHealth <= 0) { - Defeated?.Invoke(this); + deathTween.TweenCallback(Callable.From(Kill)); } TextParticle newText = new TextParticle(); newText.Modulate = Colors.Red;