Mercurial > touhou
annotate pytouhou/game/enemymanager.py @ 57:694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Tue, 23 Aug 2011 19:27:24 +0200 |
parents | 299de3a9b69f |
children | 1f591adcea04 |
rev | line source |
---|---|
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
2 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
4 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
8 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
12 ## GNU General Public License for more details. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
13 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
14 |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
15 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
16 from itertools import chain |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
17 from io import BytesIO |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
18 import os |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
19 from struct import unpack, pack |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
20 from pytouhou.utils.interpolator import Interpolator |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
21 from pytouhou.game.eclrunner import ECLRunner |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
22 from pytouhou.game.sprite import Sprite |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
23 from math import cos, sin, atan2 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
24 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
25 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
26 class Enemy(object): |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
27 def __init__(self, pos, life, _type, anm_wrapper): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
28 self._anm_wrapper = anm_wrapper |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
29 self._anm = None |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
30 self._sprite = None |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
31 self._removed = False |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
32 self._type = _type |
56
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
33 self._was_visible = False |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
34 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
35 self.frame = 0 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
36 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
37 self.x, self.y = pos |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
38 self.life = life |
36 | 39 self.max_life = life |
40 self.pending_bullets = [] | |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
41 self.bullet_attributes = None |
36 | 42 self.bullet_launch_offset = (0, 0) |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
43 self.vulnerable = True |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
44 self.death_callback = None |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
45 self.low_life_callback = None |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
46 self.low_life_trigger = None |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
47 self.timeout = None |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
48 self.remaining_lives = -1 |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
49 |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
50 self.bullet_launch_interval = 0 |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
51 self.delay_attack = False |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
52 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
53 self.death_anim = None |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
54 self.movement_dependant_sprites = None |
22 | 55 self.direction = None |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
56 self.interpolator = None #TODO |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
57 self.speed_interpolator = None |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
58 self.angle = 0. |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
59 self.speed = 0. |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
60 self.rotation_speed = 0. |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
61 self.acceleration = 0. |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
62 |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
63 self.hitbox = (0, 0) |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
64 self.screen_box = None |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
65 |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
66 |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
67 def set_bullet_attributes(self, type_, bullet_anim, launch_anim, |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
68 bullets_per_shot, number_of_shots, speed, unknown, |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
69 launch_angle, angle, flags): |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
70 self.bullet_attributes = (type_, bullet_anim, launch_anim, bullets_per_shot, |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
71 number_of_shots, speed, unknown, launch_angle, |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
72 angle, flags) |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
73 if not self.delay_attack: |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
74 self.fire() |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
75 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
76 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
77 def fire(self): |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
78 #TODO |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
79 pass |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
80 |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
81 |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
82 def select_player(self, players): |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
83 return players[0] #TODO |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
84 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
85 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
86 def get_player_angle(self, player): |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
87 return atan2(player.y - self.y, player.x - self.x) |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
88 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
89 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
90 def set_anim(self, index): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
91 self._anm, self._sprite = self._anm_wrapper.get_sprite(index) |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
92 |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
93 |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
94 def set_pos(self, x, y, z): |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
95 self.x, self.y = x, y |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
96 self.interpolator = Interpolator((x, y)) |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
97 self.interpolator.set_interpolation_start(self.frame, (x, y)) |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
98 |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
99 |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
100 def move_to(self, duration, x, y, z): |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
101 if not self.interpolator: |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
102 self.interpolator = Interpolator((self.x, self.y)) |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
103 self.interpolator.set_interpolation_start(self.frame, (self.x, self.y)) |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
104 self.interpolator.set_interpolation_end(self.frame + duration, (x, y)) |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
105 |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
106 |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
107 def stop_in(self, duration): |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
108 if not self.speed_interpolator: |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
109 self.speed_interpolator = Interpolator((self.speed,)) |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
110 self.speed_interpolator.set_interpolation_start(self.frame, (self.speed,)) |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
111 self.speed_interpolator.set_interpolation_end(self.frame + duration, (0.,)) |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
112 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
113 |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
114 def is_visible(self, screen_width, screen_height): |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
115 if not self._sprite: |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
116 return False |
29
afa91be769ae
Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents:
23
diff
changeset
|
117 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
118 tx, ty, tw, th = self._sprite.texcoords |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
119 if self._sprite.corner_relative_placement: |
29
afa91be769ae
Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents:
23
diff
changeset
|
120 raise Exception #TODO |
afa91be769ae
Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents:
23
diff
changeset
|
121 else: |
afa91be769ae
Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents:
23
diff
changeset
|
122 max_x = tw / 2. |
afa91be769ae
Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents:
23
diff
changeset
|
123 max_y = th / 2. |
afa91be769ae
Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents:
23
diff
changeset
|
124 min_x = -max_x |
afa91be769ae
Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents:
23
diff
changeset
|
125 min_y = -max_y |
afa91be769ae
Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents:
23
diff
changeset
|
126 |
56
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
127 if any((min_x > screen_width - self.x, |
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
128 max_x < -self.x, |
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
129 min_y > screen_height - self.y, |
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
130 max_y < -self.y)): |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
131 return False |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
132 return True |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
133 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
134 |
36 | 135 def get_objects_by_texture(self): |
136 objects_by_texture = {} | |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
137 key = self._anm.first_name, self._anm.secondary_name |
36 | 138 if not key in objects_by_texture: |
37
a10e3f44a883
Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents:
36
diff
changeset
|
139 objects_by_texture[key] = (0, [], [], []) |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
140 vertices = tuple((x + self.x, y + self.y, z) for x, y, z in self._sprite._vertices) |
36 | 141 objects_by_texture[key][1].extend(vertices) |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
142 objects_by_texture[key][2].extend(self._sprite._uvs) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
143 objects_by_texture[key][3].extend(self._sprite._colors) |
36 | 144 #TODO: effects/bullet launch |
145 return objects_by_texture | |
146 | |
147 | |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
148 def update(self, frame): |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
149 x, y = self.x, self.y |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
150 if self.interpolator: |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
151 self.interpolator.update(self.frame) |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
152 x, y = self.interpolator.values |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
153 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
154 self.speed += self.acceleration #TODO: units? Execution order? |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
155 self.angle += self.rotation_speed #TODO: units? Execution order? |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
156 |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
157 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
158 if self.speed_interpolator: |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
159 self.speed_interpolator.update(self.frame) |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
160 self.speed, = self.speed_interpolator.values |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
161 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
162 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
163 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
164 if self._type & 2: |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
165 x -= dx |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
166 else: |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
167 x += dx |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
168 y += dy |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
169 |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
170 if self.movement_dependant_sprites: |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
171 #TODO: is that really how it works? Almost. |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
172 # Sprite determination is done only once per changement, and is |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
173 # superseeded by ins_97. |
22 | 174 if x < self.x: |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
175 self.set_anim(self.movement_dependant_sprites[2]) |
22 | 176 self.direction = -1 |
177 elif x > self.x: | |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
178 self.set_anim(self.movement_dependant_sprites[3]) |
22 | 179 self.direction = +1 |
180 elif self.direction is not None: | |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
181 self.set_anim(self.movement_dependant_sprites[{-1: 0, +1:1}[self.direction]]) |
22 | 182 self.direction = None |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
183 |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
184 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
185 if self.screen_box: |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
186 xmin, ymin, xmax, ymax = self.screen_box |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
187 x = max(xmin, min(x, xmax)) |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
188 y = max(ymin, min(y, ymax)) |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
189 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
190 |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
191 self.x, self.y = x, y |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
192 if self._sprite: |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
193 changed = self._sprite.update() |
32 | 194 visible = self.is_visible(384, 448) |
195 if changed and visible: | |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
196 self._sprite.update_vertices_uvs_colors() |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
197 elif not self._sprite.playing: |
34
4d93d45ecb62
Fix animation script flow handling
Thibaut Girka <thib@sitedethib.com>
parents:
33
diff
changeset
|
198 visible = False |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
199 self._sprite = None |
32 | 200 else: |
201 visible = False | |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
202 |
36 | 203 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
204 self.frame += 1 |
32 | 205 return visible |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
206 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
207 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
208 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
209 class EnemyManager(object): |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
210 def __init__(self, stage, anm_wrapper, ecl, game_state): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
211 self._game_state = game_state |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
212 self.stage = stage |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
213 self.anm_wrapper = anm_wrapper |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
214 self.main = [] |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
215 self.ecl = ecl |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
216 self.objects_by_texture = {} |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
217 self.enemies = [] |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
218 self.processes = [] |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
219 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
220 # Populate main |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
221 for frame, sub, instr_type, args in ecl.main: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
222 if not self.main or self.main[-1][0] < frame: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
223 self.main.append((frame, [(sub, instr_type, args)])) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
224 elif self.main[-1][0] == frame: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
225 self.main[-1][1].append((sub, instr_type, args)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
226 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
227 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
228 def update(self, frame): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
229 if self.main and self.main[0][0] == frame: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
230 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
|
231 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
|
232 x, y, z, life, unknown1, unknown2, unknown3 = args |
40
ce662b372ee0
HANDLE RANDOM PLACEMENT (main flag 4) with results identical to 102h.exe \o/ \o/ \o/
Thibaut Girka <thib@sitedethib.com>
parents:
37
diff
changeset
|
233 if instr_type & 4: |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
234 if x < -990: #102h.exe@0x411820 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
235 x = self._game_state.prng.rand_double() * 368 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
236 if y < -990: #102h.exe@0x41184b |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
237 y = self._game_state.prng.rand_double() * 416 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
238 if z < -990: #102h.exe@0x411881 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
239 y = self._game_state.prng.rand_double() * 800 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
240 enemy = Enemy((x, y), life, instr_type, self.anm_wrapper) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
241 self.enemies.append(enemy) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
242 self.processes.append(ECLRunner(self.ecl, sub, enemy, self._game_state)) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
243 |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
244 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
245 # Run processes |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
246 self.processes[:] = (process for process in self.processes if process.run_iteration()) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
247 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
248 # Filter of destroyed enemies |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
249 self.enemies[:] = (enemy for enemy in self.enemies if not enemy._removed) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
250 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
251 # Update enemies |
32 | 252 visible_enemies = [enemy for enemy in self.enemies if enemy.update(frame)] |
56
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
253 for enemy in visible_enemies: |
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
254 enemy._was_visible = True |
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
255 |
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
256 # Filter out-of-screen enemies |
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
257 for enemy in tuple(self.enemies): |
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
258 if enemy._was_visible and not enemy in visible_enemies: |
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
259 enemy._removed = True |
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
260 self.enemies.remove(enemy) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
261 |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
262 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
263 #TODO: disable boss mode if it is dead/it has timeout |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
264 if self._game_state.boss and self._game_state.boss._removed: |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
265 self._game_state.boss = None |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
266 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
267 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
268 # Add enemies to vertices/uvs |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
269 self.objects_by_texture = {} |
32 | 270 for enemy in visible_enemies: |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
271 if enemy.is_visible(384, 448): #TODO |
37
a10e3f44a883
Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents:
36
diff
changeset
|
272 for key, (count, vertices, uvs, colors) in enemy.get_objects_by_texture().items(): |
36 | 273 if not key in self.objects_by_texture: |
37
a10e3f44a883
Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents:
36
diff
changeset
|
274 self.objects_by_texture[key] = (0, [], [], []) |
36 | 275 self.objects_by_texture[key][1].extend(vertices) |
276 self.objects_by_texture[key][2].extend(uvs) | |
37
a10e3f44a883
Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents:
36
diff
changeset
|
277 self.objects_by_texture[key][3].extend(colors) |
a10e3f44a883
Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents:
36
diff
changeset
|
278 for key, (nb_vertices, vertices, uvs, colors) in self.objects_by_texture.items(): |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
279 nb_vertices = len(vertices) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
280 vertices = pack('f' * (3 * nb_vertices), *chain(*vertices)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
281 uvs = pack('f' * (2 * nb_vertices), *chain(*uvs)) |
37
a10e3f44a883
Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents:
36
diff
changeset
|
282 colors = pack('B' * (4 * nb_vertices), *chain(*colors)) |
a10e3f44a883
Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents:
36
diff
changeset
|
283 self.objects_by_texture[key] = (nb_vertices, vertices, uvs, colors) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
284 |