-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.cs
More file actions
185 lines (170 loc) · 5.94 KB
/
Tile.cs
File metadata and controls
185 lines (170 loc) · 5.94 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using System;
using Dungeon_Delvers.Creatures;
using Dungeon_Delvers.Effects;
using Dungeon_Delvers.Equipment;
using Dungeon_Delvers.Data_Structures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Dungeon_Delvers;
class Tile
{
private bool hasUpstairs;
private bool hasDownstairs;
private bool amulet;
private bool isWall;
public bool IsWall => isWall;
public LinkedList<Dungeon_Delvers.Effects.Effect> floorItems = new();
public LinkedList<Equipment.Equipment> floorEquipment = new();
private Creature? creature;
public Creature? Creature => creature;
public Point position;
public bool HasItems => floorItems.Count > 0;
public bool HasEquipment => floorEquipment.Count > 0;
private readonly Texture2D characters;
private readonly Texture2D floors;
private readonly Texture2D items;
private readonly Texture2D mapobjects;
private readonly Texture2D walls;
public Tile(Texture2D characters, Texture2D floors, Texture2D items,
Texture2D mapobjects, Texture2D walls)
{
hasUpstairs = false;
hasDownstairs = false;
creature = null;
isWall = false;
hasAmulet = false;
this.characters = characters;
this.floors = floors;
this.items = items;
this.mapobjects = mapobjects;
this.walls = walls;
}
/* Having an upstairs and downstairs on a single tile would be cool but raises problems with displaying that info, plus
the game design consideration of forcing dungeon exploration. Ultimately this game just isn't going to allow it ¯\_(ツ)_/¯ */
public bool HasUpstairs
{
get => hasUpstairs;
set
{
if (isWall) throw new ArgumentException("Tile can not have wall and stairs");
else if (hasDownstairs && value) throw new ArgumentException("Tile can not have two sets of stairs");
else hasUpstairs = value;
}
}
public bool HasDownstairs
{
get => hasDownstairs;
set
{
if (hasUpstairs && value) throw new ArgumentException("Tile can not have two sets of stairs");
else hasDownstairs = value;
}
}
public bool hasAmulet
{
get => amulet;
set
{
if (!isWall && !hasDownstairs && !hasUpstairs) amulet = value;
else throw new InvalidOperationException("Can't place amulet here");
}
}
public bool MakeWall()
{
if (isWall) return false;
else
{
isWall = true;
return true;
}
}
public bool RemoveWall()
{
if (!isWall) return false;
else
{
isWall = false;
return true;
}
}
public void ChangeCreature(Creature creature)
{
this.creature = creature;
}
public Point Scale(Point pnt)
{
return new Point(pnt.X * Globals.SPRITESIZE.X, pnt.Y * Globals.SPRITESIZE.Y);
}
public void Draw()
{
Point drawPoint;
Rectangle drawPosition = new Rectangle(Scale(position), Globals.SPRITESIZE);
if (creature != null) Globals.sprites.Draw(characters, drawPosition,
new Rectangle(creature.Texture, Globals.SPRITESIZE), Color.White);
else if (isWall) Globals.sprites.Draw(walls, drawPosition,
new Rectangle(new Point(96, 49), Globals.SPRITESIZE), Color.White);
else if (hasUpstairs) Globals.sprites.Draw(mapobjects, drawPosition,
new Rectangle(new Point(0, 0), Globals.SPRITESIZE), Color.White);
else if (hasDownstairs) Globals.sprites.Draw(mapobjects, drawPosition,
new Rectangle(new Point(65, 0), Globals.SPRITESIZE), Color.White);
else if (amulet) Globals.sprites.Draw(items, drawPosition,
new Rectangle(new Point(112, 48), Globals.SPRITESIZE), Color.White);
else if (HasItems)
{
switch (floorItems.Get(0).Type)
{
case (ItemType.Potion):
drawPoint = new Point(80, 48);
break;
case (ItemType.Scroll):
drawPoint = new Point(34, 18);
break;
default: // Always Wand
drawPoint = new Point(112, 32);
break;
}
Globals.sprites.Draw(items, drawPosition,
new Rectangle(drawPoint, Globals.SPRITESIZE), Color.White);
}
else if (HasEquipment)
{
if (floorEquipment.Get(0).isWeapon)
{
switch (floorEquipment.Get(0).weaponType)
{
case (WeaponType.Dagger):
drawPoint = new Point(48, 16);
break;
case (WeaponType.Sword):
drawPoint = new Point(112, 16);
break;
case (WeaponType.Bow):
drawPoint = new Point(0, 16);
break;
default: // Quarterstaff
drawPoint = new Point(96, 34);
break;
}
}
else // armour
{
switch (floorEquipment.Get(0).slot)
{
case (Slot.Hands):
drawPoint = new Point(90, 62);
break;
case (Slot.Body):
drawPoint = new Point(32, 64);
break;
default: // Feet
drawPoint = new Point();
break;
}
}
Globals.sprites.Draw(items, drawPosition,
new Rectangle(drawPoint, Globals.SPRITESIZE), Color.White);
}
else Globals.sprites.Draw(floors, drawPosition,
new Rectangle(new Point(0, 0), Globals.SPRITESIZE), Color.White);
}
}