-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_cardoom_3d_view.py
More file actions
92 lines (78 loc) · 2.71 KB
/
map_cardoom_3d_view.py
File metadata and controls
92 lines (78 loc) · 2.71 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
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
# World map from bit code; 0 - Nothing, 1 - Walls
# Please note: The walls are rendered and displayed differently than in the main game; their approximate locations are simply shown here.
MAP = [
1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,0,0,0,0,1,0,1,
1,0,1,0,0,0,0,1,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,1,0,1,1,0,1,0,1,
1,0,1,0,0,0,0,1,0,1,
1,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1
]
MAP_SIZE = 10
def create_cube(x, y, z, size=1):
vertices = [
[x, y, z],
[x + size, y, z],
[x + size, y + size, z],
[x, y + size, z],
[x, y, z + size],
[x + size, y, z + size],
[x + size, y + size, z + size],
[x, y + size, z + size]
]
faces = [
[vertices[0], vertices[1], vertices[5], vertices[4]],
[vertices[2], vertices[3], vertices[7], vertices[6]],
[vertices[0], vertices[3], vertices[7], vertices[4]],
[vertices[1], vertices[2], vertices[6], vertices[5]],
[vertices[0], vertices[1], vertices[2], vertices[3]],
[vertices[4], vertices[5], vertices[6], vertices[7]]
]
return faces
def draw_map_3d():
fig = plt.figure(figsize=(12, 10))
ax = fig.add_subplot(111, projection='3d')
for y in range(MAP_SIZE):
for x in range(MAP_SIZE):
index = y * MAP_SIZE + x
if MAP[index] == 1:
faces = create_cube(x, y, 0, 1)
poly = Poly3DCollection(faces,
facecolors='darkgray',
linewidths=1,
edgecolors='black',
alpha=0.9)
ax.add_collection3d(poly)
floor_vertices = [
[0, 0, 0],
[MAP_SIZE, 0, 0],
[MAP_SIZE, MAP_SIZE, 0],
[0, MAP_SIZE, 0]
]
floor_poly = Poly3DCollection([floor_vertices],
facecolors='lightblue',
alpha=0.3,
edgecolors='blue')
ax.add_collection3d(floor_poly)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_xlim(0, MAP_SIZE)
ax.set_ylim(0, MAP_SIZE)
ax.set_zlim(0, 2)
ax.set_title('3D visualization of the map as a model\n(Use your mouse to rotate)',
fontsize=14, fontweight='bold')
ax.view_init(elev=30, azim=45)
plt.tight_layout()
plt.show()
if __name__ == "__main__":
print("Loading...")
draw_map_3d()