comparison pytouhou/game/particle.pyx @ 631:cd8a2baf468c

Move Particle to its own module, to not pollute pytouhou.game.effect.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 05 May 2015 14:49:22 +0200
parents
children
comparison
equal deleted inserted replaced
630:6c40f5840a06 631:cd8a2baf468c
1 # -*- encoding: utf-8 -*-
2 ##
3 ## Copyright (C) 2015 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
4 ##
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published
7 ## by the Free Software Foundation; version 3 only.
8 ##
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
13 ##
14
15 from pytouhou.game.game cimport Game
16
17
18 cdef class Particle(Effect):
19 def __init__(self, pos, index, anm, long amp, Game game, bint reverse=False, long duration=24):
20 Effect.__init__(self, pos, index, anm)
21
22 self.frame = 0
23 self.duration = duration
24
25 random_pos = (self.x + amp * game.prng.rand_double() - amp / 2,
26 self.y + amp * game.prng.rand_double() - amp / 2)
27
28 if not reverse:
29 self.pos_interpolator = Interpolator((self.x, self.y), 0,
30 random_pos, duration, formula=(lambda x: 2. * x - x ** 2))
31 else:
32 self.pos_interpolator = Interpolator(random_pos, 0,
33 (self.x, self.y), duration, formula=(lambda x: 2. * x - x ** 2))
34 self.x, self.y = random_pos
35
36
37 cpdef update(self):
38 Effect.update(self)
39
40 self.pos_interpolator.update(self.frame)
41 self.x, self.y = self.pos_interpolator.values
42
43 self.frame += 1