-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.py
More file actions
104 lines (94 loc) · 3.82 KB
/
map.py
File metadata and controls
104 lines (94 loc) · 3.82 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
import pygame as pg
_ = False
mini_map = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
[1, _, _, 3, 3, 3, 3, _, _, _, 3, 1, 1, _, _, 1],
[1, _, _, _, _, _, 4, _, _, _, _, _, 1, _, _, 1],
[1, _, _, _, _, _, 4, _, _, _, _, _, 3, _, _, 1],
[1, _, _, 3, 3, 3, 3, _, _, _, _, _, _, _, _, 1],
[1, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
[1, _, _, _, 4, _, _, _, 4, _, _, _, _, _, _, 1],
[1, 1, 1, 3, 1, 3, 1, 1, 1, 3, _, _, 3, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 3, _, _, 3, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 3, _, _, 3, 1, 1, 1],
[1, 1, 3, 1, 1, 1, 1, 1, 1, 3, _, _, 3, 1, 1, 1],
[1, 4, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
[1, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
[1, _, _, 2, _, _, _, _, _, 3, 4, _, 4, 3, _, 1],
[1, _, _, 5, _, _, _, _, _, _, 3, _, 3, _, _, 1],
[1, _, _, 2, _, _, _, _, _, _, _, _, _, _, _, 1],
[1, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
[1, 4, _, _, _, _, _, _, 4, _, _, 4, _, _, _, 1],
[1, 1, 3, 3, _, _, 3, 3, 1, 3, 3, 1, 3, 1, 1, 1],
[1, 1, 1, 3, _, _, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 3, 3, 4, _, _, 4, 3, 3, 3, 3, 3, 3, 3, 3, 1],
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 3],
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 3],
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 3],
[3, _, _, 5, _, _, _, 5, _, _, _, 5, _, _, _, 3],
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 3],
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 3],
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 3],
[3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
]
class Map:
"""Class for the map"""
def __init__(self, game):
"""Initialize the map"""
self.game = game
self.mini_map = mini_map
self.world_map = {}
self.rows = len(self.mini_map)
self.cols = len(self.mini_map[0])
self.get_map()
def get_map(self):
"""Get the map"""
for j, row in enumerate(self.mini_map):
for i, value in enumerate(row):
if value:
self.world_map[(i, j)] = value
def draw(self):
"""Draw untextured map"""
[
pg.draw.rect(
self.game.screen, "darkgray", (pos[0] * 100, pos[1] * 100, 100, 100), 2
)
for pos in self.world_map
]
# Draw minimap
def draw_minimap(self):
# Set scale offset and size
mini_map_scale = 8 # Adjust the scale as needed
mini_map_offset = (self.game.screen.get_width() - self.cols * mini_map_scale, 0)
mini_map_size = (self.cols * mini_map_scale, self.rows * mini_map_scale)
# Draw the background rectangle
pg.draw.rect(
self.game.screen,
(50, 50, 50),
(
mini_map_offset[0],
mini_map_offset[1],
mini_map_size[0],
mini_map_size[1],
),
)
# Draw the map tiles
for pos, value in self.world_map.items():
mini_map_x = pos[0] * mini_map_scale + mini_map_offset[0]
mini_map_y = pos[1] * mini_map_scale + mini_map_offset[1]
pg.draw.rect(
self.game.screen,
"darkgray",
(mini_map_x, mini_map_y, mini_map_scale, mini_map_scale),
2,
)
# Draw the player marker on the mini-map
player = self.game.player
player_mini_map_x = int(player.x * mini_map_scale) + mini_map_offset[0]
player_mini_map_y = int(player.y * mini_map_scale) + mini_map_offset[1]
pg.draw.circle(
self.game.screen, (255, 0, 0), (player_mini_map_x, player_mini_map_y), 3
)