-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCalculateGameView
More file actions
41 lines (32 loc) · 1.66 KB
/
Copy pathCalculateGameView
File metadata and controls
41 lines (32 loc) · 1.66 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
//Draw the gameview
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
int GVOriginX, GVOriginY;
GVOriginX = fov.Player.X - iViewWidth / 2;
GVOriginY = fov.Player.Y - iViewHeight / 2;
if (GVOriginX < 0)
GVOriginX = 0;
else if (GVOriginX + iViewWidth > fov.map.GetLength(0))
GVOriginX -= (GVOriginX + iViewWidth - fov.map.GetLength(0));
if (GVOriginY < 0)
GVOriginY = 0;
else if (GVOriginY + iViewHeight > fov.map.GetLength(1))
GVOriginY -= (GVOriginY + iViewHeight - fov.map.GetLength(1));
for (int x = 0 ; x < iViewWidth; x++)
for (int y = 0; y < iViewHeight; y++)
if (fov.map[x + GVOriginX, y + GVOriginY] == 0)
{
//draw the bFloor in the specified point
e.Graphics.DrawImage(bFloor, new Point(x * iTileWidth,
y * iTileHeight));
//FOV Algorithm:
//if the map cell being drawn is not contained in
//the VisualPoints list generated by the FOV algorithm, draw the fog over it
if (!fov.VisiblePoints.Contains(new Point(x + GVOriginX, y + GVOriginY)))
e.Graphics.DrawImage(bFog, new Point(x * iTileWidth
, y * iTileHeight));
}
//draw the bPlayer bitmap in the specified point
e.Graphics.DrawImage(bPlayer, new Point((fov.Player.X - GVOriginX) * iTileWidth
, (fov.Player.Y - GVOriginY) * iTileHeight ));
}