Rework game over logic and game initialization
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Chickensoft.Collections;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
@@ -11,6 +12,8 @@ public interface IMap : INode3D
|
||||
|
||||
Task LoadFloor(string sceneName);
|
||||
|
||||
void ClearMap();
|
||||
|
||||
IDungeonFloor CurrentFloor { get; }
|
||||
|
||||
Transform3D GetPlayerSpawnPosition();
|
||||
@@ -20,4 +23,6 @@ public interface IMap : INode3D
|
||||
void InitializeMapData();
|
||||
|
||||
public AutoProp<int> CurrentFloorNumber { get; }
|
||||
|
||||
public event Action<Transform3D> SpawnPointCreated;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Collections;
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.SaveFileBuilder;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -18,9 +16,6 @@ public partial class Map : Node3D, IMap
|
||||
[Dependency]
|
||||
public IGame Game => this.DependOn<IGame>();
|
||||
|
||||
[Dependency]
|
||||
public IPlayer Player => this.DependOn<IPlayer>();
|
||||
|
||||
[Node]
|
||||
public Node MapOrder { get; set; } = default!;
|
||||
|
||||
@@ -33,10 +28,11 @@ public partial class Map : Node3D, IMap
|
||||
|
||||
private readonly string _floorFilePath = @"res://src/map/dungeon/floors/";
|
||||
|
||||
public event Action<Transform3D> SpawnPointCreated;
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
this.Provide();
|
||||
|
||||
InitializeMapData();
|
||||
}
|
||||
|
||||
@@ -66,13 +62,20 @@ public partial class Map : Node3D, IMap
|
||||
public async Task LoadFloor(string sceneName)
|
||||
{
|
||||
AnimationPlayer.CallDeferred(AnimationPlayer.MethodName.Play, "fade_out");
|
||||
ClearCurrentMap();
|
||||
ClearMap();
|
||||
var newFloor = await LoadNewFloor(sceneName);
|
||||
AddChild(newFloor);
|
||||
InitializeFloor(newFloor);
|
||||
AnimationPlayer.CallDeferred(AnimationPlayer.MethodName.Play, ("fade_in"));
|
||||
}
|
||||
|
||||
public void ClearMap()
|
||||
{
|
||||
AnimationPlayer.CallDeferred(AnimationPlayer.MethodName.Play, "fade_out");
|
||||
CurrentFloor?.CallDeferred(MethodName.QueueFree, []);
|
||||
SpawnPointCreated?.Invoke(new Transform3D(Basis.Identity, new Vector3(-999, -999, -999)));
|
||||
}
|
||||
|
||||
private void InitializeFloor(Node newFloor)
|
||||
{
|
||||
CurrentFloor = (IDungeonFloor)newFloor;
|
||||
@@ -92,16 +95,10 @@ public partial class Map : Node3D, IMap
|
||||
return result;
|
||||
}
|
||||
|
||||
private void ClearCurrentMap()
|
||||
{
|
||||
CurrentFloor?.CallDeferred(MethodName.QueueFree, []);
|
||||
Player.TeleportPlayer(new Transform3D(Basis.Identity, new Vector3(-999, -999, -999)));
|
||||
}
|
||||
|
||||
private void SetupDungeonFloor()
|
||||
{
|
||||
CurrentFloor.InitializeDungeon();
|
||||
var transform = GetPlayerSpawnPosition();
|
||||
Player.TeleportPlayer(transform);
|
||||
SpawnPointCreated?.Invoke(transform);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public partial class MonsterRoom : DungeonRoom
|
||||
rng.Randomize();
|
||||
var numberOfItemsToSpawn = rng.RandiRange(1, itemSpawnPoints.Count);
|
||||
itemSpawnPoints.Shuffle();
|
||||
var database = new ItemDatabase();
|
||||
var database = ItemDatabase.Instance;
|
||||
foreach (var spawnPoint in itemSpawnPoints.Cast<Marker3D>())
|
||||
{
|
||||
if (numberOfItemsToSpawn <= 0)
|
||||
|
||||
Reference in New Issue
Block a user