Mercurial > touhou
annotate pytouhou/game/enemymanager.py @ 21:bf225780973f
Small refactoring, and Rumia \o/
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Thu, 11 Aug 2011 12:39:12 +0200 |
parents | 6ebf9539c077 |
children | fa87db09fc3a |
rev | line source |
---|---|
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
1 from itertools import chain |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
2 from io import BytesIO |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
3 import os |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
4 from struct import unpack, pack |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
5 from pytouhou.utils.interpolator import Interpolator |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
6 from pytouhou.game.sprite import Sprite |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
7 from math import cos, sin, atan2 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
8 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
9 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
10 class Enemy(object): |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
11 def __init__(self, pos, life, _type, script, anm_wrapper): |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
12 self.anm_wrapper = anm_wrapper |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
13 self.anm = None |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
14 self.script = list(script) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
15 self.x, self.y = pos |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
16 self.life = life |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
17 self.type = _type |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
18 self.frame = 0 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
19 self.sprite = None |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
20 |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
21 self.movement_dependant_sprites = None |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
22 self.interpolator = None #TODO |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
23 self.angle = 0. |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
24 self.speed = 0. |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
25 self.rotation_speed = 0. |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
26 self.acceleration = 0. |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
27 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
28 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
29 def update(self, frame): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
30 if not self.script: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
31 return True |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
32 if self.script[0][0] == self.frame: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
33 for instr_type, rank_mask, param_mask, args in self.script.pop(0)[1]: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
34 if instr_type == 1: # delete |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
35 return False |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
36 elif instr_type == 97: # set_enemy_sprite |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
37 script_index, = unpack('<I', args) |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
38 self.anm, self.sprite = self.anm_wrapper.get_sprite(script_index) |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
39 elif instr_type == 98: #TODO |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
40 self.movement_dependant_sprites = unpack('<HHHHI', args) |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
41 elif instr_type == 43: # set_pos |
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
42 self.x, self.y, z = unpack('<fff', args) |
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
43 self.interpolator = Interpolator((self.x, self.y)) #TODO: better interpolation |
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
44 self.interpolator.set_interpolation_start(self.frame, (self.x, self.y)) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
45 elif instr_type == 45: # set_angle_speed |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
46 self.angle, self.speed = unpack('<ff', args) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
47 elif instr_type == 46: # set_angle |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
48 self.rotation_speed, = unpack('<f', args) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
49 elif instr_type == 47: # set_speed |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
50 self.speed, = unpack('<f', args) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
51 elif instr_type == 48: # set_acceleration |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
52 self.acceleration, = unpack('<f', args) |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
53 elif instr_type == 51: # move_towards_player #TODO: main |
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
54 unknown, self.speed = unpack('<If', args) #TODO: unknown |
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
55 player_x, player_y = 192., 400.#TODO |
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
56 self.angle = atan2(player_y - self.y, player_x - self.x) |
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
57 elif instr_type == 57: |
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
58 duration, x, y, z = unpack('<Ifff', args) |
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
59 self.interpolator.set_interpolation_end(self.frame + duration, (x, y)) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
60 |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
61 x, y = self.x, self.y |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
62 if self.interpolator: |
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
63 self.interpolator.update(self.frame) |
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
64 x, y = self.interpolator.values |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
65 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
66 self.speed += self.acceleration #TODO: units? Execution order? |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
67 self.angle += self.rotation_speed #TODO: units? Execution order? |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
68 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
69 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
70 if self.type & 2: |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
71 x -= dx |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
72 else: |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
73 x += dx |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
74 y += dy |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
75 |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
76 if self.movement_dependant_sprites: |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
77 #TODO: is that really how it works? |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
78 dx, dy = self.x - x, self.y - y |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
79 if (dx, dy) == (0, 0): |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
80 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[0]) |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
81 elif abs(dx) > abs(dy): |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
82 if dx < 0: |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
83 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[2]) |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
84 else: |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
85 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[3]) |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
86 else: |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
87 if dy < 0: |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
88 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[1]) |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
89 else: |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
90 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[2]) |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
91 |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
92 self.x, self.y = x, y |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
93 if self.sprite: |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
94 self.sprite.update() |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
95 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
96 self.frame += 1 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
97 return True |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
98 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
99 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
100 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
101 class EnemyManager(object): |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
102 def __init__(self, stage, anm_wrapper, ecl): |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
103 self.stage = stage |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
104 self.anm_wrapper = anm_wrapper |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
105 self.main = [] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
106 self.subs = {} |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
107 self.objects_by_texture = {} |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
108 self.enemies = [] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
109 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
110 # Populate main |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
111 for frame, sub, instr_type, args in ecl.main: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
112 if not self.main or self.main[-1][0] < frame: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
113 self.main.append((frame, [(sub, instr_type, args)])) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
114 elif self.main[-1][0] == frame: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
115 self.main[-1][1].append((sub, instr_type, args)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
116 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
117 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
118 # Populate subs |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
119 for i, sub in enumerate(ecl.subs): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
120 for frame, instr_type, rank_mask, param_mask, args in sub: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
121 if i not in self.subs: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
122 self.subs[i] = [] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
123 if not self.subs[i] or self.subs[i][-1][0] < frame: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
124 self.subs[i].append((frame, [(instr_type, rank_mask, param_mask, args)])) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
125 elif self.subs[i][-1][0] == frame: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
126 self.subs[i][-1][1].append((instr_type, rank_mask, param_mask, args)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
127 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
128 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
129 def update(self, frame): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
130 if self.main and self.main[0][0] == frame: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
131 for sub, instr_type, args in self.main.pop(0)[1]: |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
132 if instr_type in (0, 2, 4, 6): # Normal/mirrored enemy |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
133 x, y, z, life, unknown1, unknown2, unknown3 = args |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
134 self.enemies.append(Enemy((x, y), life, instr_type, self.subs[sub], self.anm_wrapper)) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
135 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
136 # Update enemies |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
137 for enemy in tuple(self.enemies): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
138 if not enemy.update(frame): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
139 self.enemies.remove(enemy) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
140 continue |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
141 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
142 # Add enemies to vertices/uvs |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
143 self.objects_by_texture = {} |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
144 for enemy in self.enemies: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
145 ox, oy = enemy.x, enemy.y |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
146 if enemy.sprite: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
147 key = enemy.anm.first_name, enemy.anm.secondary_name |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
148 if not key in self.objects_by_texture: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
149 self.objects_by_texture[key] = (0, [], []) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
150 vertices = tuple((x + ox, y + oy, z) for x, y, z in enemy.sprite._vertices) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
151 self.objects_by_texture[key][2].extend(enemy.sprite._uvs) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
152 self.objects_by_texture[key][1].extend(vertices) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
153 for key, (nb_vertices, vertices, uvs) in self.objects_by_texture.items(): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
154 nb_vertices = len(vertices) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
155 vertices = pack('f' * (3 * nb_vertices), *chain(*vertices)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
156 uvs = pack('f' * (2 * nb_vertices), *chain(*uvs)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
157 self.objects_by_texture[key] = (nb_vertices, vertices, uvs) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
158 |