forked from RuslanShafeev/marivo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapBase.py
106 lines (88 loc) · 3.45 KB
/
MapBase.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
101
102
103
104
105
106
from Tile import *
from Player import Player
from Goomba import Goomba
from Tube import Tube
from Koopa import Koopa, JumpingKoopa
from Castle import Castle
from FlagPole import FlagPole
class MapBase:
"""Класс карты. Занимается созданием отдельных видов спрайтов, хранит в себе самые
важные объекты для удобного доступа из других модулей. Иными словами, занимается конвертацией
загруженного json в питоновские объекты"""
RIGHT_ADD = 12
def __init__(self, world_type, width, height):
self.world_type = world_type
self.width = width
self.height = height
self.castle = None
self.flagpole = None
self.player = None
def add_castle(self, x, y, is_big):
self.castle = Castle(x, y, is_big)
def add_flagpole(self, x, y):
self.flagpole = FlagPole(x, y)
def add_goombas(self, goombas):
for y in goombas:
for x in goombas[y]:
Goomba(x, y, self.world_type)
def add_koopas(self, koopas):
for y in koopas:
for x in koopas[y]:
Koopa(x, y, self.world_type)
def add_jkoopas(self, jkoopas):
for y in jkoopas:
for x in jkoopas[y]:
JumpingKoopa(x, y, self.world_type)
def add_quests(self, quests, sizeup=[], liveup=[], star=[], flower=[]):
for y in quests:
for x in quests[y]:
quest = 'Coin'
if [x, y] in sizeup:
quest = 'MushroomSizeUp'
elif [x, y] in liveup:
quest = 'MushroomLiveUp'
elif [x, y] in star:
quest = 'Star'
elif [x, y] in flower:
quest = 'FireFlower'
Quest(x, y, self.world_type, quest)
def add_tiles(self, tile_class, tiles):
for y in tiles:
for x in tiles[y]:
tile_class(x, y, self.world_type)
def add_bonus_brick(self, tiles):
for x, y, bonus in tiles:
Brick(x, y, self.world_type, bonus)
def add_enemies(self, enemy_class, enemies):
for y in enemies:
for x in enemies[y]:
enemy_class(x, y, self.world_type)
def add_floor(self, empty):
for i in range(1, self.width + MapBase.RIGHT_ADD + 1):
if i in empty:
continue
Floor(i, 13, self.world_type)
Floor(i, 14, self.world_type)
def add_tubes(self, tubes):
for y in tubes:
for x, pow in tubes[y]:
Tube(x, y, pow)
def add_decor(self, grass_hills=[], grass=[], clouds=[]):
for y in grass_hills:
for x, h in grass_hills[y]:
GrassHill(x, y, h)
for y in grass:
for x in grass[y]:
Grass(x, y)
for y in clouds:
for x in clouds[y]:
Cloud(x, y)
def add_invisible_tile(self, tiles):
for x, y, bonus in tiles:
InvincibleTile(x, y, self.world_type, bonus)
def add_world_name(self, world_name):
"""Сохраняет название мира для hud"""
self.world_name = world_name
def add_player(self, coords, state, type):
self.player = Player(*coords, state, type, self.world_type)
return self.player