mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-11 15:25:55 +00:00
Roguelike map
This commit is contained in:
parent
a005e3c480
commit
e1496c9228
18 changed files with 226 additions and 101 deletions
9
Scripts/Controllers/RogueliteRoom.cs
Normal file
9
Scripts/Controllers/RogueliteRoom.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using Cirno.Scripts.Resources.Roguelite;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Controllers;
|
||||
|
||||
public partial class RogueliteRoom : Node2D
|
||||
{
|
||||
[Export] public RogueliteRoomResource RoomResource { get; set; }
|
||||
}
|
||||
1
Scripts/Controllers/RogueliteRoom.cs.uid
Normal file
1
Scripts/Controllers/RogueliteRoom.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b2j00riayxkit
|
||||
50
Scripts/Controllers/RogueliteRoomManager.cs
Normal file
50
Scripts/Controllers/RogueliteRoomManager.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using System.Linq;
|
||||
using Cirno.Scripts.Resources.Roguelite;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Controllers;
|
||||
|
||||
public partial class RogueliteRoomManager : Node2D
|
||||
{
|
||||
[Export] public Array<RogueliteRoomResource> Rooms { get; set; }
|
||||
|
||||
[Export] public Node2D SceneContainer { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
// Spawn first room
|
||||
|
||||
}
|
||||
|
||||
private void SpawnRoomsGrid()
|
||||
{
|
||||
var firstRoom = Rooms.FirstOrDefault();
|
||||
|
||||
var origin = Vector2.Zero;
|
||||
var tileSize = new Vector2(16, 16);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
for (int j = 0; j < 10; j++)
|
||||
{
|
||||
SpawnRoom(firstRoom, origin + (firstRoom.Size * new Vector2(i, j) * tileSize));
|
||||
}
|
||||
}
|
||||
|
||||
CallDeferred(MethodName.RebakeNavigationDeferred);
|
||||
|
||||
}
|
||||
|
||||
private void RebakeNavigationDeferred()
|
||||
{
|
||||
GameManager.Instance.RebakeNavigation();
|
||||
}
|
||||
|
||||
private void SpawnRoom(RogueliteRoomResource room, Vector2 position)
|
||||
{
|
||||
var roomScene = GD.Load<PackedScene>(room.ScenePath);
|
||||
|
||||
var spawnedScene = this.CreateChild<RogueliteRoom>(roomScene, position);
|
||||
}
|
||||
}
|
||||
1
Scripts/Controllers/RogueliteRoomManager.cs.uid
Normal file
1
Scripts/Controllers/RogueliteRoomManager.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bt2qjgnf1wc2r
|
||||
9
Scripts/Enums/GameMode.cs
Normal file
9
Scripts/Enums/GameMode.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
namespace Cirno.Scripts.Enums;
|
||||
|
||||
public enum GameMode
|
||||
{
|
||||
Game,
|
||||
Roguelite,
|
||||
BossRush,
|
||||
SpellCard
|
||||
}
|
||||
|
|
@ -66,6 +66,8 @@ public partial class GameManager : Node2D
|
|||
|
||||
[Export] public NavigationRegion2D NavigationRegion { get; private set; }
|
||||
|
||||
[Signal] public delegate void ManagerReadyEventHandler();
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -116,8 +118,15 @@ public partial class GameManager : Node2D
|
|||
//_ = DelayPlayerSpawn();
|
||||
|
||||
CallDeferred(MethodName.DelayPlayerSpawn);
|
||||
|
||||
CallDeferred(MethodName.OnFinished);
|
||||
}
|
||||
|
||||
private void OnFinished()
|
||||
{
|
||||
EmitSignalManagerReady();
|
||||
}
|
||||
|
||||
private void OnPlayerRespawned()
|
||||
{
|
||||
this.ClearBullets();
|
||||
|
|
|
|||
|
|
@ -39,14 +39,14 @@ public partial class GlobalState : Node
|
|||
this.ProcessMode = ProcessModeEnum.Always;
|
||||
|
||||
_mapsDatabase = ResourceLoader.Load<MapsDatabase>(_mapsDatabaseResource);
|
||||
|
||||
|
||||
Viewport root = GetTree().Root;
|
||||
// Using a negative index counts from the end, so this gets the last child node of `root`.
|
||||
CurrentScene = root.GetChild(-1);
|
||||
|
||||
_fader = CreateFader();
|
||||
|
||||
_menuMouseTexture =ResourceLoader.Load<Texture2D>(_menuMouseTexturePath);
|
||||
|
||||
_menuMouseTexture = ResourceLoader.Load<Texture2D>(_menuMouseTexturePath);
|
||||
_menuMouseImage = _menuMouseTexture.GetImage();
|
||||
|
||||
GetTree().GetRoot().SizeChanged += OnSizeChanged;
|
||||
|
|
@ -65,7 +65,7 @@ public partial class GlobalState : Node
|
|||
var root = GetTree().GetRoot();
|
||||
var baseSize = root.ContentScaleSize;
|
||||
var newSize = root.Size;
|
||||
|
||||
|
||||
int scaleX = newSize.X / baseSize.X;
|
||||
int scaleY = newSize.Y / baseSize.Y;
|
||||
int scale = Math.Min(scaleX, scaleY); // Ensure pixel-perfect scaling
|
||||
|
|
@ -83,31 +83,25 @@ public partial class GlobalState : Node
|
|||
|
||||
// The solution is to defer the load to a later time, when
|
||||
// we can be sure that no code from the current scene is running:
|
||||
|
||||
|
||||
//CallDeferred(MethodName.DeferredGotoScene, path, new MapStartDataResource());
|
||||
|
||||
|
||||
GoToScene(path, new MapStartDataResource());
|
||||
}
|
||||
|
||||
public void GoToScene(string path, MapStartDataResource startData)
|
||||
{
|
||||
GTweenSequenceBuilder.New()
|
||||
.AppendCallback(() =>
|
||||
{
|
||||
_loadingPlaque?.Show();
|
||||
})
|
||||
.AppendCallback(() => { _loadingPlaque?.Show(); })
|
||||
//.Append(_fader.TweenModulateAlpha(0, 0f))
|
||||
.Append(_fader.TweenModulateAlpha(1, 0.5f))
|
||||
.AppendCallback(() =>
|
||||
{
|
||||
CallDeferred(MethodName.DeferredGotoScene, path, startData);
|
||||
})
|
||||
.AppendCallback(() => { CallDeferred(MethodName.DeferredGotoScene, path, startData); })
|
||||
.Build()
|
||||
.PlayUnpausable();
|
||||
|
||||
|
||||
//CallDeferred(MethodName.DeferredGotoScene, path, startData);
|
||||
}
|
||||
|
||||
|
||||
public void GotoScene(MapResource map)
|
||||
{
|
||||
this.SessionSettings.LevelNumber = map.LevelId;
|
||||
|
|
@ -122,22 +116,22 @@ public partial class GlobalState : Node
|
|||
//var sceneParent = CurrentScene.GetParent();
|
||||
//sceneParent.RemoveChild(CurrentScene);
|
||||
//sceneParent.QueueFree();
|
||||
|
||||
|
||||
// Load a new scene.
|
||||
var nextScene = GD.Load<PackedScene>(path);
|
||||
|
||||
|
||||
// Instance the new scene.
|
||||
CurrentScene = nextScene.Instantiate();
|
||||
|
||||
// Add it to the active scene, as child of root.
|
||||
GetTree().Root.AddChild(CurrentScene);
|
||||
|
||||
|
||||
// Optionally, to make it compatible with the SceneTree.change_scene_to_file() API.
|
||||
GetTree().CurrentScene = CurrentScene;
|
||||
|
||||
|
||||
// // Update current scene here too
|
||||
// CurrentScene = GetTree().Root.GetChild(-1);
|
||||
|
||||
|
||||
if (startData is not null && GameManager.Instance is not null)
|
||||
{
|
||||
// Call deferred if it gives issues
|
||||
|
|
@ -148,7 +142,7 @@ public partial class GlobalState : Node
|
|||
// if (GameManager.Instance is not null) {
|
||||
// GameManager.Instance.ApplySessionState(SessionSettings);
|
||||
// }
|
||||
|
||||
|
||||
FadeIn();
|
||||
}
|
||||
|
||||
|
|
@ -162,9 +156,8 @@ public partial class GlobalState : Node
|
|||
_plaqueTemplate = GD.Load<PackedScene>("res://Scenes/HUD/LoadingPlaque.tscn");
|
||||
|
||||
return _plaqueTemplate.Instantiate<Control>();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private ColorRect CreateFader()
|
||||
{
|
||||
var canvas = new CanvasLayer();
|
||||
|
|
@ -176,19 +169,19 @@ public partial class GlobalState : Node
|
|||
rect.SetAnchorsPreset(Control.LayoutPreset.FullRect);
|
||||
rect.Color = new Color(Colors.Black, 1f);
|
||||
rect.ProcessMode = ProcessModeEnum.Always;
|
||||
|
||||
rect.Modulate = new Color(0,0,0,0);
|
||||
|
||||
rect.Modulate = new Color(0, 0, 0, 0);
|
||||
|
||||
rect.MouseFilter = Control.MouseFilterEnum.Ignore;
|
||||
|
||||
canvas.CallDeferred("add_child", rect);
|
||||
|
||||
|
||||
this.CallDeferred("add_child", canvas);
|
||||
|
||||
|
||||
_loadingPlaque = LoadPlaque();
|
||||
canvas.CallDeferred("add_child", _loadingPlaque);
|
||||
_loadingPlaque.Hide();
|
||||
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
|
|
@ -205,18 +198,18 @@ public partial class GlobalState : Node
|
|||
}
|
||||
|
||||
private readonly string SaveNameFile = "user://savegame.save";
|
||||
|
||||
|
||||
public void SaveGame()
|
||||
{
|
||||
var items = InventoryManager.Instance.Save();
|
||||
|
||||
|
||||
SessionSettings.Items = items;
|
||||
|
||||
|
||||
var serializedSavedata = new Godot.Collections.Dictionary<string, Variant>()
|
||||
{
|
||||
{ "Items", items },
|
||||
{ "Level", SessionSettings.LevelNumber },
|
||||
{ "Difficulty", (int)SessionSettings.Difficulty}
|
||||
{ "Difficulty", (int)SessionSettings.Difficulty }
|
||||
};
|
||||
|
||||
var saveFile = FileAccess.Open(SaveNameFile, FileAccess.ModeFlags.Write);
|
||||
|
|
@ -224,16 +217,17 @@ public partial class GlobalState : Node
|
|||
var jsonString = Json.Stringify(serializedSavedata);
|
||||
|
||||
saveFile.StoreLine(jsonString);
|
||||
|
||||
|
||||
GD.Print("Saved data successfully");
|
||||
}
|
||||
|
||||
|
||||
public bool LoadGame()
|
||||
{
|
||||
if (!FileAccess.FileExists(SaveNameFile))
|
||||
{
|
||||
return false; // Error! We don't have a save to load.
|
||||
}
|
||||
|
||||
using var saveFile = FileAccess.Open(SaveNameFile, FileAccess.ModeFlags.Read);
|
||||
|
||||
var jsonString = saveFile.GetLine();
|
||||
|
|
@ -245,13 +239,13 @@ public partial class GlobalState : Node
|
|||
GD.Print($"JSON Parse Error: {json.GetErrorMessage()} in {jsonString} at line {json.GetErrorLine()}");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
var deserializedSaveData = new Dictionary<string, Variant>((Dictionary)json.Data);
|
||||
|
||||
Dictionary<string, int> items = (Dictionary<string, int>)deserializedSaveData["Items"];
|
||||
|
||||
DifficultyLevel difficulty = (DifficultyLevel)deserializedSaveData["Difficulty"].AsInt32();
|
||||
|
||||
|
||||
int levelNumber = (int)deserializedSaveData["Level"];
|
||||
|
||||
var levelData = _mapsDatabase.Maps.FirstOrDefault(x => x.LevelId == levelNumber);
|
||||
|
|
@ -259,25 +253,25 @@ public partial class GlobalState : Node
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
this.SessionSettings.NewSession();
|
||||
SessionSettings.LevelNumber = levelNumber;
|
||||
SessionSettings.Items = items;
|
||||
SessionSettings.Difficulty = difficulty;
|
||||
|
||||
|
||||
this.GotoScene(levelData);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void ResizeCursor(float scale)
|
||||
{
|
||||
var scaled = (Image)_menuMouseImage.Duplicate();
|
||||
|
||||
var size = (Vector2I)(scale * _menuMouseTexture.GetSize());
|
||||
|
||||
|
||||
scaled.Resize(size.X, size.Y, Image.Interpolation.Nearest);
|
||||
|
||||
|
||||
DisplayServer.CursorSetCustomImage(scaled);
|
||||
}
|
||||
|
||||
|
|
@ -285,6 +279,4 @@ public partial class GlobalState : Node
|
|||
{
|
||||
GotoScene(CurrentScene.GetSceneFilePath());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using Cirno.Scripts.Enums;
|
||||
using Cirno.Scripts.UI;
|
||||
using Godot.Collections;
|
||||
|
||||
|
|
@ -55,8 +56,6 @@ public partial class MainMenu : CanvasLayer
|
|||
private void _on_start_button_pressed()
|
||||
{
|
||||
SpawnMenu<DifficultyMenu>(DifficultyMenuTemplate, SubMenuHolder);
|
||||
|
||||
return;
|
||||
|
||||
//GetTree().ChangeSceneToFile(GameScene);
|
||||
}
|
||||
|
|
@ -66,6 +65,7 @@ public partial class MainMenu : CanvasLayer
|
|||
if (GameScene == null) return;
|
||||
if (GlobalState.Instance.LoadGame())
|
||||
{
|
||||
GlobalState.Session.GameMode = GameMode.Game;
|
||||
GlobalState.Session.AllowSaving = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
Scripts/Resources/Roguelite/RogueliteRoom.cs.uid
Normal file
1
Scripts/Resources/Roguelite/RogueliteRoom.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d1w6r3yfmw8ag
|
||||
11
Scripts/Resources/Roguelite/RogueliteRoomResource.cs
Normal file
11
Scripts/Resources/Roguelite/RogueliteRoomResource.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources.Roguelite;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class RogueliteRoomResource : Resource
|
||||
{
|
||||
[Export] public StringName RoomName { get; set; }
|
||||
[Export] public StringName ScenePath { get; set; }
|
||||
[Export] public Vector2 Size { get; set; } = new(20, 10);
|
||||
}
|
||||
1
Scripts/Resources/Roguelite/RogueliteRoomResource.cs.uid
Normal file
1
Scripts/Resources/Roguelite/RogueliteRoomResource.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bl2ne8w12e3a
|
||||
|
|
@ -34,6 +34,7 @@ public partial class DifficultyMenu : MenuBase
|
|||
GlobalState.Session.NewSession();
|
||||
GlobalState.Session.AllowSaving = true;
|
||||
GlobalState.Session.Difficulty = difficultyLevel;
|
||||
GlobalState.Session.GameMode = GameMode.Game;
|
||||
GlobalState.Instance.GotoScene(StartMap);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ namespace Cirno.Scripts.Utils;
|
|||
|
||||
public class SessionSettings
|
||||
{
|
||||
public GameMode GameMode { get; set; } = GameMode.Game;
|
||||
public bool SkipDialogues { get; set; } = false;
|
||||
public bool GodMode { get; set; } = false;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue