Repository navigation
Expand file tree
/
Copy pathdemo_grid_effects.py
More file actions
309 lines (233 loc) · 9.42 KB
/
Copy pathdemo_grid_effects.py
File metadata and controls
309 lines (233 loc) · 9.42 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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#
# cocos2d
# http://python.cocos2d.org
#
# Particle Engine done by Phil Hassey
# http://www.imitationpickles.org
#
from __future__ import division, print_function, unicode_literals
import six
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
import pyglet
from pyglet.gl import *
from cocos.director import *
from cocos.menu import *
from cocos.scene import *
from cocos.layer import *
from cocos.actions import *
from cocos.sprite import Sprite
import random
rr = random.randrange
class Fire:
def __init__(self, x, y, vy, frame, size):
self.x, self.y, self.vy, self.frame, self.size = x, y, vy, frame, size
class FireManager(Layer):
def __init__(self, view_width, num):
super(FireManager, self).__init__()
self.view_width = view_width
self.goodies = []
self.batch = pyglet.graphics.Batch()
self.fimg = pyglet.resource.image('fire.jpg')
self.group = pyglet.sprite.SpriteGroup(self.fimg.texture,
blend_src=GL_SRC_ALPHA, blend_dest=GL_ONE)
self.vertex_list = self.batch.add(4 * num, GL_QUADS, self.group,
'v2i', 'c4B', ('t3f', self.fimg.texture.tex_coords * num))
for n in range(0, num):
f = Fire(0, 0, 0, 0, 0)
self.goodies.append(f)
self.vertex_list.vertices[n * 8:(n + 1) * 8] = [0, 0, 0, 0, 0, 0, 0, 0]
self.vertex_list.colors[n * 16:(n + 1) * 16] = [0, 0, 0, 0, ] * 4
self.schedule(self.step)
def step(self, dt):
w, h = self.fimg.width, self.fimg.height
fires = self.goodies
verts, clrs = self.vertex_list.vertices, self.vertex_list.colors
for n, f in enumerate(fires):
if not f.frame:
f.x = rr(0, self.view_width)
f.y = rr(-120, -80)
f.vy = rr(40, 70) / 100.0
f.frame = rr(50, 250)
f.size = 8 + pow(rr(0.0, 100) / 100.0, 2.0) * 32
f.scale = f.size / 32.0
x = f.x = f.x + rr(-50, 50) / 100.0
y = f.y = f.y + f.vy * 4
c = 3 * f.frame / 255.0
r, g, b = (min(255, int(c * 0xc2)), min(255, int(c * 0x41)), min(255, int(c * 0x21)))
f.frame -= 1
ww, hh = w * f.scale, h * f.scale
x -= ww / 2
if six.PY2:
vs = map(int, [x, y, x + ww, y, x + ww, y + hh, x, y + hh])
else:
vs = list(map(int, [x, y, x + ww, y, x + ww, y + hh, x, y + hh]))
verts[n * 8:(n + 1) * 8] = vs
clrs[n * 16:(n + 1) * 16] = [r, g, b, 255] * 4
def draw(self):
glPushMatrix()
self.transform()
self.batch.draw()
glPopMatrix()
class SpriteLayer(Layer):
def __init__(self):
super(SpriteLayer, self).__init__()
sprite1 = Sprite('grossini.png')
sprite2 = Sprite('grossinis_sister1.png')
sprite3 = Sprite('grossinis_sister2.png')
sprite1.position = (320, 240)
sprite2.position = (620, 100)
sprite3.position = (20, 100)
self.add(sprite1)
self.add(sprite2)
self.add(sprite3)
ju_right = JumpBy((600, 0), height=100, jumps=4, duration=5)
ju_left = JumpBy((-600, 0), height=100, jumps=4, duration=5)
rot1 = Rotate(180 * 4, duration=5)
sprite1.opacity = 128
sc = ScaleBy(9, 5)
rot = Rotate(180, 5)
sprite1.do(Repeat(sc + Reverse(sc)))
sprite1.do(Repeat(rot + Reverse(rot)))
sprite2.do(Repeat(ju_left + Reverse(ju_left)))
sprite2.do(Repeat(Reverse(rot1) + rot1))
sprite3.do(Repeat(ju_right + Reverse(ju_right)))
sprite3.do(Repeat(rot1 + Reverse(rot1)))
class MainMenu(Menu):
def __init__(self):
# call superclass with the title
super(MainMenu, self).__init__("GROSSINI'S SISTERS")
pyglet.font.add_directory('.')
# you can override the font that will be used for the title and the items
self.font_title['font_name'] = 'You Are Loved'
self.font_title['font_size'] = 72
self.font_item['font_name'] = 'You Are Loved'
self.font_item_selected['font_name'] = 'You Are Loved'
# you can also override the font size and the colors. see menu.py for
# more info
# example: menus can be vertical aligned and horizontal aligned
self.menu_valign = CENTER
self.menu_halign = CENTER
items = []
items.append(MenuItem('New Game', self.on_new_game))
items.append(MenuItem('Options', self.on_options))
items.append(MenuItem('Scores', self.on_scores))
items.append(MenuItem('Quit', self.on_quit))
self.create_menu(items, zoom_in(), zoom_out())
# Callbacks
def on_new_game(self):
# director.set_scene(StartGame())
print("on_new_game()")
def on_scores(self):
self.parent.switch_to(2)
def on_options(self):
self.parent.switch_to(1)
def on_quit(self):
director.pop()
class OptionMenu(Menu):
def __init__(self):
super(OptionMenu, self).__init__("GROSSINI'S SISTERS")
self.font_title['font_name'] = 'You Are Loved'
self.font_title['font_size'] = 72
self.font_item['font_name'] = 'You Are Loved'
self.font_item_selected['font_name'] = 'You Are Loved'
self.menu_valign = BOTTOM
self.menu_halign = RIGHT
items = []
items.append(MenuItem('Fullscreen', self.on_fullscreen))
items.append(ToggleMenuItem('Show FPS: ', self.on_show_fps, True))
items.append(MenuItem('OK', self.on_quit))
self.create_menu(items, shake(), shake_back())
# Callbacks
def on_fullscreen(self):
director.window.set_fullscreen(not director.window.fullscreen)
def on_quit(self):
self.parent.switch_to(0)
def on_show_fps(self, value):
director.show_FPS = value
class ScoreMenu(Menu):
def __init__(self):
super(ScoreMenu, self).__init__("GROSSINI'S SISTERS")
self.font_title['font_name'] = 'You Are Loved'
self.font_title['font_size'] = 72
self.font_item['font_name'] = 'You Are Loved'
self.font_item_selected['font_name'] = 'You Are Loved'
self.menu_valign = BOTTOM
self.menu_halign = LEFT
self.create_menu([MenuItem('Go Back', self.on_quit)])
def on_quit(self):
self.parent.switch_to(0)
def init():
director.init(resizable=True, width=640, height=480)
def start():
director.set_depth_test()
firelayer = FireManager(director.get_window_size()[0], 250)
spritelayer = SpriteLayer()
menulayer = MultiplexLayer(MainMenu(), OptionMenu(), ScoreMenu())
scene = Scene(firelayer, spritelayer, menulayer)
twirl_normal = Twirl(center=(320, 240), grid=(16, 12), duration=15, twirls=6, amplitude=6)
twirl = AccelDeccelAmplitude(twirl_normal, rate=4.0)
lens = Lens3D(radius=240, center=(320, 240), grid=(32, 24), duration=5)
waves3d = AccelDeccelAmplitude(
Waves3D(waves=18, amplitude=80, grid=(32, 24), duration=15), rate=4.0)
flipx = FlipX3D(duration=1)
flipy = FlipY3D(duration=1)
flip = Flip(duration=1)
liquid = Liquid(grid=(16, 12), duration=4)
ripple = Ripple3D(grid=(32, 24), waves=7, duration=10, amplitude=100, radius=320)
shakyt = ShakyTiles3D(grid=(16, 12), duration=3)
corners = CornerSwap(duration=1)
waves = AccelAmplitude(Waves(waves=8, amplitude=50, grid=(32, 24), duration=5), rate=2.0)
shaky = Shaky3D(randrange=10, grid=(32, 24), duration=5)
quadmove = QuadMoveBy(
delta0=(320, 240), delta1=(-630, 0), delta2=(-320, -240), delta3=(630, 0), duration=2)
fadeout = FadeOutTRTiles(grid=(16, 12), duration=2)
cornerup = MoveCornerUp(duration=1)
cornerdown = MoveCornerDown(duration=1)
shatter = ShatteredTiles3D(randrange=16, grid=(16, 12), duration=4)
shuffle = ShuffleTiles(grid=(16, 12), duration=1)
orbit = OrbitCamera(
radius=1, delta_radius=2, angle_x=0, delta_x=-90, angle_z=0, delta_z=180, duration=4)
jumptiles = JumpTiles3D(jumps=2, duration=4, amplitude=80, grid=(16, 12))
wavestiles = WavesTiles3D(waves=3, amplitude=60, duration=8, grid=(16, 12))
turnoff = TurnOffTiles(grid=(16, 12), duration=2)
# firelayer.do(
# spritelayer.do(
# menulayer.do(
scene.do(
Delay(3) +
ripple + Delay(2) +
wavestiles + Delay(1) +
twirl +
liquid + Delay(2) +
shakyt + Delay(2) +
ReuseGrid() +
shuffle + Delay(4) + ReuseGrid() + turnoff + Reverse(turnoff) + Delay(1) +
shatter +
flip + Delay(2) +
Reverse(flip) +
flipx + Delay(2) + ReuseGrid() +
flipy + Delay(2) + ReuseGrid() +
flipx + Delay(2) + ReuseGrid() +
flipy + Delay(2) +
lens + ReuseGrid() + ((orbit + Reverse(orbit)) | waves3d) + Delay(1) +
corners + Delay(2) + Reverse(corners) +
waves + Delay(2) + ReuseGrid() + shaky +
jumptiles + Delay(1) +
cornerup + Delay(1) +
Reverse(cornerdown) + Delay(1) +
fadeout + Reverse(fadeout) + Delay(2) +
quadmove + Delay(1) +
Reverse(quadmove) +
StopGrid()
)
scene.do(Delay(10) + OrbitCamera(delta_z=-360 * 3, duration=10 * 4))
firelayer.do(Delay(4) + Repeat(RotateBy(360, 10)))
return scene
def run(scene):
director.run(scene)
if __name__ == "__main__":
init()
s = start()
run(s)