# HG changeset patch # User Thibaut Girka # Date 1315255246 -7200 # Node ID c7847bfed427f3aec1d04fb9b15a66993c269f98 # Parent 572740acdb258dc194f2600cc445936c5a6749e0 Minor refactoring diff --git a/eclviewer.py b/eclviewer.py --- a/eclviewer.py +++ b/eclviewer.py @@ -146,7 +146,20 @@ def main(path, stage_num): glDisable(GL_FOG) objects_by_texture = {} - game.get_objects_by_texture(objects_by_texture) + for enemy in game.enemies: + enemy.get_objects_by_texture(objects_by_texture) + for (texture_key, blendfunc), (vertices, uvs, colors) in objects_by_texture.items(): + nb_vertices = len(vertices) + glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) + glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key]) + glVertexPointer(3, GL_FLOAT, 0, struct.pack(str(3 * nb_vertices) + 'f', *chain(*vertices))) + glTexCoordPointer(2, GL_FLOAT, 0, struct.pack(str(2 * nb_vertices) + 'f', *chain(*uvs))) + glColorPointer(4, GL_UNSIGNED_BYTE, 0, struct.pack(str(4 * nb_vertices) + 'B', *chain(*colors))) + glDrawArrays(GL_QUADS, 0, nb_vertices) + + objects_by_texture = {} + for bullet in game.game_state.bullets: + bullet.get_objects_by_texture(objects_by_texture) for (texture_key, blendfunc), (vertices, uvs, colors) in objects_by_texture.items(): nb_vertices = len(vertices) glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) diff --git a/pytouhou/game/bullet.py b/pytouhou/game/bullet.py --- a/pytouhou/game/bullet.py +++ b/pytouhou/game/bullet.py @@ -45,10 +45,16 @@ class Bullet(object): #TODO #if flags & (2|4|8): - # index = {2: 11, 4: 12, 8: 13}[flags & (2|4|8)] + # if flags & 2: #TODO: Huh?! + # index = 14 + # elif flags & 4: + # index = 15 + # else: + # index = 19 # self._sprite = Sprite() - # self._anmrunner = ANMRunner(self._game_state.resources.etama_anm_wrappers[0], - # index, self._sprite, sprite_idx_offset) + # self._anmrunner = ANMRunner(self._game_state.resource_loader.get_anm_wrapper(('etama3.anm',)), #TODO + # index, self._sprite, 0) #TODO: offset + # self._anmrunner.run_frame() self.flags = flags self.attributes = list(attributes) diff --git a/pytouhou/game/enemy.py b/pytouhou/game/enemy.py --- a/pytouhou/game/enemy.py +++ b/pytouhou/game/enemy.py @@ -43,7 +43,6 @@ class Enemy(object): self.touchable = True self.damageable = True self.death_flags = 0 - self.bullets = [] self.extended_bullet_attributes = (0, 0, 0, 0, 0., 0., 0., 0.) self.bullet_attributes = None self.bullet_launch_offset = (0, 0) @@ -105,6 +104,8 @@ class Enemy(object): if type_ != 75: launch_angle -= angle * (bullets_per_shot - 1) / 2. + bullets = self._game_state.bullets + for shot_nb in range(number_of_shots): shot_speed = speed if shot_nb == 0 else speed + (speed2 - speed) * float(shot_nb) / float(number_of_shots) bullet_angle = launch_angle @@ -112,11 +113,11 @@ class Enemy(object): if type_ == 75: # 102.h@0x4138cf bullet_angle = self._game_state.prng.rand_double() * (launch_angle - angle) + angle shot_speed = self._game_state.prng.rand_double() * (speed - speed2) + speed2 - self.bullets.append(Bullet((self.x, self.y), - anim, sprite_idx_offset, - bullet_angle, shot_speed, - self.extended_bullet_attributes, - flags, player, self._game_state)) + bullets.append(Bullet((self.x, self.y), + anim, sprite_idx_offset, + bullet_angle, shot_speed, + self.extended_bullet_attributes, + flags, player, self._game_state)) bullet_angle += angle @@ -184,9 +185,6 @@ class Enemy(object): def get_objects_by_texture(self, objects_by_texture): - for bullet in self.bullets: - bullet.get_objects_by_texture(objects_by_texture) - if not self._sprite: return @@ -265,10 +263,5 @@ class Enemy(object): if self.bullet_launch_timer == self.bullet_launch_interval: self.fire() - - for bullet in self.bullets: - bullet.update() - - self.frame += 1 diff --git a/pytouhou/game/game.py b/pytouhou/game/game.py --- a/pytouhou/game/game.py +++ b/pytouhou/game/game.py @@ -21,11 +21,13 @@ from pytouhou.game.enemy import Enemy class GameState(object): - __slots__ = ('resource_loader', 'players', 'rank', 'difficulty', 'frame', + __slots__ = ('resource_loader', 'bullets', 'players', 'rank', 'difficulty', 'frame', 'stage', 'boss', 'prng') def __init__(self, resource_loader, players, stage, rank, difficulty): self.resource_loader = resource_loader + self.bullets = [] + self.stage = stage self.players = players self.rank = rank @@ -42,7 +44,6 @@ class Game(object): self.enemies = [] - self.bullets = [] self.bonuses = [] self.enm_anm_wrapper = resource_loader.get_anm_wrapper2(('stg%denm.anm' % stage, @@ -51,15 +52,6 @@ class Game(object): self.ecl_runner = ECLMainRunner(ecl, self.new_enemy, self.game_state) - def get_objects_by_texture(self, objects_by_texture): - #TODO: move elsewhere - for enemy in self.enemies: - enemy.get_objects_by_texture(objects_by_texture) - - for bullet in self.bullets: - bullet.get_objects_by_texture(objects_by_texture) - - def new_enemy(self, pos, life, instr_type): enemy = Enemy(pos, life, instr_type, self.enm_anm_wrapper, self.game_state) self.enemies.append(enemy) @@ -76,14 +68,10 @@ class Game(object): # 3. Let's play! for enemy in self.enemies: enemy.update() - for bullet in tuple(enemy.bullets): - if bullet._launched: - enemy.bullets.remove(bullet) - self.bullets.append(bullet) - for bullet in self.bullets: + + for bullet in self.game_state.bullets: bullet.update() - # 4. Cleaning self.cleanup() @@ -102,9 +90,10 @@ class Game(object): # Filter out-of-scren bullets # TODO: was_visible thing - for bullet in tuple(self.bullets): + bullets = self.game_state.bullets + for bullet in tuple(bullets): if not bullet.is_visible(384, 448): - self.bullets.remove(bullet) + bullets.remove(bullet) # Disable boss mode if it is dead/it has timeout if self.game_state.boss and self.game_state.boss._removed: diff --git a/pytouhou/vm/eclrunner.py b/pytouhou/vm/eclrunner.py --- a/pytouhou/vm/eclrunner.py +++ b/pytouhou/vm/eclrunner.py @@ -602,7 +602,7 @@ class ECLRunner(object): @instruction(75) - def set_bullet_attributes6(self, anim, sprite_idx_offset, bullets_per_shot, + def set_bullet_attributes7(self, anim, sprite_idx_offset, bullets_per_shot, number_of_shots, speed, speed2, launch_angle, angle, flags): #TODO