-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapa.py
116 lines (81 loc) · 4.39 KB
/
mapa.py
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
import sys
import pygame
import csv
from enum import Enum
from config_jogo import ConfigJogo
from utils import ler_imagem
class TileType(Enum):
GRAMA = 0
DESTRUTIVEL_C = 1
DESTRUTIVEL_M = 2
FIXA = 3
class Mapa:
def __init__(self):
self.grama = ler_imagem('map/grama.png', (ConfigJogo.TAM_TILE, ConfigJogo.TAM_TILE))
self.destrutivel_c = ler_imagem('map/parede-destruivel.png', (ConfigJogo.TAM_TILE, ConfigJogo.TAM_TILE))
self.destrutivel_m = ler_imagem('map/parede-destruivel-marrom.png', (ConfigJogo.TAM_TILE, ConfigJogo.TAM_TILE))
self.fixa = ler_imagem('map/parede-fixa.png', (ConfigJogo.TAM_TILE, ConfigJogo.TAM_TILE))
self.map_matrix = []
with open(ConfigJogo.MAPA, newline='') as csvfile:
spamreader = csv.reader(csvfile)
for linha in spamreader:
linha = [int(valor) for valor in linha]
self.map_matrix.append(linha)
def desenha(self, tela: pygame.Surface):
for lin_idx in range(len(self.map_matrix)):
py = (lin_idx * ConfigJogo.TAM_TILE) + ConfigJogo.ALTURA_MENU
for col_idx in range(len(self.map_matrix[0])):
px = col_idx * ConfigJogo.TAM_TILE
if self.map_matrix[lin_idx][col_idx] == TileType.GRAMA.value:
tela.blit(self.grama, (px, py))
elif self.map_matrix[lin_idx][col_idx] == TileType.DESTRUTIVEL_C.value:
tela.blit(self.destrutivel_c, (px, py))
elif self.map_matrix[lin_idx][col_idx] == TileType.DESTRUTIVEL_M.value:
tela.blit(self.destrutivel_m, (px, py))
elif self.map_matrix[lin_idx][col_idx] == TileType.FIXA.value:
tela.blit(self.fixa, (px, py))
def is_any_wall(self, x, y):
y -= ConfigJogo.ALTURA_MENU
lin_idx_c_e = y // ConfigJogo.TAM_TILE
col_idx_c_e = x // ConfigJogo.TAM_TILE
lin_idx_b_d = (y + ConfigJogo.TAM_TILE - 1) // ConfigJogo.TAM_TILE
col_idx_b_d = (x + ConfigJogo.TAM_TILE - 1) // ConfigJogo.TAM_TILE
for lin_idx in range(lin_idx_c_e, lin_idx_b_d + 1):
for col_idx in range(col_idx_c_e, col_idx_b_d + 1):
if 0 <= lin_idx < len(self.map_matrix) and 0 <= col_idx < len(self.map_matrix[0]):
tile_type = self.map_matrix[lin_idx][col_idx]
if tile_type != TileType.GRAMA.value:
return True
def is_fixed_wall(self, x, y):
y -= ConfigJogo.ALTURA_MENU
lin_idx_c_e = y // ConfigJogo.TAM_TILE
col_idx_c_e = x // ConfigJogo.TAM_TILE
lin_idx_b_d = (y + ConfigJogo.TAM_TILE - 1) // ConfigJogo.TAM_TILE
col_idx_b_d = (x + ConfigJogo.TAM_TILE - 1) // ConfigJogo.TAM_TILE
for lin_idx in range(lin_idx_c_e, lin_idx_b_d + 1):
for col_idx in range(col_idx_c_e, col_idx_b_d + 1):
if 0 <= lin_idx < len(self.map_matrix) and 0 <= col_idx < len(self.map_matrix[0]):
tile_type = self.map_matrix[lin_idx][col_idx]
if tile_type == TileType.FIXA.value:
return True
def destrutivel(self, x, y):
y -= ConfigJogo.ALTURA_MENU
lin_idx_c_e = y // ConfigJogo.TAM_TILE
col_idx_c_e = x // ConfigJogo.TAM_TILE
lin_idx_b_d = (y + ConfigJogo.TAM_TILE - 1) // ConfigJogo.TAM_TILE
col_idx_b_d = (x + ConfigJogo.TAM_TILE - 1) // ConfigJogo.TAM_TILE
for lin_idx in range(int(lin_idx_c_e), int(lin_idx_b_d + 1)):
for col_idx in range(int(col_idx_c_e), int(col_idx_b_d + 1)):
if 0 <= lin_idx < len(self.map_matrix) and 0 <= col_idx < len(self.map_matrix[0]):
tile_type = self.map_matrix[lin_idx][col_idx]
if tile_type == TileType.DESTRUTIVEL_C.value:
return TileType.DESTRUTIVEL_C.value
elif tile_type == TileType.FIXA.value or tile_type == TileType.DESTRUTIVEL_M.value:
return TileType.FIXA.value
else:
return TileType.GRAMA.value
def explodirBloco(self, lin, col, explosao):
if explosao == 0:
self.map_matrix[lin][col] = TileType.DESTRUTIVEL_M.value
else:
self.map_matrix[lin][col] = TileType.GRAMA.value