Skip to content

Commit 175a64b

Browse files
committed
Map Scene and Damage number particle
1 parent 692cf28 commit 175a64b

9 files changed

Lines changed: 148 additions & 17 deletions

File tree

Globals/StageProducer.cs

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ public partial class StageProducer : Node
1010
public static RandomNumberGenerator GlobalRng = new RandomNumberGenerator();
1111
private ulong _seed;
1212
private ulong _lastRngState;
13+
private bool _isInitialized = false;
1314

1415
private Stages _curStage = Stages.Title;
1516
private Node _curScene;
17+
public static MapGrid.Room CurRoom { get; private set; }
18+
public static Vector2I MapSize { get; private set; } = new Vector2I(3, 2); //For now, make width an odd number
1619

17-
private MapGrid _map = new MapGrid();
20+
public static MapGrid Map { get; } = new MapGrid();
1821

1922
//Hold here to persist between changes
2023
//TODO: Allow for permanent changes and battle temporary stat changes.
@@ -27,6 +30,11 @@ public class MapGrid
2730
private int _curIdx = 0;
2831
private int _curRoom = 0;
2932

33+
public Room[] GetRooms()
34+
{
35+
return _rooms;
36+
}
37+
3038
public class Room
3139
{
3240
public Room(int idx, int x, int y)
@@ -48,10 +56,10 @@ public void AddChild(int newIdx)
4856
Children = Children.Append(newIdx).ToArray();
4957
}
5058

51-
private int Idx;
52-
private int[] Children = Array.Empty<int>();
53-
private int X;
54-
private int Y;
59+
public int Idx { get; private set; }
60+
public int[] Children { get; private set; } = Array.Empty<int>();
61+
public int X { get; private set; }
62+
public int Y { get; private set; }
5563
private string Type;
5664
}
5765

@@ -61,15 +69,15 @@ public void InitMapGrid(int width, int height, int paths)
6169
_rooms = Array.Empty<Room>();
6270
_map = new int[width, height]; //x,y
6371

64-
int startX = GlobalRng.RandiRange(0, width - 1); //TODO: Replace with seeding
72+
int startX = (width / 2);
6573
_rooms = _rooms.Append(new Room(_curIdx, startX, 0)).ToArray();
6674
_map[startX, 0] = _curIdx++;
6775

6876
for (int i = 0; i < paths; i++)
6977
{
7078
GeneratePath_r(startX, 0, width, height);
7179
}
72-
80+
CreateCommonChildren(width, height);
7381
AddBossRoom(width, height);
7482
}
7583

@@ -93,9 +101,25 @@ private void GeneratePath_r(int x, int y, int width, int height)
93101
}
94102
}
95103

104+
//Asserts that if there is a room at the same x, but y+1 they are connected
105+
private void CreateCommonChildren(int width, int height)
106+
{
107+
foreach (Room room in _rooms)
108+
{
109+
Vector2I curPos = new Vector2I(room.X, room.Y);
110+
if (room.Y + 1 >= height)
111+
continue;
112+
if (_map[curPos.X, curPos.Y + 1] == 0)
113+
continue;
114+
GD.Print("Added child on same X.");
115+
room.AddChild(_map[curPos.X, curPos.Y + 1]);
116+
}
117+
}
118+
119+
//Adds a boss room at the end of rooms, all max height rooms connect to it.
96120
private void AddBossRoom(int width, int height)
97121
{
98-
_rooms = _rooms.Append(new Room(_curIdx, 0, height)).ToArray();
122+
_rooms = _rooms.Append(new Room(_curIdx, width / 2, height)).ToArray();
99123
_rooms[_curIdx].SetType("Boss");
100124
for (int i = 0; i < width; i++) //Attach all last rooms to a boss room
101125
{
@@ -109,10 +133,19 @@ private void AddBossRoom(int width, int height)
109133

110134
public void StartGame()
111135
{
112-
_map.InitMapGrid(2, 2, 1);
136+
Map.InitMapGrid(MapSize.X, MapSize.Y, 1);
113137
_seed = GlobalRng.Seed;
114138
_lastRngState = GlobalRng.State;
115139
PlayerStats = new PlayerStats();
140+
141+
CurRoom = Map.GetRooms()[0];
142+
_isInitialized = true;
143+
}
144+
145+
public void TransitionFromRoom(int nextRoomIdx)
146+
{
147+
//CurRoom = Map.GetRooms()[nextRoomIdx];
148+
TransitionStage(Stages.Battle);
116149
}
117150

118151
public void TransitionStage(Stages nextStage)
@@ -124,9 +157,15 @@ public void TransitionStage(Stages nextStage)
124157
GetTree().ChangeSceneToFile("res://scenes/SceneTransitions/TitleScreen.tscn");
125158
break;
126159
case Stages.Battle:
127-
StartGame();
128160
GetTree().ChangeSceneToFile("res://scenes/BattleDirector/test_battle_scene.tscn");
129161
break;
162+
case Stages.Map:
163+
GetTree().ChangeSceneToFile("res://scenes/Maps/cartographer.tscn");
164+
if (!_isInitialized)
165+
{
166+
StartGame();
167+
}
168+
break;
130169
case Stages.Quit:
131170
GD.Print("Exiting game");
132171
GetTree().Quit();

scenes/BattleDirector/NotePlacementBar.tscn

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ gradient = SubResource("Gradient_0u6yv")
1313
width = 26
1414
height = 100
1515

16-
[sub_resource type="Gradient" id="Gradient_lyd0l"]
16+
[sub_resource type="Gradient" id="Gradient_xvck1"]
1717
offsets = PackedFloat32Array(0, 0.485915, 0.739437, 1)
1818
colors = PackedColorArray(0, 1, 0, 1, 0.68, 0, 0.272, 1, 0, 0.64, 0.608, 1, 0.4, 0, 0, 1)
1919

20-
[sub_resource type="GradientTexture2D" id="GradientTexture2D_k7kvy"]
21-
gradient = SubResource("Gradient_lyd0l")
20+
[sub_resource type="GradientTexture2D" id="GradientTexture2D_0bqho"]
21+
gradient = SubResource("Gradient_xvck1")
2222
width = 24
2323
height = 98
2424
fill_to = Vector2(0, 1)
@@ -42,7 +42,7 @@ offset_right = 26.0
4242
offset_bottom = 100.0
4343
fill_mode = 3
4444
texture_under = SubResource("GradientTexture2D_hhds4")
45-
texture_progress = SubResource("GradientTexture2D_k7kvy")
45+
texture_progress = SubResource("GradientTexture2D_0bqho")
4646
texture_progress_offset = Vector2(1, 1)
4747

4848
[node name="TextEdit" type="TextEdit" parent="."]

scenes/BattleDirector/test_battle_scene.tscn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ metadata/_edit_lock_ = true
1919
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
2020
stream = ExtResource("8_caqms")
2121

22+
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
23+
stream = ExtResource("8_caqms")
24+
2225
[node name="UILayer" type="CanvasLayer" parent="."]
2326

2427
[node name="Conductor" type="Node" parent="." node_paths=PackedStringArray("CM")]
@@ -47,6 +50,7 @@ offset_bottom = 360.0
4750
color = Color(0.165656, 0.165656, 0.165656, 1)
4851

4952
[node name="NotePlacementBar" parent="." instance=ExtResource("7_3ko4g")]
53+
z_index = 1
5054
offset_left = 16.0
5155
offset_top = 164.0
5256
offset_right = 16.0

scenes/Maps/cartographer.tscn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
[gd_scene format=3 uid="uid://cydmo2lbnj1de"]
1+
[gd_scene load_steps=2 format=3 uid="uid://cydmo2lbnj1de"]
2+
3+
[ext_resource type="Script" path="res://scenes/Maps/scripts/Cartographer.cs" id="1_u4q3n"]
24

35
[node name="Cartographer" type="Node2D"]
6+
script = ExtResource("1_u4q3n")
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Linq;
3+
using FunkEngine;
4+
using Godot;
5+
6+
public partial class Cartographer : Node2D
7+
{
8+
public override void _Ready()
9+
{
10+
DrawMap();
11+
}
12+
13+
private Vector2 GetPosition(int x, int y)
14+
{
15+
return new Vector2((float)x * 640 / StageProducer.MapSize.X - 1 + 64, y * 64 + 16);
16+
}
17+
18+
private void DrawMap()
19+
{
20+
var rooms = StageProducer.Map.GetRooms();
21+
foreach (StageProducer.MapGrid.Room room in rooms)
22+
{
23+
DrawMapSprite(room);
24+
foreach (int roomIdx in room.Children)
25+
{
26+
Line2D newLine = new Line2D();
27+
newLine.AddPoint(GetPosition(room.X, room.Y));
28+
newLine.AddPoint(GetPosition(rooms[roomIdx].X, rooms[roomIdx].Y));
29+
AddChild(newLine);
30+
}
31+
}
32+
}
33+
34+
private void DrawMapSprite(StageProducer.MapGrid.Room room)
35+
{
36+
var newSprite = new Button();
37+
AddChild(newSprite);
38+
//button is disabled if it is not a child of current room.
39+
if (!StageProducer.CurRoom.Children.Contains(room.Idx))
40+
{
41+
newSprite.Disabled = true;
42+
newSprite.FocusMode = Control.FocusModeEnum.None;
43+
}
44+
else
45+
{
46+
newSprite.GrabFocus();
47+
newSprite.Pressed += () =>
48+
{
49+
EnterStage(room.Idx);
50+
};
51+
}
52+
newSprite.Icon = (Texture2D)GD.Load("res://icon.svg"); //TODO: Room types icons
53+
newSprite.Scale *= .25f;
54+
newSprite.ZIndex = 1;
55+
newSprite.Position = GetPosition(room.X, room.Y) - newSprite.Size * 2;
56+
}
57+
58+
private void EnterStage(int roomIdx)
59+
{
60+
GetNode<StageProducer>("/root/StageProducer").TransitionFromRoom(roomIdx);
61+
}
62+
}

scenes/Puppets/scripts/PuppetTemplate.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,24 @@ public virtual void TakeDamage(int amount)
4646
{
4747
Defeated?.Invoke(this);
4848
}
49+
if (amount != 0)
50+
{
51+
TextParticle newText = new TextParticle();
52+
newText.Modulate = Colors.Red;
53+
Sprite.AddChild(newText);
54+
newText.Text = $"-{amount}";
55+
}
4956
}
5057

5158
public virtual void Heal(int amount)
5259
{
60+
if (amount != 0)
61+
{
62+
TextParticle newText = new TextParticle();
63+
newText.Modulate = Colors.Green;
64+
Sprite.AddChild(newText);
65+
newText.Text = $"+{amount}";
66+
}
5367
_currentHealth = _healthBar.ChangeHP(amount);
5468
}
5569

scenes/SceneTransitions/TitleScreen.tscn

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ texture = ExtResource("2_cf582")
4848

4949
[node name="Label" type="Label" parent="VBoxContainer/MarginContainer/Control"]
5050
layout_mode = 2
51-
text = "Project Funk engine"
51+
text = "Insert Title Screen Here"
5252

5353
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
5454
layout_mode = 2
@@ -69,7 +69,8 @@ layout_mode = 2
6969
size_flags_horizontal = 3
7070
text = "Start Game"
7171
script = ExtResource("2_7f3m6")
72-
ScenePath = 1
72+
ScenePath = 3
73+
_startFocused = true
7374

7475
[node name="MarginContainer3" type="MarginContainer" parent="VBoxContainer/HBoxContainer"]
7576
visible = false

scenes/SceneTransitions/scripts/SceneChange.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ public partial class SceneChange : Button
77
[Export]
88
public Stages ScenePath;
99

10+
[Export]
11+
private bool _startFocused = false;
12+
1013
public override void _Ready()
1114
{
15+
if (_startFocused)
16+
{
17+
GrabFocus();
18+
}
1219
Pressed += OnButtonPressed;
1320
GD.Print($"[DEBUG] Scene Path: '{ScenePath}'");
1421
}

scenes/UI/scripts/PauseMenu.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ private void Quit()
3737

3838
private void QuitToMainMenu()
3939
{
40+
GetTree().Paused = false;
4041
GetNode<StageProducer>("/root/StageProducer").TransitionStage(Stages.Title);
4142
}
4243
}

0 commit comments

Comments
 (0)