comparison pytouhou/game/game.py @ 181:184196480f59

Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 23 Oct 2011 14:50:44 -0700
parents 5a1533677a9a
children 54eb6b254b7b
comparison
equal deleted inserted replaced
180:5a1533677a9a 181:184196480f59
19 19
20 from pytouhou.game.player import Player 20 from pytouhou.game.player import Player
21 from pytouhou.game.enemy import Enemy 21 from pytouhou.game.enemy import Enemy
22 from pytouhou.game.item import Item 22 from pytouhou.game.item import Item
23 from pytouhou.game.effect import Effect 23 from pytouhou.game.effect import Effect
24 from pytouhou.game.effect import Particle
24 25
25 26
26 27
27 class Game(object): 28 class Game(object):
28 def __init__(self, resource_loader, player_states, stage, rank, difficulty, 29 def __init__(self, resource_loader, player_states, stage, rank, difficulty,
50 self.prng = Random() 51 self.prng = Random()
51 self.frame = 0 52 self.frame = 0
52 53
53 self.enm_anm_wrapper = resource_loader.get_anm_wrapper2(('stg%denm.anm' % stage, 54 self.enm_anm_wrapper = resource_loader.get_anm_wrapper2(('stg%denm.anm' % stage,
54 'stg%denm2.anm' % stage)) 55 'stg%denm2.anm' % stage))
55 self.eff00 = resource_loader.get_anm_wrapper(('eff00.anm',)) 56 self.etama4 = resource_loader.get_anm_wrapper(('etama4.anm',))
56 ecl = resource_loader.get_ecl('ecldata%d.ecl' % stage) 57 ecl = resource_loader.get_ecl('ecldata%d.ecl' % stage)
57 self.ecl_runner = ECLMainRunner(ecl, self) 58 self.ecl_runner = ECLMainRunner(ecl, self)
58 59
59 60
60 def drop_bonus(self, x, y, _type, end_pos=None): 61 def drop_bonus(self, x, y, _type, end_pos=None):
71 item_type = self.item_types[6] 72 item_type = self.item_types[6]
72 self.items.extend(Item((bullet.x, bullet.y), item_type, self, player=player) for bullet in self.bullets) 73 self.items.extend(Item((bullet.x, bullet.y), item_type, self, player=player) for bullet in self.bullets)
73 self.bullets = [] 74 self.bullets = []
74 75
75 76
76 def new_effect(self, pos, anim): 77 def new_death(self, pos, index):
77 self.effects.append(Effect(pos, anim, self.eff00)) 78 anim = {0: 3, 1: 4, 2: 5}[index % 256] # The TB is wanted, if index isn’t in these values the original game crashs.
79 self.effects.append(Effect(pos, anim, self.etama4))
80
81
82 def new_particle(self, pos, color, size, amp):
83 self.effects.append(Particle(pos, 7 + 4 * color + self.prng.rand_uint16() % 4, self.etama4, size,
84 (pos[0] + amp * self.prng.rand_double() - amp/2,
85 pos[1] + amp * self.prng.rand_double() - amp/2)))
78 86
79 87
80 def new_enemy(self, pos, life, instr_type, bonus_dropped, die_score): 88 def new_enemy(self, pos, life, instr_type, bonus_dropped, die_score):
81 enemy = Enemy(pos, life, instr_type, bonus_dropped, die_score, self.enm_anm_wrapper, self) 89 enemy = Enemy(pos, life, instr_type, bonus_dropped, die_score, self.enm_anm_wrapper, self)
82 self.enemies.append(enemy) 90 self.enemies.append(enemy)
150 or by2 < py1 or by1 > py2): 158 or by2 < py1 or by1 > py2):
151 bullet.collide() 159 bullet.collide()
152 if player.state.invulnerable_time == 0: 160 if player.state.invulnerable_time == 0:
153 player.collide() 161 player.collide()
154 162
155 elif not (bx2 < gx1 or bx1 > gx2 163 elif not bullet.grazed and not (bx2 < gx1 or bx1 > gx2
156 or by2 < gy1 or by1 > gy2): 164 or by2 < gy1 or by1 > gy2):
157 pass#TODO: graze 165 bullet.grazed = True
166 player.state.score += 500 # found experimentally
167 self.new_particle((px, py), 0, .8, 192)
168 #TODO: display a static particle during one frame at
169 # 12 pixels of the player, in the axis of the “collision”.
158 170
159 for enemy in self.enemies: 171 for enemy in self.enemies:
160 half_size_x, half_size_y = enemy.hitbox_half_size 172 half_size_x, half_size_y = enemy.hitbox_half_size
161 bx, by = enemy.x, enemy.y 173 bx, by = enemy.x, enemy.y
162 bx1, bx2 = bx - half_size_x, bx + half_size_x 174 bx1, bx2 = bx - half_size_x, bx + half_size_x