SupaLidlGame/Scenes/Map.cs

98 lines
1.9 KiB
C#
Raw Permalink Normal View History

2023-03-26 10:53:45 -07:00
using Godot;
2023-08-03 16:17:34 -07:00
using SupaLidlGame.Extensions;
2024-06-06 07:59:29 -07:00
using System.Collections.Generic;
2023-03-26 10:53:45 -07:00
2023-06-03 18:21:46 -07:00
namespace SupaLidlGame.Scenes;
public partial class Map : Node2D
2023-03-26 10:53:45 -07:00
{
2023-06-03 18:21:46 -07:00
[Export]
public Node2D Entities { get; set; }
2023-03-26 10:53:45 -07:00
2023-06-03 18:21:46 -07:00
[Export]
public Node2D Areas { get; set; }
2023-03-26 10:53:45 -07:00
2023-06-03 18:21:46 -07:00
[Export]
public Node2D Spawners { get; set; }
2023-03-26 10:53:45 -07:00
[Export]
public Node2D Markers { get; set; }
2023-06-03 18:21:46 -07:00
[Export]
public Vector2 CameraLowerBound { get; set; }
2023-03-26 10:53:45 -07:00
2023-06-03 18:21:46 -07:00
[Export]
public Vector2 CameraUpperBound { get; set; }
2023-03-26 10:53:45 -07:00
2023-07-31 01:12:47 -07:00
[Export]
public Color ClearColor { get; set; }
[Export]
public string AreaName { get; set; }
[Export]
public string MapName { get; set; }
[Export]
public AudioStream Music { get; set; }
2023-06-03 18:21:46 -07:00
private bool _active;
2023-03-26 10:53:45 -07:00
2023-06-03 18:21:46 -07:00
public bool Active
{
get
2023-03-26 10:53:45 -07:00
{
2023-06-03 18:21:46 -07:00
return _active;
2023-03-26 10:53:45 -07:00
}
2023-06-03 18:21:46 -07:00
set
2023-03-26 10:53:45 -07:00
{
_active = value;
2023-06-03 18:21:46 -07:00
SetProcess(value);
2023-03-26 10:53:45 -07:00
}
2023-06-03 18:21:46 -07:00
}
2023-03-26 10:53:45 -07:00
2023-06-03 18:21:46 -07:00
public override void _Ready()
{
2023-08-03 16:17:34 -07:00
var world = this.GetWorld();
if (world.CurrentMap is null)
{
world.LoadScene(this);
}
2023-06-03 18:21:46 -07:00
Active = true;
}
public override void _Process(double delta)
{
base._Process(delta);
2023-03-26 10:53:45 -07:00
}
2023-07-13 23:46:58 -07:00
2023-07-31 01:12:47 -07:00
public void Load()
{
Godot.RenderingServer.SetDefaultClearColor(ClearColor);
GetNode<Audio.AudioManager>("/root/AudioManager").PlayBackground(Music);
2023-07-31 01:12:47 -07:00
}
2024-06-06 07:59:29 -07:00
public IEnumerable<Characters.Character> GetCharacters()
{
foreach (var child in Entities.GetChildren())
{
if (child is Characters.Character c)
{
yield return c;
}
}
}
2023-07-13 23:46:58 -07:00
public Node SpawnEntity(PackedScene scene)
{
var instance = scene.Instantiate();
Entities.AddChild(instance);
return instance;
}
public T SpawnEntity<T>(PackedScene scene) where T : Node
{
return SpawnEntity(scene) as T;
}
2023-03-26 10:53:45 -07:00
}