comparison pytouhou/game/enemymanager.py @ 22:fa87db09fc3a

Fix Rumia's animations
author Thibaut Girka <thib@sitedethib.com>
date Thu, 11 Aug 2011 21:21:38 +0200
parents bf225780973f
children 444ac7bca7bc
comparison
equal deleted inserted replaced
21:bf225780973f 22:fa87db09fc3a
17 self.type = _type 17 self.type = _type
18 self.frame = 0 18 self.frame = 0
19 self.sprite = None 19 self.sprite = None
20 20
21 self.movement_dependant_sprites = None 21 self.movement_dependant_sprites = None
22 self.direction = None
22 self.interpolator = None #TODO 23 self.interpolator = None #TODO
23 self.angle = 0. 24 self.angle = 0.
24 self.speed = 0. 25 self.speed = 0.
25 self.rotation_speed = 0. 26 self.rotation_speed = 0.
26 self.acceleration = 0. 27 self.acceleration = 0.
35 return False 36 return False
36 elif instr_type == 97: # set_enemy_sprite 37 elif instr_type == 97: # set_enemy_sprite
37 script_index, = unpack('<I', args) 38 script_index, = unpack('<I', args)
38 self.anm, self.sprite = self.anm_wrapper.get_sprite(script_index) 39 self.anm, self.sprite = self.anm_wrapper.get_sprite(script_index)
39 elif instr_type == 98: #TODO 40 elif instr_type == 98: #TODO
40 self.movement_dependant_sprites = unpack('<HHHHI', args) 41 default, end_left, end_right, left, right, unknown = unpack('<HHHHHH', args)
42 self.movement_dependant_sprites = end_left, end_right, left, right, unknown
43 self.anm, self.sprite = self.anm_wrapper.get_sprite(default)
41 elif instr_type == 43: # set_pos 44 elif instr_type == 43: # set_pos
42 self.x, self.y, z = unpack('<fff', args) 45 self.x, self.y, z = unpack('<fff', args)
43 self.interpolator = Interpolator((self.x, self.y)) #TODO: better interpolation 46 self.interpolator = Interpolator((self.x, self.y)) #TODO: better interpolation
44 self.interpolator.set_interpolation_start(self.frame, (self.x, self.y)) 47 self.interpolator.set_interpolation_start(self.frame, (self.x, self.y))
45 elif instr_type == 45: # set_angle_speed 48 elif instr_type == 45: # set_angle_speed
73 x += dx 76 x += dx
74 y += dy 77 y += dy
75 78
76 if self.movement_dependant_sprites: 79 if self.movement_dependant_sprites:
77 #TODO: is that really how it works? 80 #TODO: is that really how it works?
78 dx, dy = self.x - x, self.y - y 81 if x < self.x:
79 if (dx, dy) == (0, 0): 82 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[2])
80 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[0]) 83 self.direction = -1
81 elif abs(dx) > abs(dy): 84 elif x > self.x:
82 if dx < 0: 85 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[3])
83 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[2]) 86 self.direction = +1
84 else: 87 #TODO: end_animation
85 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[3]) 88 elif self.direction is not None:
86 else: 89 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[{-1: 0, +1:1}[self.direction]])
87 if dy < 0: 90 self.direction = None
88 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[1])
89 else:
90 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[2])
91 91
92 self.x, self.y = x, y 92 self.x, self.y = x, y
93 if self.sprite: 93 if self.sprite:
94 self.sprite.update() 94 self.sprite.update()
95 95