# HG changeset patch # User Emmanuel Gil Peyrot # Date 1430830162 -7200 # Node ID cd8a2baf468cedb8d38f74e9a0ce303a7b521b95 # Parent 6c40f5840a065189747bbdee21a1c59ffed86216 Move Particle to its own module, to not pollute pytouhou.game.effect. diff --git a/pytouhou/game/effect.pxd b/pytouhou/game/effect.pxd --- a/pytouhou/game/effect.pxd +++ b/pytouhou/game/effect.pxd @@ -1,12 +1,4 @@ from pytouhou.game.element cimport Element -from pytouhou.utils.interpolator cimport Interpolator cdef class Effect(Element): cpdef update(self) - - -cdef class Particle(Effect): - cdef long frame, duration - cdef Interpolator pos_interpolator - - cpdef update(self) diff --git a/pytouhou/game/effect.pyx b/pytouhou/game/effect.pyx --- a/pytouhou/game/effect.pyx +++ b/pytouhou/game/effect.pyx @@ -15,8 +15,6 @@ from pytouhou.game.sprite cimport Sprite from pytouhou.vm import ANMRunner -from pytouhou.game.game cimport Game - cdef class Effect(Element): def __init__(self, pos, index, anm): @@ -33,32 +31,3 @@ cdef class Effect(Element): if self.sprite.removed: self.sprite = None self.removed = True - - - -cdef class Particle(Effect): - def __init__(self, pos, index, anm, long amp, Game game, bint reverse=False, long duration=24): - Effect.__init__(self, pos, index, anm) - - self.frame = 0 - self.duration = duration - - random_pos = (self.x + amp * game.prng.rand_double() - amp / 2, - self.y + amp * game.prng.rand_double() - amp / 2) - - if not reverse: - self.pos_interpolator = Interpolator((self.x, self.y), 0, - random_pos, duration, formula=(lambda x: 2. * x - x ** 2)) - else: - self.pos_interpolator = Interpolator(random_pos, 0, - (self.x, self.y), duration, formula=(lambda x: 2. * x - x ** 2)) - self.x, self.y = random_pos - - - cpdef update(self): - Effect.update(self) - - self.pos_interpolator.update(self.frame) - self.x, self.y = self.pos_interpolator.values - - self.frame += 1 diff --git a/pytouhou/game/game.pyx b/pytouhou/game/game.pyx --- a/pytouhou/game/game.pyx +++ b/pytouhou/game/game.pyx @@ -18,7 +18,7 @@ from pytouhou.game.element cimport Eleme from pytouhou.game.bullet cimport Bullet, LAUNCHED, CANCELLED from pytouhou.game.enemy cimport Enemy from pytouhou.game.item cimport Item -from pytouhou.game.effect cimport Particle +from pytouhou.game.particle cimport Particle from pytouhou.game.laser cimport Laser, PlayerLaser from pytouhou.game.face import Face diff --git a/pytouhou/game/particle.pxd b/pytouhou/game/particle.pxd new file mode 100644 --- /dev/null +++ b/pytouhou/game/particle.pxd @@ -0,0 +1,8 @@ +from pytouhou.game.effect cimport Effect +from pytouhou.utils.interpolator cimport Interpolator + +cdef class Particle(Effect): + cdef long frame, duration + cdef Interpolator pos_interpolator + + cpdef update(self) diff --git a/pytouhou/game/particle.pyx b/pytouhou/game/particle.pyx new file mode 100644 --- /dev/null +++ b/pytouhou/game/particle.pyx @@ -0,0 +1,43 @@ +# -*- encoding: utf-8 -*- +## +## Copyright (C) 2015 Emmanuel Gil Peyrot +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published +## by the Free Software Foundation; version 3 only. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## + +from pytouhou.game.game cimport Game + + +cdef class Particle(Effect): + def __init__(self, pos, index, anm, long amp, Game game, bint reverse=False, long duration=24): + Effect.__init__(self, pos, index, anm) + + self.frame = 0 + self.duration = duration + + random_pos = (self.x + amp * game.prng.rand_double() - amp / 2, + self.y + amp * game.prng.rand_double() - amp / 2) + + if not reverse: + self.pos_interpolator = Interpolator((self.x, self.y), 0, + random_pos, duration, formula=(lambda x: 2. * x - x ** 2)) + else: + self.pos_interpolator = Interpolator(random_pos, 0, + (self.x, self.y), duration, formula=(lambda x: 2. * x - x ** 2)) + self.x, self.y = random_pos + + + cpdef update(self): + Effect.update(self) + + self.pos_interpolator.update(self.frame) + self.x, self.y = self.pos_interpolator.values + + self.frame += 1