Mercurial > touhou
changeset 173:35d850502d1f
Move effects where they should be.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 21 Oct 2011 09:37:23 -0700 |
parents | ea2ad94c33a0 |
children | c0183515a0a3 |
files | pytouhou/game/effect.py pytouhou/game/enemy.py pytouhou/game/game.py pytouhou/game/player.py |
diffstat | 4 files changed, 44 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/pytouhou/game/effect.py @@ -0,0 +1,36 @@ +# -*- encoding: utf-8 -*- +## +## Copyright (C) 2011 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> +## +## 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.sprite import Sprite +from pytouhou.vm.anmrunner import ANMRunner + + + +class Effect(object): + def __init__(self, pos, index, anm_wrapper): + self._sprite = Sprite() + self._anmrunner = ANMRunner(anm_wrapper, index, self._sprite) + self._anmrunner.run_frame() + self._removed = False + + self.x, self.y = pos + + def update(self): + if self._anmrunner and not self._anmrunner.run_frame(): + self._anmrunner = None + + if self._sprite: + if self._sprite._removed: + self._sprite = None
--- a/pytouhou/game/enemy.py +++ b/pytouhou/game/enemy.py @@ -21,24 +21,6 @@ from pytouhou.game.item import Item from math import cos, sin, atan2, pi -class Effect(object): - def __init__(self, pos, index, anm_wrapper): - self._sprite = Sprite() - self._anmrunner = ANMRunner(anm_wrapper, index, self._sprite) - self._anmrunner.run_frame() - self._removed = False - - self.x, self.y = pos - - def update(self): - if self._anmrunner and not self._anmrunner.run_frame(): - self._anmrunner = None - - if self._sprite: - if self._sprite._removed: - self._sprite = None - - class Enemy(object): def __init__(self, pos, life, _type, bonus_dropped, die_score, anm_wrapper, game): self._game = game @@ -173,8 +155,7 @@ class Enemy(object): def die_anim(self): - eff00 = self._game.resource_loader.get_anm_wrapper(('eff00.anm',)) - self._game.effects.append(Effect((self.x, self.y), self.death_anim, eff00)) + self._game.new_effect((self.x, self.y), self.death_anim) def set_pos(self, x, y, z):
--- a/pytouhou/game/game.py +++ b/pytouhou/game/game.py @@ -20,6 +20,7 @@ from pytouhou.vm.eclrunner import ECLMai from pytouhou.game.player import Player from pytouhou.game.enemy import Enemy from pytouhou.game.item import Item +from pytouhou.game.effect import Effect @@ -50,6 +51,7 @@ class Game(object): self.enm_anm_wrapper = resource_loader.get_anm_wrapper2(('stg%denm.anm' % stage, 'stg%denm2.anm' % stage)) + self.eff00 = resource_loader.get_anm_wrapper(('eff00.anm',)) ecl = resource_loader.get_ecl('ecldata%d.ecl' % stage) self.ecl_runner = ECLMainRunner(ecl, self) @@ -70,6 +72,10 @@ class Game(object): self.bullets = [] + def new_effect(self, pos, anim): + self.effects.append(Effect(pos, anim, self.eff00)) + + def new_enemy(self, pos, life, instr_type, bonus_dropped, die_score): enemy = Enemy(pos, life, instr_type, bonus_dropped, die_score, self.enm_anm_wrapper, self) self.enemies.append(enemy)
--- a/pytouhou/game/player.py +++ b/pytouhou/game/player.py @@ -14,7 +14,6 @@ from pytouhou.game.sprite import Sprite -from pytouhou.game.enemy import Effect from pytouhou.vm.anmrunner import ANMRunner @@ -77,8 +76,7 @@ class Player(object): def collide(self): if not self.state.invulnerable_time and not self.death_time and self.state.touchable: # Border Between Life and Death self.death_time = self._game.frame - eff00 = self._game.resource_loader.get_anm_wrapper(('eff00.anm',)) - self._game.effects.append(Effect((self.state.x, self.state.y), 2, eff00)) + self._game.new_effect((self.state.x, self.state.y), 2) def collect(self, item):