Skip to content

Commit 9f08b0e

Browse files
authored
Merge pull request #48 from Project-Funk-Engine/Inventory
Inventory into Sprint 2
2 parents 2db3f63 + b1a27eb commit 9f08b0e

40 files changed

+1083
-500
lines changed

Classes/Note.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

Classes/Notes/Note.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using FunkEngine;
3+
using Godot;
4+
5+
/**
6+
* @class Note
7+
* @brief Data structure class for holding data and methods for a battle time note. WIP
8+
*/
9+
public partial class Note : Resource
10+
{
11+
public PuppetTemplate Owner;
12+
public string Name;
13+
private int _baseVal;
14+
private Action<BattleDirector, Note, Timing> NoteEffect; //TODO: Where/How to deal with timing.
15+
16+
//public string Tooltip;
17+
18+
public Note(
19+
string name,
20+
PuppetTemplate owner = null,
21+
int baseVal = 1,
22+
Action<BattleDirector, Note, Timing> noteEffect = null
23+
)
24+
{
25+
Name = name;
26+
Owner = owner;
27+
NoteEffect =
28+
noteEffect
29+
?? (
30+
(BD, source, Timing) =>
31+
{
32+
BD.GetTarget(this).TakeDamage(source._baseVal);
33+
}
34+
);
35+
_baseVal = baseVal;
36+
}
37+
38+
public void OnHit(BattleDirector BD, Timing timing)
39+
{
40+
NoteEffect(BD, this, timing);
41+
}
42+
43+
public Note Clone()
44+
{
45+
return (Note)MemberwiseClone();
46+
}
47+
}

Classes/Relics/RelicEffect.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using FunkEngine;
3+
using Godot;
4+
5+
public partial class RelicEffect : IBattleEvent
6+
{
7+
private BattleEffectTrigger Trigger { get; set; }
8+
public int BaseValue;
9+
private Action<BattleDirector, int> OnRelicEffect;
10+
11+
public RelicEffect(
12+
BattleEffectTrigger trigger,
13+
int val,
14+
Action<BattleDirector, int> onRelicEffect
15+
)
16+
{
17+
BaseValue = val;
18+
Trigger = trigger;
19+
OnRelicEffect = onRelicEffect;
20+
}
21+
22+
public void OnTrigger(BattleDirector battleDirector)
23+
{
24+
OnRelicEffect(battleDirector, BaseValue);
25+
}
26+
27+
public BattleEffectTrigger GetTrigger()
28+
{
29+
return Trigger;
30+
}
31+
}

Classes/Relics/RelicTemplate.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using FunkEngine;
3+
using Godot;
4+
5+
public partial class RelicTemplate : Resource
6+
{
7+
public RelicEffect[] Effects;
8+
public string Name;
9+
10+
//public Texture2D Texture
11+
//public string Tooltip
12+
public RelicTemplate(string Name = "", RelicEffect[] EffectTags = null)
13+
{
14+
Effects = EffectTags;
15+
this.Name = Name;
16+
}
17+
18+
public RelicTemplate Clone()
19+
{
20+
return (RelicTemplate)MemberwiseClone();
21+
}
22+
}

Globals/FunkEngineNameSpace.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Godot;
2+
3+
namespace FunkEngine;
4+
5+
public enum ArrowType
6+
{
7+
Up = 0,
8+
Down = 1,
9+
Left = 2,
10+
Right = 3,
11+
}
12+
13+
public enum BattleEffectTrigger
14+
{
15+
NotePlaced,
16+
NoteHit,
17+
SelfNoteHit,
18+
}
19+
20+
public enum Timing
21+
{
22+
Miss = 0,
23+
Bad = 1,
24+
Okay = 2,
25+
Good = 3,
26+
Perfect = 4,
27+
}
28+
29+
public enum Stages
30+
{
31+
Title,
32+
Battle,
33+
Quit,
34+
Map,
35+
}
36+
37+
public struct SongData
38+
{
39+
public int Bpm;
40+
public double SongLength;
41+
public int NumLoops;
42+
}
43+
44+
public struct ArrowData
45+
{
46+
public Color Color;
47+
public string Key;
48+
public NoteChecker Node;
49+
public ArrowType Type;
50+
}
51+
52+
public interface IBattleEvent
53+
{
54+
void OnTrigger(BattleDirector BD);
55+
BattleEffectTrigger GetTrigger();
56+
}

Globals/Scribe.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using FunkEngine;
3+
using Godot;
4+
5+
/**
6+
* Global for storing defined data, e.g. Notes and Relic Dictionaries.
7+
*/
8+
public partial class Scribe : Node
9+
{
10+
public static readonly Note[] NoteDictionary = new[]
11+
{
12+
new Note(
13+
"EnemyBase",
14+
null,
15+
1,
16+
(director, note, timing) =>
17+
{
18+
director.Player.TakeDamage(4 - (int)timing);
19+
}
20+
),
21+
new Note(
22+
"PlayerBase",
23+
null,
24+
1,
25+
(director, note, timing) =>
26+
{
27+
director.Enemy.TakeDamage((int)timing);
28+
}
29+
),
30+
};
31+
32+
public static readonly RelicTemplate[] RelicDictionary = new[]
33+
{
34+
new RelicTemplate(
35+
"Good Vibes",
36+
new RelicEffect[]
37+
{
38+
new RelicEffect(
39+
BattleEffectTrigger.NotePlaced,
40+
5,
41+
(director, val) =>
42+
{
43+
director.Player.Heal(val);
44+
}
45+
),
46+
}
47+
),
48+
};
49+
}

Globals/StageProducer.cs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
using System;
2+
using System.Linq;
3+
using FunkEngine;
4+
using Godot;
5+
6+
public partial class StageProducer : Node
7+
{
8+
//Generate a map, starting as a width x height grid, pick a starting spot and do (path) paths from that to the last
9+
//row, connecting the path, then connect all at the end to the boss room.
10+
public static RandomNumberGenerator GlobalRng = new RandomNumberGenerator();
11+
private ulong _seed;
12+
private ulong _lastRngState;
13+
14+
private Stages _curStage = Stages.Title;
15+
private Node _curScene;
16+
17+
private MapGrid _map = new MapGrid();
18+
19+
public class MapGrid
20+
{
21+
private int[,] _map;
22+
private Room[] _rooms;
23+
private int _curIdx = 0;
24+
private int _curRoom = 0;
25+
26+
public class Room
27+
{
28+
public Room(int idx, int x, int y)
29+
{
30+
Idx = idx;
31+
X = x;
32+
Y = y;
33+
}
34+
35+
public void SetType(string type)
36+
{
37+
Type = type;
38+
}
39+
40+
public void AddChild(int newIdx)
41+
{
42+
if (Children.Contains(newIdx))
43+
return;
44+
Children = Children.Append(newIdx).ToArray();
45+
}
46+
47+
private int Idx;
48+
private int[] Children = Array.Empty<int>();
49+
private int X;
50+
private int Y;
51+
private string Type;
52+
}
53+
54+
public void InitMapGrid(int width, int height, int paths)
55+
{
56+
_curIdx = 0;
57+
_rooms = Array.Empty<Room>();
58+
_map = new int[width, height]; //x,y
59+
60+
int startX = GlobalRng.RandiRange(0, width - 1); //TODO: Replace with seeding
61+
_rooms = _rooms.Append(new Room(_curIdx, startX, 0)).ToArray();
62+
_map[startX, 0] = _curIdx++;
63+
64+
for (int i = 0; i < paths; i++)
65+
{
66+
GeneratePath_r(startX, 0, width, height);
67+
}
68+
69+
AddBossRoom(width, height);
70+
}
71+
72+
//Start at x, y, assume prev room exists. Picks new x pos within +/- 1, attaches recursively
73+
private void GeneratePath_r(int x, int y, int width, int height)
74+
{
75+
int nextX = GlobalRng.RandiRange(Math.Max(x - 1, 0), Math.Min(x + 1, width - 1));
76+
if (_map[nextX, y + 1] == 0)
77+
{
78+
_rooms = _rooms.Append(new Room(_curIdx, nextX, y + 1)).ToArray();
79+
_map[nextX, y + 1] = _curIdx;
80+
_rooms[_map[x, y]].AddChild(_curIdx++);
81+
}
82+
else
83+
{
84+
_rooms[_map[x, y]].AddChild(_map[nextX, y + 1]);
85+
}
86+
if (y < height - 2)
87+
{
88+
GeneratePath_r(nextX, y + 1, width, height);
89+
}
90+
}
91+
92+
private void AddBossRoom(int width, int height)
93+
{
94+
_rooms = _rooms.Append(new Room(_curIdx, 0, height)).ToArray();
95+
_rooms[_curIdx].SetType("Boss");
96+
for (int i = 0; i < width; i++) //Attach all last rooms to a boss room
97+
{
98+
if (_map[i, height - 1] != 0)
99+
{
100+
_rooms[_map[i, height - 1]].AddChild(_curIdx);
101+
}
102+
}
103+
}
104+
}
105+
106+
public void StartGame()
107+
{
108+
_map.InitMapGrid(2, 2, 1);
109+
_seed = GlobalRng.Seed;
110+
_lastRngState = GlobalRng.State;
111+
}
112+
113+
public void TransitionStage(Stages nextStage)
114+
{
115+
GD.Print(GetTree().CurrentScene);
116+
switch (nextStage)
117+
{
118+
case Stages.Title:
119+
GetTree().ChangeSceneToFile("res://scenes/SceneTransitions/TitleScreen.tscn");
120+
break;
121+
case Stages.Battle:
122+
GetTree().ChangeSceneToFile("res://scenes/BattleDirector/test_battle_scene.tscn");
123+
break;
124+
}
125+
126+
_curStage = nextStage;
127+
}
128+
}

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ Current team members include:
1414

1515

1616
#### Attributions:
17-
Note icon: <a href="https://www.flaticon.com/free-icons/next" title="next icons">Next icons created by Pixel perfect - Flaticon</a>
18-
1917
First Song: <a href="https://freesound.org/people/Magntron/sounds/335571/" title="gameMusic">gameMusic by Magntron - freesound.org</a>
2018

2119

project.godot

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ config_version=5
1111
[application]
1212

1313
config/name="Funk Engine"
14-
run/main_scene="res://scenes/BattleDirector/test_battle_scene.tscn"
14+
run/main_scene="res://scenes/SceneTransitions/TitleScreen.tscn"
1515
config/features=PackedStringArray("4.3", "C#", "Forward Plus")
1616
config/icon="res://icon.svg"
1717

1818
[autoload]
1919

20-
TimeKeeper="*res://scripts/TimeKeeper.cs"
20+
TimeKeeper="*res://Globals/TimeKeeper.cs"
21+
Scribe="*res://Globals/Scribe.cs"
22+
StageProducer="*res://Globals/StageProducer.cs"
2123

2224
[display]
2325

0 commit comments

Comments
 (0)