-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.cs
More file actions
98 lines (86 loc) · 2.86 KB
/
Map.cs
File metadata and controls
98 lines (86 loc) · 2.86 KB
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 Dungeon_Delvers.Creatures;
using Dungeon_Delvers.Data_Structures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Dungeon_Delvers;
class Map
{
public Tile[,] tiles;
public readonly int size;
public Map(int mapSize)
{
this.size = mapSize;
Texture2D characters = Globals.content.Load<Texture2D>("roguelike_characters");
Texture2D floors = Globals.content.Load<Texture2D>("roguelike_floors");
Texture2D items = Globals.content.Load<Texture2D>("roguelike_items");
Texture2D mapobjects = Globals.content.Load<Texture2D>("roguelike_mapobjects");
Texture2D walls = Globals.content.Load<Texture2D>("roguelike_walls_edited");
tiles = new Tile[size, size];
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
// Properly construct each tile object with the spritesheets
tiles[i, j] = new Tile(characters, floors, items, mapobjects, walls);
tiles[i, j].position = new(j, i);
}
}
}
public void Draw()
{
foreach (Tile tile in tiles) tile.Draw();
}
// If a free tile can not be found, return out of bounds Point
public Point GetRandomFreeTile()
{
Random rand = new Random();
Point point = Point.Zero;
bool found = false;
while (!found)
{
point = new Point(rand.Next(0, size), rand.Next(0, size));
if (!tiles[point.Y, point.X].IsWall ||
tiles[point.Y, point.X].HasDownstairs ||
tiles[point.Y, point.X].HasUpstairs)
found = true;
}
return point;
}
public bool IsPointInBounds(Point point)
{
return point.X < size && point.Y < size && point.X >= 0 && point.Y >= 0;
}
public void Update(LinkedList<Creature> mobs)
{
Creature creature;
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
tiles[i, j].ChangeCreature(null);
}
}
for (int i = 0; i < mobs.Count; i++)
{
creature = mobs.Get(i);
// X and Y are swapped because in the 2d array each list is its own horizontal row
tiles[creature.Position.Y, creature.Position.X].ChangeCreature(creature);
}
}
public void ResetTiles()
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
tiles[i, j].ChangeCreature(null);
tiles[i, j].floorEquipment.Reset();
tiles[i, j].floorItems.Reset();
tiles[i, j].RemoveWall();
tiles[i, j].HasDownstairs = false;
tiles[i, j].HasUpstairs = false;
}
}
}
}