annotate pytouhou/game/effect.py @ 329:1bb78c469f64

Fix difficulty influence on bullet launch interval, and fix instruction 77's rand usage
author Thibaut Girka <thib@sitedethib.com>
date Sun, 24 Jun 2012 17:00:07 +0200
parents 56523a16db1d
children bdcf2077e368
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
173
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 ##
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 ## Copyright (C) 2011 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 ##
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 ## it under the terms of the GNU General Public License as published
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 ## by the Free Software Foundation; version 3 only.
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 ##
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 ## This program is distributed in the hope that it will be useful,
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 ## GNU General Public License for more details.
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ##
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 from pytouhou.game.sprite import Sprite
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 from pytouhou.vm.anmrunner import ANMRunner
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
18 from pytouhou.utils.interpolator import Interpolator
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
19 from math import pi
173
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 class Effect(object):
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 def __init__(self, pos, index, anm_wrapper):
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
25 self.sprite = Sprite()
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
26 self.anmrunner = ANMRunner(anm_wrapper, index, self.sprite)
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
27 self.anmrunner.run_frame()
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
28 self.removed = False
173
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 self.x, self.y = pos
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
32
173
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 def update(self):
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
34 if self.anmrunner and not self.anmrunner.run_frame():
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
35 self.anmrunner = None
173
35d850502d1f Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
37 if self.sprite:
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
38 if self.sprite.removed:
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
39 self.sprite = None
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
40
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
41
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
42
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
43 class Particle(object):
193
9f58e2a6e950 Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 190
diff changeset
44 def __init__(self, start_pos, index, anm_wrapper, size, amp, game):
190
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
45 self._game = game
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
46
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
47 self.sprite = Sprite()
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
48 self.sprite.anm, self.sprite.texcoords = anm_wrapper.get_sprite(index)
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
49 self.removed = False
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
50
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
51 self.x, self.y = start_pos
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
52 self.frame = 0
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
53 self.sprite.alpha = 128
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
54 self.sprite.blendfunc = 1
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
55 self.sprite.rescale = (size, size)
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
56
190
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
57 self.pos_interpolator = None
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
58 self.scale_interpolator = None
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
59 self.rotations_interpolator = None
328
56523a16db1d Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
60 self.alpha_interpolator = None
190
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
61
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
62 self.amp = amp
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
63
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
64
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
65 def set_end_pos(self, amp):
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
66 end_pos = (self.x + amp * self._game.prng.rand_double() - amp/2,
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
67 self.y + amp * self._game.prng.rand_double() - amp/2)
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
68
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
69 self.pos_interpolator = Interpolator((self.x, self.y), 0,
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
70 end_pos, 24, formula=(lambda x: 2. * x - x ** 2))
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
71 self.scale_interpolator = Interpolator(self.sprite.rescale, 0,
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
72 (0., 0.), 24)
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
73 self.rotations_interpolator = Interpolator(self.sprite.rotations_3d, 0,
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
74 (0., 0., 2*pi), 24)
328
56523a16db1d Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
75 self.alpha_interpolator = Interpolator((self.sprite.alpha,), 0,
56523a16db1d Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
76 (0.,), 24)
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
77
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
78
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
79 def update(self):
193
9f58e2a6e950 Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 190
diff changeset
80 if self.frame == 0:
190
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
81 self.set_end_pos(self.amp)
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
82
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
83 if self.pos_interpolator:
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
84 self.pos_interpolator.update(self.frame)
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
85 self.x, self.y = self.pos_interpolator.values
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
86
190
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
87 self.scale_interpolator.update(self.frame)
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
88 self.sprite.rescale = self.scale_interpolator.values
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
89
190
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
90 self.rotations_interpolator.update(self.frame)
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
91 self.sprite.rotations_3d = self.rotations_interpolator.values
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
92
328
56523a16db1d Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
93 self.alpha_interpolator.update(self.frame)
56523a16db1d Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
94 self.sprite.alpha, = self.alpha_interpolator.values
56523a16db1d Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
95
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
96 self.sprite.changed = True
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
97
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
98 if self.frame == 24:
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
99 self.removed = True
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
100
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
101 self.frame += 1
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
102