changeset 328:56523a16db1d

Fix some replay synchronization issues and update the TODO.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 21 Jun 2012 19:59:41 +0200
parents 13201d90bb22
children 1bb78c469f64
files TODO pytouhou/formats/t6rp.py pytouhou/game/bullet.pyx pytouhou/game/effect.py pytouhou/game/enemy.py pytouhou/game/game.py pytouhou/game/player.py
diffstat 7 files changed, 28 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/TODO
+++ b/TODO
@@ -2,7 +2,6 @@ Engine
 - homing bullets
 - MSG texts
 - boss OSD
-- music
 - bombs
 - vm END
 - score display
@@ -21,7 +20,9 @@ Engine
 - look at the the last spellcard of Remi
 - huge slowdowns with the spamming fairies of extra
 - Patchouli’s books are too agressive
+- Flandre’s And Then Will There Be None? is done two times
 - Flandre’s QED is impossible
+- Patchouli replaces Flandre in the last MSG
 
 ECL
 - fix 77 interval
@@ -50,3 +51,6 @@ MSG
 - 12
 - 14
 - fix the end
+
+Ideas
+- make a cache for the labels, to speed up the spellcard bonus
--- a/pytouhou/formats/t6rp.py
+++ b/pytouhou/formats/t6rp.py
@@ -32,11 +32,13 @@ class Level(object):
     def __init__(self):
         self.score = 0
         self.random_seed = 0
+        self.point_items = 0
 
         self.power = 0
         self.lives = 2
         self.bombs = 3
         self.difficulty = 16
+        self.unknown = 0
         self.keys = []
 
 
@@ -85,7 +87,7 @@ class T6RP(object):
             if checksum != (sum(ord(c) for c in data) + 0x3f000318 + replay.key) & 0xffffffff:
                 raise Exception #TODO
 
-        replay.unknown3 = unpack('<B', file.read(1))
+        replay.unknown3, = unpack('<B', file.read(1))
         replay.date = file.read(9) #read_string(file, 9, 'ascii')
         replay.name = file.read(9) #read_string(file, 9, 'ascii').rstrip()
         replay.unknown4, replay.score, replay.unknown5, replay.slowdown, replay.unknown6 = unpack('<HIIfI', file.read(18))
@@ -100,8 +102,8 @@ class T6RP(object):
             replay.levels[i] = level
 
             file.seek(offset)
-            (level.score, level.random_seed, level.unknown1, level.power,
-             level.lives, level.bombs, level.difficulty, level.unknown2) = unpack('<IHHBbbBI', file.read(16))
+            (level.score, level.random_seed, level.point_items, level.power,
+             level.lives, level.bombs, level.difficulty, level.unknown) = unpack('<IHHBbbBI', file.read(16))
 
             while True:
                 time, keys, unknown = unpack('<IHH', file.read(8))
--- a/pytouhou/game/bullet.pyx
+++ b/pytouhou/game/bullet.pyx
@@ -126,6 +126,7 @@ cdef class Bullet(object):
         self.frame = 0
         self.set_anim()
         self.dx, self.dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed
+
         if self.flags & 1:
             self.speed_interpolator = Interpolator((self.speed + 5.,), 0,
                                                    (self.speed,), 16)
@@ -133,6 +134,7 @@ cdef class Bullet(object):
 
     def collide(Bullet self):
         self.cancel()
+        self._game.new_particle((self.x, self.y), 1, 3., 256) #TODO: find the real size.
 
 
     def cancel(Bullet self):
--- a/pytouhou/game/effect.py
+++ b/pytouhou/game/effect.py
@@ -57,6 +57,7 @@ class Particle(object):
         self.pos_interpolator = None
         self.scale_interpolator = None
         self.rotations_interpolator = None
+        self.alpha_interpolator = None
 
         self.amp = amp
 
@@ -71,6 +72,8 @@ class Particle(object):
                                                (0., 0.), 24)
         self.rotations_interpolator = Interpolator(self.sprite.rotations_3d, 0,
                                                    (0., 0., 2*pi), 24)
+        self.alpha_interpolator = Interpolator((self.sprite.alpha,), 0,
+                                               (0.,), 24)
 
 
     def update(self):
@@ -87,6 +90,9 @@ class Particle(object):
             self.rotations_interpolator.update(self.frame)
             self.sprite.rotations_3d = self.rotations_interpolator.values
 
+            self.alpha_interpolator.update(self.frame)
+            self.sprite.alpha, = self.alpha_interpolator.values
+
             self.sprite.changed = True
 
         if self.frame == 24:
--- a/pytouhou/game/enemy.py
+++ b/pytouhou/game/enemy.py
@@ -210,13 +210,11 @@ class Enemy(object):
 
 
     def drop_particles(self, number, color):
-        #TODO: white particles are only used in stage 3 to 6,
-        # in other stages they are blue.
         if color == 0:
             if self._game.stage in [1, 2, 7]:
                 color = 3
         for i in range(number):
-            self._game.new_particle((self.x, self.y), color, 4., 256) #TODO: find the real size.
+            self._game.new_particle((self.x, self.y), color, 3., 256) #TODO: find the real size.
 
 
     def set_aux_anm(self, number, script):
@@ -291,7 +289,6 @@ class Enemy(object):
                 bullet.collide()
                 if self.damageable:
                     damages += bullet.damage
-                self.drop_particles(1, 1)
 
         # Check for enemy-laser collisions
         for laser in self._game.players_lasers:
@@ -306,7 +303,7 @@ class Enemy(object):
                     or ly < ey1):
                 if self.damageable:
                     damages += laser.damage
-                self.drop_particles(1, 1)
+                self.drop_particles(1, 1) #TODO: don’t call each frame.
 
         # Check for enemy-player collisions
         ex1, ex2 = ex - ehalf_size_x * 2. / 3., ex + ehalf_size_x * 2. / 3.
@@ -407,7 +404,6 @@ class Enemy(object):
     def update(self):
         if self.process:
             self.process.run_iteration()
-            self.handle_callbacks()
 
         x, y = self.x, self.y
 
@@ -481,5 +477,7 @@ class Enemy(object):
                 anm.x, anm.y = self.x, self.y
                 anm.update()
 
+        self.handle_callbacks()
+
         self.frame += 1
 
--- a/pytouhou/game/game.py
+++ b/pytouhou/game/game.py
@@ -259,6 +259,10 @@ class Game(object):
     def update_players(self, keystate):
         if self.time_stop:
             return None
+
+        for bullet in self.players_bullets:
+            bullet.update()
+
         for player in self.players:
             player.update(keystate) #TODO: differentiate keystates (multiplayer mode)
             if player.state.x < 8.:
@@ -270,9 +274,6 @@ class Game(object):
             if player.state.y > self.height - 16:
                 player.state.y = self.height -16
 
-        for bullet in self.players_bullets:
-            bullet.update()
-
         #XXX: Why 78910? Is it really the right value?
         player.state.effective_score = min(player.state.effective_score + 78910,
                                            player.state.score)
--- a/pytouhou/game/player.py
+++ b/pytouhou/game/player.py
@@ -192,10 +192,10 @@ class Player(object):
                 self.state.invulnerable_time -= 1
 
                 m = self.state.invulnerable_time % 8
-                if m == 0:
+                if m == 7 or self.state.invulnerable_time == 0:
                     self.sprite.color = (255, 255, 255)
                     self.sprite.changed = True
-                elif m == 2:
+                elif m == 1:
                     self.sprite.color = (64, 64, 64)
                     self.sprite.changed = True