-
Notifications
You must be signed in to change notification settings - Fork 2
/
World.cs
129 lines (112 loc) · 2.04 KB
/
World.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
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
using Raylib_cs;
namespace kum
{
internal class World
{
int width, height, resize_factor;
Tile[,]? sandbox;
public World(int width, int height, int resize_factor)
{
this.width = width / resize_factor;
this.height = height / resize_factor;
this.resize_factor = resize_factor;
sandbox = new Tile[width, height];
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
sandbox[i, j] = new Tile(i, j, this, "air");
}
}
}
internal Tile Get(int x, int y)
{
try
{
return sandbox[x, y];
}
catch (System.NullReferenceException)
{
return null;
}
catch (IndexOutOfRangeException)
{
return new Tile(x, y, this, "sand");
}
}
internal void Set(int x, int y, Tile tile)
{
try
{
sandbox[x, y] = tile;
}
catch (System.NullReferenceException)
{
}
catch (IndexOutOfRangeException)
{
}
}
internal void Paint(int x, int y, string type, int brush_size)
{
try
{
for (int i = 0; i < brush_size; i++)
{
for (int j = 0; j < brush_size; j++)
{
sandbox[x + i, y + j] = new Tile(x + i, y + j, this, type);
}
}
}
catch (System.NullReferenceException)
{
}
catch (IndexOutOfRangeException)
{
}
}
internal void Draw()
{
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
try
{
if (!(sandbox[i, j].type == "air"))
{
Raylib.DrawRectangle(i * resize_factor, j * resize_factor, resize_factor, resize_factor, sandbox[i, j].color);
}
}
catch (System.NullReferenceException)
{
}
}
}
}
internal void Update()
{
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
try
{
if (!(sandbox[i, j].type == "air") && !(sandbox[i, j].updated))
{
sandbox[i, j].Update();
}
else if (sandbox[i, j].updated)
{
sandbox[i, j].updated = false;
}
}
catch (System.NullReferenceException)
{
}
}
}
}
}
}