-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.cs
98 lines (83 loc) · 2.65 KB
/
map.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using SFML.System;
using RogueSharp;
using RogueSharp.MapCreation;
namespace LilRogue
{
public class Map
{
public IMap _rogueSharpMap;
private bool[,] _isCellVisible; // Add the visibility array
public int Width => _rogueSharpMap.Width;
public int Height => _rogueSharpMap.Height;
public Map(int width, int height)
{
var mapCreationStrategy = new RandomRoomsMapCreationStrategy<RogueSharp.Map>(width, height, 100, 7, 3);
_rogueSharpMap = RogueSharp.Map.Create(mapCreationStrategy);
_isCellVisible = new bool[width, height]; // Initialize the visibility array
}
public bool IsWalkable(int x, int y)
{
return _rogueSharpMap.GetCell(x, y).IsWalkable;
}
public ICell GetCell(int x, int y)
{
return _rogueSharpMap.GetCell(x, y);
}
public ICell GetRandomCell()
{
var cell = _rogueSharpMap.GetCell(Random.Shared.Next(Width), Random.Shared.Next(Height));
if (cell != null)
{
return cell;
}
return null;
}
public void ComputeFov(int x, int y, int radius, bool lightWalls)
{
var fov = new FieldOfView(_rogueSharpMap);
fov.ComputeFov(x, y, radius, lightWalls);
// clean up visibility map cells
for (int i = 0; i < Width; i++)
{
for (int j = 0; j < Height; j++)
{
_isCellVisible[i, j] = false;
}
}
for (int dx = -radius; dx <= radius; dx++)
{
for (int dy = -radius; dy <= radius; dy++)
{
int mapX = x + dx;
int mapY = y + dy;
if (IsValidPosition(mapX, mapY))
{
// Update
_isCellVisible[mapX, mapY] = fov.IsInFov(mapX, mapY); // Update visibility array
}
}
}
}
public bool IsTransparent(int x, int y)
{
return _rogueSharpMap.GetCell(x, y).IsTransparent;
}
public bool IsCellVisible(int x, int y)
{
if (IsValidPosition(x, y))
{
return _isCellVisible[x, y];
}
return false;
}
private bool IsValidPosition(int x, int y)
{
return x >= 0 && x < Width && y >= 0 && y < Height;
}
public IMap getMap()
{
return _rogueSharpMap;
}
}
}