-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatforms.py
171 lines (136 loc) · 5.64 KB
/
platforms.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import pygame
from pygame import *
from Mob import Mob
import pyganim
PLATFORM_WIDTH = 40
PLATFORM_HEIGHT = 40
SEWER_WIDTH = 80
SEWER_HEIGHT = 100
COLOR = (0, 0, 0)
ANIMATION_DELAY = 130
COIN_ANIMATION = [("images/coin_0.png"), ("images/coin_1.png"),
("images/coin_2.png"), ("images/coin_3.png")]
SPECIAL_BLOCK_ANIMATION = [("images/special_block_0.png"), ("images/special_block_1.png"),
("images/special_block_2.png"), ("images/special_block_1.png"),
("images/special_block_0.png")]
class Flour(sprite.Sprite):
# Базовый класс - кирпич для пола (кирпичный блок)
def __init__(self, x, y):
sprite.Sprite.__init__(self)
self.rect = Rect(x, y, PLATFORM_WIDTH, PLATFORM_HEIGHT)
picture = pygame.image.load("images/flour.png")
picture = pygame.transform.scale(picture, (40, 40))
self.image = picture
class Platform(sprite.Sprite):
def __init__(self, x, y):
sprite.Sprite.__init__(self)
self.rect = Rect(x, y, PLATFORM_WIDTH, PLATFORM_HEIGHT)
picture = pygame.image.load("images/block.png")
picture = pygame.transform.scale(picture, (40, 40))
self.image = picture
class Stairs(Flour):
def __init__(self, x, y):
Flour.__init__(self, x, y)
picture = pygame.image.load("images/stair.png")
picture = pygame.transform.scale(picture, (40, 40))
self.image = picture
class Special_Platform(Flour):
# Блок с вопросом
def __init__(self, x, y, type):
Flour.__init__(self, x, y)
self.image = image.load("images/special_block.png")
self.type = type
# Анимация блока
boltAnim = []
for anim in SPECIAL_BLOCK_ANIMATION:
boltAnim.append((anim, ANIMATION_DELAY))
self.boltAnimSpec = pyganim.PygAnimation(boltAnim)
self.boltAnimSpec.play()
def update(self):
self.image.fill(Color(COLOR))
self.boltAnimSpec.blit(self.image, (0, 0))
class Coin(Flour):
# Монетка
def __init__(self, x, y):
Flour.__init__(self, x, y)
self.image = image.load("images/special_block.png")
self.image.set_colorkey(Color(COLOR))
# Анимация монетки
boltAnim = []
for anim in COIN_ANIMATION:
boltAnim.append((anim, ANIMATION_DELAY))
self.boltAnimCoin = pyganim.PygAnimation(boltAnim)
self.boltAnimCoin.play()
def update(self):
self.image.fill(Color(COLOR))
self.boltAnimCoin.blit(self.image, (0, 0))
class Sewer(Flour):
# Труба
def __init__(self, x, y, status, mark):
Flour.__init__(self, x, y)
self.mark = mark
if self.mark == "tube_1":
self.image = image.load("images/sewer.png")
self.rect = Rect(x, y, SEWER_WIDTH, SEWER_HEIGHT)
elif self.mark == "tube_2":
picture = pygame.image.load("images/tube_3.png")
self.rect = Rect(x, y, 80, 180)
self.image = picture
else:
picture = pygame.image.load("images/biigest_tube.png")
self.rect = Rect(x, y, 80, 220)
self.image = picture
self.status = status
# class Mushroom(Platform):
# #грибы
# def __init__(self, x, y):
# Platform.__init__(self, x, y)
# self.image = image.load()
def get_sprites(coordinates, type):
# Получение структуры уровня
amount = 1
direction = "ver"
sprites = []
for line in coordinates:
x = line[0]
y = line[1]
# По умолчанию отрисовывается один блок по вертикали. Но если coordinates - это список обычных кирпичных блоков,
# там значения количества рисуемых блоков и направление отрисовки могут быть иными. Поэтому достаем amount
# и direction из списка
if type == "flour" or type == "simple" or type == "stair":
direction = line[3]
amount = line[2]
for i in range(amount):
if type == "flour":
sprite = Flour(x, y)
elif type == "simple":
sprite = Platform(x, y)
elif type == "special":
sprite = Special_Platform(x, y, line[2])
elif type == "mobs":
sprite = Mob(x, y)
elif type == "sewer":
mark = line[3]
sprite = Sewer(x, y, line[2], mark)
elif type == "stair":
sprite = Stairs(x, y)
else:
sprite = Coin(x, y)
sprite.boltAnimCoin.blit(sprite.image, (0, 0))
if direction == "hor":
x += PLATFORM_WIDTH
else:
y += PLATFORM_HEIGHT
sprites.append(sprite)
return sprites
def get_needed_platform(temp_blocks, blocks):
# Функция, которая возвращает даннные о блоке с вопросом, которые активировал игрок
for i in temp_blocks:
if i not in blocks:
return i
def get_status_from_sewer(x, sewers):
# Функция, возращающая статус трубы - является она телепортом на скрытый уровень или нет. Если является -
# возвращается номер скрытого уровня
for i in sewers:
if i.rect.left < x and i.rect.right > x:
return i.status