Skip to content

Commit 8e3ab6c

Browse files
authored
Merge branch 'Sprint-2' into note-effects
2 parents 9567f84 + ee4dc88 commit 8e3ab6c

File tree

13 files changed

+361
-23
lines changed

13 files changed

+361
-23
lines changed

Globals/Scribe.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using FunkEngine;
34
using Godot;
45

@@ -42,6 +43,20 @@ public partial class Scribe : Node
4243

4344
public static readonly RelicTemplate[] RelicDictionary = new[]
4445
{
46+
new RelicTemplate(
47+
"Breakfast", //Reference ha ha, Item to give when relic pool is empty.
48+
new RelicEffect[]
49+
{
50+
new RelicEffect(
51+
BattleEffectTrigger.NotePlaced,
52+
1,
53+
(director, val) =>
54+
{
55+
director.Player.Heal(val);
56+
}
57+
),
58+
}
59+
),
4560
new RelicTemplate(
4661
"Good Vibes",
4762
new RelicEffect[]
@@ -56,5 +71,40 @@ public partial class Scribe : Node
5671
),
5772
}
5873
),
74+
new RelicTemplate(
75+
"Dummy Item",
76+
new RelicEffect[]
77+
{
78+
new RelicEffect(
79+
BattleEffectTrigger.NotePlaced,
80+
100,
81+
(director, val) =>
82+
{
83+
director.Player.Heal(val);
84+
}
85+
),
86+
}
87+
),
5988
};
89+
90+
//TODO: Item pool(s)
91+
92+
public static RelicTemplate[] GetRandomRelics(RelicTemplate[] ownedRelics, int count)
93+
{
94+
var availableRelics = Scribe
95+
.RelicDictionary.Where(r => !ownedRelics.Any(o => o.Name == r.Name))
96+
.ToArray();
97+
98+
availableRelics = availableRelics
99+
.OrderBy(_ => StageProducer.GlobalRng.Randi())
100+
.Take(count)
101+
.Select(r => r.Clone())
102+
.ToArray();
103+
104+
for (int i = availableRelics.Length; i < count; i++)
105+
{
106+
availableRelics = availableRelics.Append(RelicDictionary[0].Clone()).ToArray();
107+
}
108+
return availableRelics;
109+
}
60110
}

Globals/StageProducer.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public partial class StageProducer : Node
1616

1717
private MapGrid _map = new MapGrid();
1818

19+
//Hold here to persist between changes
20+
//TODO: Allow for permanent changes and battle temporary stat changes.
21+
public static PlayerStats PlayerStats;
22+
1923
public class MapGrid
2024
{
2125
private int[,] _map;
@@ -108,6 +112,7 @@ public void StartGame()
108112
_map.InitMapGrid(2, 2, 1);
109113
_seed = GlobalRng.Seed;
110114
_lastRngState = GlobalRng.State;
115+
PlayerStats = new PlayerStats();
111116
}
112117

113118
public void TransitionStage(Stages nextStage)
@@ -119,8 +124,16 @@ public void TransitionStage(Stages nextStage)
119124
GetTree().ChangeSceneToFile("res://scenes/SceneTransitions/TitleScreen.tscn");
120125
break;
121126
case Stages.Battle:
127+
StartGame();
122128
GetTree().ChangeSceneToFile("res://scenes/BattleDirector/test_battle_scene.tscn");
123129
break;
130+
case Stages.Quit:
131+
GD.Print("Exiting game");
132+
GetTree().Quit();
133+
return;
134+
default:
135+
GD.Print($"Error Scene Transition is {nextStage}");
136+
break;
124137
}
125138

126139
_curStage = nextStage;

project.godot

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ arrowRight={
5858
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
5959
]
6060
}
61+
Pause={
62+
"deadzone": 0.5,
63+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
64+
]
65+
}
6166

6267
[rendering]
6368

scenes/BattleDirector/scripts/BattleDirector.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public override void _Ready()
8484

8585
Player = new PlayerPuppet();
8686
AddChild(Player);
87+
Player.Defeated += CheckBattleStatus;
8788
EventizeRelics();
8889
//TODO: Refine
8990
foreach (var note in Player.Stats.CurNotes)
@@ -97,6 +98,7 @@ public override void _Ready()
9798
Enemy = new PuppetTemplate();
9899
Enemy.SetPosition(new Vector2(400, 0));
99100
AddChild(Enemy);
101+
Enemy.Defeated += CheckBattleStatus;
100102
Enemy.Init(GD.Load<Texture2D>("res://scenes/BattleDirector/assets/Enemy1.png"), "Enemy");
101103
Enemy.Sprite.Scale *= 2;
102104

@@ -134,6 +136,26 @@ public override void _Process(double delta)
134136
#endregion
135137

136138
#region Input&Timing
139+
140+
public override void _UnhandledInput(InputEvent @event)
141+
{
142+
//this one is for calling a debug key to insta-kill the enemy
143+
if (@event is InputEventKey eventKey && eventKey.Pressed && !eventKey.Echo)
144+
{
145+
if (eventKey.Keycode == Key.Key0)
146+
{
147+
DebugKillEnemy();
148+
}
149+
}
150+
151+
if (@event.IsActionPressed("Pause"))
152+
{
153+
var pauseMenu = GD.Load<PackedScene>("res://scenes/UI/Pause.tscn");
154+
GetNode<CanvasLayer>("UILayer").AddChild(pauseMenu.Instantiate());
155+
GetTree().Paused = true;
156+
}
157+
}
158+
137159
private void OnNotePressed(ArrowType type)
138160
{
139161
CD.CheckNoteTiming(type);
@@ -186,6 +208,31 @@ private Timing CheckTiming(double beatDif)
186208
return Timing.Miss;
187209
}
188210

211+
private void CheckBattleStatus(PuppetTemplate puppet)
212+
{
213+
if (puppet == Player)
214+
{
215+
GD.Print("Player is Dead");
216+
return;
217+
}
218+
219+
//will have to adjust this to account for when we have multiple enemies at once
220+
if (puppet == Enemy)
221+
{
222+
GD.Print("Enemy is dead");
223+
ShowRewardSelection(3);
224+
}
225+
}
226+
227+
private void ShowRewardSelection(int amount)
228+
{
229+
var rewardUI = GD.Load<PackedScene>("res://scenes/UI/RewardSelectionUI.tscn")
230+
.Instantiate<RewardSelect>();
231+
AddChild(rewardUI);
232+
rewardUI.Initialize(Player.Stats, amount);
233+
GetTree().Paused = true;
234+
}
235+
189236
#endregion
190237

191238
#region BattleEffect Handling
@@ -210,4 +257,9 @@ private void EventizeRelics()
210257
}
211258
}
212259
#endregion
260+
261+
private void DebugKillEnemy()
262+
{
263+
Enemy.TakeDamage(1000);
264+
}
213265
}

scenes/BattleDirector/test_battle_scene.tscn

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
[ext_resource type="PackedScene" uid="uid://duhiilcv4tat3" path="res://scenes/BattleDirector/NotePlacementBar.tscn" id="7_3ko4g"]
88
[ext_resource type="PackedScene" uid="uid://bvhpon5liybd1" path="res://scenes/CustomNotes/NoteQueue.tscn" id="8_7wwxo"]
99
[ext_resource type="AudioStream" uid="uid://cv6lqjj6lu36h" path="res://Audio/335571__magntron__gamemusic_120bpm.mp3" id="8_caqms"]
10-
[ext_resource type="Script" path="res://scenes/SceneTransitions/scripts/SceneChange.cs" id="9_bxa6e"]
1110

1211
[node name="ProtoBattleDirector" type="Node2D" node_paths=PackedStringArray("CM", "NotePlacementBar", "CD", "Audio", "NQ")]
12+
process_mode = 1
1313
script = ExtResource("1_cwqqr")
1414
CM = NodePath("SubViewport")
1515
NotePlacementBar = NodePath("NotePlacementBar")
1616
CD = NodePath("Conductor")
1717
Audio = NodePath("AudioStreamPlayer")
1818
NQ = NodePath("NoteQueue")
1919

20+
[node name="UILayer" type="CanvasLayer" parent="."]
21+
2022
[node name="Conductor" type="Node" parent="." node_paths=PackedStringArray("CM")]
2123
script = ExtResource("2_pcp76")
2224
CM = NodePath("../SubViewport")
@@ -51,12 +53,6 @@ offset_top = 164.0
5153
offset_right = 16.0
5254
offset_bottom = 164.0
5355

54-
[node name="LeaveButton" type="Button" parent="."]
55-
offset_right = 119.0
56-
offset_bottom = 31.0
57-
text = "Return to Title"
58-
script = ExtResource("9_bxa6e")
59-
6056
[node name="TempRelicList" type="Label" parent="."]
6157
offset_left = 564.0
6258
offset_top = 165.0

scenes/Puppets/scripts/PlayerPuppet.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,30 @@
33

44
public partial class PlayerPuppet : PuppetTemplate
55
{
6-
public PlayerStats Stats = new PlayerStats();
6+
public PlayerStats Stats;
77

88
public override void _Ready()
99
{
10-
base._Ready();
10+
Stats = StageProducer.PlayerStats;
11+
12+
_currentHealth = Stats.CurrentHealth;
13+
_maxHealth = Stats.MaxHealth;
14+
1115
Init(GD.Load<Texture2D>("res://scenes/BattleDirector/assets/Character1.png"), "Player");
1216
SetPosition(new Vector2(80, 0));
1317
Sprite.Position += Vector2.Down * 30; //TEMP
18+
base._Ready();
19+
}
20+
21+
public override void TakeDamage(int amount)
22+
{
23+
base.TakeDamage(amount);
24+
Stats.CurrentHealth = _currentHealth;
25+
}
26+
27+
public override void Heal(int amount)
28+
{
29+
base.Heal(amount);
30+
Stats.CurrentHealth = _currentHealth;
1431
}
1532
}
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
using System;
2+
using System.Linq;
23
using Godot;
34

45
public partial class PlayerStats : Resource
56
{
6-
public int MaxHealth = 300;
7-
public Note[] CurNotes = new Note[] { Scribe.NoteDictionary[1].Clone() };
7+
public int MaxHealth = 100;
8+
public int CurrentHealth = 100;
9+
public Note[] CurNotes = new Note[] { Scribe.NoteDictionary[1].Clone() }; //TODO: Get a better method than .Clone
810

9-
public RelicTemplate[] CurRelics = new[] { Scribe.RelicDictionary[0].Clone() };
11+
public RelicTemplate[] CurRelics = Array.Empty<RelicTemplate>();
1012
public int Attack = 1;
13+
14+
public void AddRelic(RelicTemplate relic)
15+
{
16+
if (CurRelics.Any(r => r.Name == relic.Name))
17+
{
18+
GD.PrintErr("Relic already in inventory: " + relic.Name);
19+
return;
20+
}
21+
CurRelics = CurRelics.Append(relic).ToArray();
22+
GD.Print("Adding relic: " + relic.Name);
23+
}
1124
}

scenes/Puppets/scripts/PuppetTemplate.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77
public partial class PuppetTemplate : Node2D
88
{
9+
public delegate void DefeatedHandler(PuppetTemplate self);
10+
public event DefeatedHandler Defeated;
11+
912
protected HealthBar _healthBar;
1013
public Sprite2D Sprite = new Sprite2D();
1114

@@ -34,13 +37,22 @@ public void Init(Texture2D texture, string name)
3437
UniqName = name;
3538
}
3639

37-
public void TakeDamage(int amount)
40+
public virtual void TakeDamage(int amount)
41+
{
42+
_currentHealth = _healthBar.ChangeHP(-amount);
43+
if (_currentHealth <= 0)
44+
{
45+
Defeated?.Invoke(this);
46+
}
47+
}
48+
49+
public virtual void Heal(int amount)
3850
{
39-
_healthBar.ChangeHP(-amount);
51+
_currentHealth = _healthBar.ChangeHP(amount);
4052
}
4153

42-
public void Heal(int amount)
54+
public int GetCurrentHealth()
4355
{
44-
_healthBar.ChangeHP(amount);
56+
return _currentHealth;
4557
}
4658
}

scenes/SceneTransitions/scripts/SceneChange.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ public override void _Ready()
1515

1616
private void OnButtonPressed()
1717
{
18-
if (ScenePath == Stages.Quit)
19-
{
20-
GD.Print("Exiting game");
21-
GetTree().Quit();
22-
return;
23-
}
24-
2518
GD.Print($"✅ Loading scene: {ScenePath}");
2619
GetNode<StageProducer>("/root/StageProducer").TransitionStage(ScenePath);
2720
}

0 commit comments

Comments
 (0)