-
Notifications
You must be signed in to change notification settings - Fork 1
/
stage.py
223 lines (199 loc) · 7.95 KB
/
stage.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
from __future__ import with_statement
import pygame
import util
import gameobject
import animation
STAGE_INTRO = 0
STAGE_0 = 1
STAGE_1 = 2
STAGE_2 = 3
STAGE_3 = 4
STAGE_4 = 5
STAGE_5 = 6
STAGE_6 = 7
STAGE_7 = 8
STAGE_8 = 9
STAGE_9 = 10
STAGE_10 = 11
STAGE_11 = 12
class Stage:
def __init__(self, player, space):
self.tiles = []
self.player = player
self.map_time = 60*2
self.game_objects = []
self.info_blocks = []
self.splosion_objects = []
self.keys = { gameobject.OBJECT_TYPE_KEY_RED : False,
gameobject.OBJECT_TYPE_KEY_GREEN : False,
gameobject.OBJECT_TYPE_KEY_BLUE : False }
def finished(self):
return (self.keys[gameobject.OBJECT_TYPE_KEY_RED] and self.keys[gameobject.OBJECT_TYPE_KEY_GREEN] and self.keys[gameobject.OBJECT_TYPE_KEY_BLUE])
def load(self, filepath, space):
import sys
#goal
doorblock = util.load_image("data/entity_door0.png")
# standard blocks
rblock = util.load_image("data/red_block16.png")
gblock = util.load_image("data/green_block16.png")
bblock = util.load_image("data/blue_block16.png")
wblock = util.load_image("data/bw_block16.png")
#keys
rkblock = util.load_image("data/red_key0.png")
gkblock = util.load_image("data/green_key0.png")
bkblock = util.load_image("data/blue_key0.png")
# movable
r_movableblock = util.load_image("data/red_movable_block0.png")
g_movableblock = util.load_image("data/green_movable_block0.png")
b_movableblock = util.load_image("data/blue_movable_block0.png")
with open(filepath) as f:
data = f.readlines()
xoffset = 7
yoffset = 3
for rnum, row in enumerate(data):
for cnum, col in enumerate(row):
movable = False
if col == '1':
block = r_movableblock
movable = True
type = gameobject.OBJECT_TYPE_RED
elif col == '2':
block = g_movableblock
movable = True
type = gameobject.OBJECT_TYPE_GREEN
elif col == '3':
block = b_movableblock
movable = True
type = gameobject.OBJECT_TYPE_BLUE
elif col == 'R':
block = rblock
type = gameobject.OBJECT_TYPE_RED
elif col == 'G':
block = gblock
type = gameobject.OBJECT_TYPE_GREEN
elif col == 'B':
block = bblock
type = gameobject.OBJECT_TYPE_BLUE
elif col == 'W':
block = wblock
type = gameobject.OBJECT_TYPE_BW
elif col == 'X':
block = rkblock
type = gameobject.OBJECT_TYPE_KEY_RED
elif col == 'Y':
block = gkblock
type = gameobject.OBJECT_TYPE_KEY_GREEN
elif col == 'Z':
block = bkblock
type = gameobject.OBJECT_TYPE_KEY_BLUE
elif col == 'D':
block = doorblock
type = gameobject.OBJECT_TYPE_GOAL
self.doorpos = (cnum * 16 - xoffset * 16, rnum * 16 - yoffset * 16)
elif col == 'P':
self.player.body.position = (cnum * 16 - xoffset * 16, rnum * 16 - yoffset * 16)
continue
else: continue
pos = util.vec2(cnum * 16 - xoffset * 16, rnum * 16 - yoffset * 16)
if (movable):
go = gameobject.MovableBlock(pos, util.to_sprite(block), space, type)
self.game_objects.append(go)
else:
go = gameobject.StaticBlock(pos, util.to_sprite(block), space, type)
self.tiles.append(go)
def collide(self,rect):
return rect.colliderect(self.camera.rect)
def draw(self,canvas):
for tile in self.tiles:
#discard items that should not be drawn
if self.collide(tile.sprite.rect):
tile.draw(canvas)
else:
#print tile.pos
pass
for splosion in self.splosion_objects:
splosion.draw(canvas)
for obj in self.game_objects:
obj.draw(canvas)
for inf in self.info_blocks:
inf.draw(canvas)
class StageIntro(Stage):
def __init__(self,camera, player, space):
Stage.__init__(self, player, space)
self.load("data/stage_intro.txt", space)
self.camera = camera
self.keys[gameobject.OBJECT_TYPE_KEY_RED] = True
self.keys[gameobject.OBJECT_TYPE_KEY_GREEN] = True
self.keys[gameobject.OBJECT_TYPE_KEY_BLUE] = True
class Stage0(Stage):
def __init__(self,camera, player, space):
Stage.__init__(self, player, space)
self.load("data/stage0.txt", space)
self.camera = camera
info0 = gameobject.InfoBlock(util.vec2(-64,16), "data/info_bubble0_0.png", space,"data/info_bubble0_")
info1 = gameobject.InfoBlock(util.vec2(32,16), "data/info_bubble1_0.png", space,"data/info_bubble1_")
info2 = gameobject.InfoBlock(util.vec2(304,16), "data/info_bubble2_0.png", space,"data/info_bubble2_",6,[0,1,2,3,5,5,6,6,5,5,6,6])
info3 = gameobject.InfoBlock(util.vec2(512,16), "data/info_bubble3_0.png", space,"data/info_bubble3_",7,[0,1,2,3,4,5,6,7,6,7,6,7],2)
self.info_blocks.append(info1)
self.info_blocks.append(info0)
self.info_blocks.append(info2)
self.info_blocks.append(info3)
class Stage1(Stage):
def __init__(self,camera, player, space):
Stage.__init__(self, player, space)
self.load("data/stage1.txt", space)
self.camera = camera
class Stage2(Stage):
def __init__(self,camera, player, space):
Stage.__init__(self, player, space)
self.load("data/stage2.txt", space)
self.camera = camera
class Stage3(Stage):
def __init__(self,camera, player, space):
Stage.__init__(self, player, space)
self.load("data/stage3.txt", space)
self.camera = camera
self.keys[gameobject.OBJECT_TYPE_KEY_GREEN] = True
self.keys[gameobject.OBJECT_TYPE_KEY_BLUE] = True
class Stage4(Stage):
def __init__(self,camera, player, space):
Stage.__init__(self, player, space)
self.load("data/stage4.txt", space)
self.camera = camera
class Stage5(Stage):
def __init__(self,camera, player, space):
Stage.__init__(self, player, space)
self.load("data/stage5.txt", space)
self.keys[gameobject.OBJECT_TYPE_KEY_GREEN] = True
self.keys[gameobject.OBJECT_TYPE_KEY_BLUE] = True
self.camera = camera
class Stage6(Stage):
def __init__(self,camera, player, space):
Stage.__init__(self, player, space)
self.load("data/stage6.txt", space)
self.camera = camera
class Stage7(Stage):
def __init__(self,camera, player, space):
Stage.__init__(self, player, space)
self.load("data/stage7.txt", space)
self.camera = camera
class Stage8(Stage):
def __init__(self,camera, player, space):
Stage.__init__(self, player, space)
self.load("data/stage8.txt", space)
self.camera = camera
class Stage9(Stage):
def __init__(self,camera, player, space):
Stage.__init__(self, player, space)
self.load("data/stage9.txt", space)
self.camera = camera
class Stage10(Stage):
def __init__(self,camera, player, space):
Stage.__init__(self, player, space)
self.load("data/stage10.txt", space)
self.camera = camera
class Stage11(Stage):
def __init__(self,camera, player, space):
Stage.__init__(self, player, space)
self.load("data/stage11.txt", space)
self.camera = camera