Mercurial > touhou
annotate pytouhou/vm/eclrunner.py @ 165:c8c60291c56f
Implement item dropping by enemies.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 18 Oct 2011 07:35:02 -0700 |
parents | 606468ab4f7b |
children | dcf32488a2c9 |
rev | line source |
---|---|
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
2 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
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:
51
diff
changeset
|
4 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
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:
51
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:
51
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:
51
diff
changeset
|
8 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
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:
51
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:
51
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:
51
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:
51
diff
changeset
|
13 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
14 |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
15 |
107
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
16 from math import atan2, cos, sin, pi |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
17 |
58 | 18 from pytouhou.utils.helpers import get_logger |
19 | |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
67
diff
changeset
|
20 from pytouhou.vm.common import MetaRegistry, instruction |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
21 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
67
diff
changeset
|
22 logger = get_logger(__name__) |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
23 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
24 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
25 |
97 | 26 class ECLMainRunner(object): |
27 __metaclass__ = MetaRegistry | |
157
ca6f8b3f739d
Remove half of the new_enemy/pop_enemy mess.
Thibaut Girka <thib@sitedethib.com>
parents:
155
diff
changeset
|
28 __slots__ = ('_ecl', '_game', 'processes', |
97 | 29 'instruction_pointer') |
30 | |
157
ca6f8b3f739d
Remove half of the new_enemy/pop_enemy mess.
Thibaut Girka <thib@sitedethib.com>
parents:
155
diff
changeset
|
31 def __init__(self, ecl, game): |
97 | 32 self._ecl = ecl |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
33 self._game = game |
97 | 34 |
35 self.processes = [] | |
36 | |
37 self.instruction_pointer = 0 | |
38 | |
39 | |
40 def run_iter(self): | |
41 while True: | |
42 try: | |
43 frame, sub, instr_type, args = self._ecl.main[self.instruction_pointer] | |
44 except IndexError: | |
45 break | |
46 | |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
47 if frame > self._game.frame: |
97 | 48 break |
49 else: | |
50 self.instruction_pointer += 1 | |
51 | |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
52 if frame == self._game.frame: |
97 | 53 try: |
54 callback = self._handlers[instr_type] | |
55 except KeyError: | |
99
68aa8bf00c88
Change a debug string to avoid confusion
Thibaut Girka <thib@sitedethib.com>
parents:
97
diff
changeset
|
56 logger.warn('unhandled main opcode %d (args: %r)', instr_type, args) |
97 | 57 else: |
58 callback(self, sub, instr_type, *args) | |
59 | |
60 self.processes[:] = (process for process in self.processes | |
61 if process.run_iteration()) | |
62 | |
63 | |
140
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
64 def _pop_enemy(self, sub, instr_type, x, y, z, life, bonus_dropped, unknown2, unknown3): |
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
65 if instr_type & 4: |
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
66 if x < -990: #102h.exe@0x411820 |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
67 x = self._game.prng.rand_double() * 368 |
140
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
68 if y < -990: #102h.exe@0x41184b |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
69 y = self._game.prng.rand_double() * 416 |
140
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
70 if z < -990: #102h.exe@0x411881 |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
71 y = self._game.prng.rand_double() * 800 |
159
4684d311a32d
Remove remaining pop_enemy/new_enemy mess
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
72 enemy = self._game.new_enemy((x, y), life, instr_type, bonus_dropped) |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
73 process = ECLRunner(self._ecl, sub, enemy, self._game) |
140
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
74 self.processes.append(process) |
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
75 process.run_iteration() |
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
76 |
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
77 |
97 | 78 @instruction(0) |
79 @instruction(2) | |
80 @instruction(4) | |
81 @instruction(6) | |
134
e9ac3640280b
Add support for enemy spawnling enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
128
diff
changeset
|
82 def pop_enemy(self, sub, instr_type, x, y, z, life, bonus_dropped, unknown2, unknown3): |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
83 if self._game.boss: |
97 | 84 return |
140
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
85 self._pop_enemy(sub, instr_type, x, y, z, life, bonus_dropped, unknown2, unknown3) |
97 | 86 |
87 | |
88 | |
89 | |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
90 class ECLRunner(object): |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
91 __metaclass__ = MetaRegistry |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
92 __slots__ = ('_ecl', '_enemy', '_game', 'variables', 'sub', 'frame', |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
93 'instruction_pointer', 'comparison_reg', 'stack') |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
94 |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
95 def __init__(self, ecl, sub, enemy, game): |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
96 # Things not supposed to change |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
97 self._ecl = ecl |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
98 self._enemy = enemy |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
99 self._game = game |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
100 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
101 # Things supposed to change (and be put in the stack) |
47
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
102 self.variables = [0, 0, 0, 0, |
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
103 0., 0., 0., 0., |
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
104 0, 0, 0, 0] |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
105 self.comparison_reg = 0 |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
106 self.sub = sub |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
107 self.frame = 0 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
108 self.instruction_pointer = 0 |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
109 |
47
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
110 self.stack = [] |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
111 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
112 |
93
d167280a82fc
Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents:
91
diff
changeset
|
113 def handle_callbacks(self): |
103
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
114 #TODO: implement missing callbacks and clean up! |
93
d167280a82fc
Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents:
91
diff
changeset
|
115 enm = self._enemy |
103
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
116 if enm.boss_callback is not None: #XXX: MSG's job! |
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
117 self.frame = 0 |
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
118 self.sub = enm.boss_callback |
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
119 self.instruction_pointer = 0 |
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
120 enm.boss_callback = None |
165
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
121 if enm.life <= 0: |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
122 death_flags = enm.death_flags & 7 |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
123 |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
124 if death_flags < 4: |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
125 if enm._bonus_dropped >= 0: |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
126 self._game.drop_bonus(enm.x, enm.y, enm._bonus_dropped) |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
127 elif enm._bonus_dropped == -1: |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
128 self._game.drop_bonus(enm.x, enm.y, self._game.prng.rand_uint16() % 2) #TODO: find the formula in the binary. Can be big power sometimes. |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
129 |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
130 if enm.death_callback is not None: |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
131 self.frame = 0 |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
132 self.sub = enm.death_callback |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
133 self.instruction_pointer = 0 |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
134 enm.death_callback = None |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
135 elif enm.life <= enm.low_life_trigger and enm.low_life_callback is not None: |
103
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
136 self.frame = 0 |
165
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
137 self.sub = enm.low_life_callback |
103
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
138 self.instruction_pointer = 0 |
165
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
139 enm.low_life_callback = None |
103
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
140 elif enm.timeout and enm.frame == enm.timeout: |
93
d167280a82fc
Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents:
91
diff
changeset
|
141 enm.frame = 0 |
103
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
142 if enm.timeout_callback is not None: |
93
d167280a82fc
Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents:
91
diff
changeset
|
143 self.frame = 0 |
d167280a82fc
Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents:
91
diff
changeset
|
144 self.sub = enm.timeout_callback |
d167280a82fc
Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents:
91
diff
changeset
|
145 self.instruction_pointer = 0 |
103
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
146 enm.timeout_callback = None |
93
d167280a82fc
Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents:
91
diff
changeset
|
147 else: |
103
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
148 enm.life = 0 |
93
d167280a82fc
Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents:
91
diff
changeset
|
149 #TODO: other callbacks (low life, etc.) |
d167280a82fc
Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents:
91
diff
changeset
|
150 |
d167280a82fc
Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents:
91
diff
changeset
|
151 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
152 def run_iteration(self): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
153 # First, if enemy is dead, return |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
154 if self._enemy._removed: |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
155 return False |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
156 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
157 # Then, check for callbacks |
93
d167280a82fc
Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents:
91
diff
changeset
|
158 self.handle_callbacks() |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
159 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
160 # Now, process script |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
161 while True: |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
162 try: |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
163 frame, instr_type, rank_mask, param_mask, args = self._ecl.subs[self.sub][self.instruction_pointer] |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
164 except IndexError: |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
165 return False |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
166 |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
167 if frame > self.frame: |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
168 break |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
169 else: |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
170 self.instruction_pointer += 1 |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
171 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
172 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
173 #TODO: skip bad ranks |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
174 if not rank_mask & (0x100 << self._game.rank): |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
175 continue |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
176 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
177 |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
178 if frame == self.frame: |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
179 try: |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
180 callback = self._handlers[instr_type] |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
181 except KeyError: |
58 | 182 logger.warn('unhandled opcode %d (args: %r)', instr_type, args) |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
183 else: |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
184 callback(self, *args) |
100
5c40cc1b8019
Use game's frame for interpolation. No more time manipulation interfering with interpolators!
Thibaut Girka <thib@sitedethib.com>
parents:
99
diff
changeset
|
185 logger.debug('executed opcode %d (args: %r)', instr_type, args) |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
186 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
187 self.frame += 1 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
188 return True |
47
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
189 |
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
190 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
191 def _getval(self, value): |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
47
diff
changeset
|
192 if -10012 <= value <= -10001: |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
47
diff
changeset
|
193 return self.variables[int(-10001-value)] |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
194 elif -10025 <= value <= -10013: |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
195 if value == -10013: |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
196 return self._game.rank |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
197 elif value == -10014: |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
198 return self._game.difficulty |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
199 elif value == -10015: |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
200 return self._enemy.x |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
201 elif value == -10016: |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
202 return self._enemy.y |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
203 elif value == -10017: |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
204 return self._enemy.z |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
205 elif value == -10018: |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
206 player = self._enemy.select_player() |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
207 return player.x |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
208 elif value == -10019: |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
209 player = self._enemy.select_player() |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
210 return player.y |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
211 elif value == -10021: |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
212 return self._enemy.get_player_angle() |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
213 elif value == -10022: |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
214 return self._enemy.frame |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
215 elif value == -10024: |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
216 return self._enemy.life |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
217 elif value == -10025: |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
218 return self._enemy.select_player().state.character #TODO |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
219 raise NotImplementedError(value) #TODO |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
47
diff
changeset
|
220 else: |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
47
diff
changeset
|
221 return value |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
47
diff
changeset
|
222 |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
47
diff
changeset
|
223 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
224 def _setval(self, variable_id, value): |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
225 if -10012 <= variable_id <= -10001: |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
226 self.variables[int(-10001-variable_id)] = value |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
227 elif -10025 <= variable_id <= -10013: |
55 | 228 if variable_id == -10015: |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
229 self._enemy.x = value |
55 | 230 elif variable_id == -10016: |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
231 self._enemy.y = value |
55 | 232 elif variable_id == -10017: |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
233 self._enemy.z = value |
55 | 234 elif variable_id == -10022: |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
235 self._enemy.frame = value |
55 | 236 elif variable_id == -10024: |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
237 self._enemy.life = value |
55 | 238 else: |
239 raise IndexError #TODO: proper exception | |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
240 else: |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
241 raise IndexError #TODO: proper exception |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
242 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
243 |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
244 @instruction(0) |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
245 def noop(self): |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
246 pass #TODO: Really? |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
247 |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
248 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
249 @instruction(1) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
250 def destroy(self, arg): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
251 #TODO: arg? |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
252 self._enemy._removed = True |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
47
diff
changeset
|
253 |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
47
diff
changeset
|
254 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
255 @instruction(2) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
256 def relative_jump(self, frame, instruction_pointer): |
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
257 """Jumps to a relative offset in the same subroutine. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
258 |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
259 Warning: the relative offset has been translated to an instruction pointer |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
260 by the ECL parsing code (see pytouhou.formats.ecl). |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
261 """ |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
262 self.frame, self.instruction_pointer = frame, instruction_pointer |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
47
diff
changeset
|
263 |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
47
diff
changeset
|
264 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
265 @instruction(3) |
53 | 266 def relative_jump_ex(self, frame, instruction_pointer, variable_id): |
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
267 """If the given variable is non-zero, decrease it by 1 and jump to a |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
268 relative offset in the same subroutine. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
269 |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
270 Warning: the relative offset has been translated to an instruction pointer |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
271 by the ECL parsing code (see pytouhou.formats.ecl). |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
272 """ |
91 | 273 counter_value = self._getval(variable_id) - 1 |
274 if counter_value > 0: | |
275 self._setval(variable_id, counter_value) | |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
276 self.frame, self.instruction_pointer = frame, instruction_pointer |
47
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
277 |
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
278 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
279 @instruction(4) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
280 @instruction(5) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
281 def set_variable(self, variable_id, value): |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
282 self._setval(variable_id, self._getval(value)) |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
283 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
284 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
285 @instruction(6) |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
286 def set_random_int(self, variable_id, maxval): |
63
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
287 """Set the specified variable to a random int in the [0, maxval) range. |
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
288 """ |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
289 self._setval(variable_id, int(self._getval(maxval) * self._game.prng.rand_double())) |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
290 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
291 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
292 @instruction(8) |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
293 def set_random_float(self, variable_id, maxval): |
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
294 """Set the specified variable to a random float in [0, maxval) range. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
295 """ |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
296 self._setval(variable_id, self._getval(maxval) * self._game.prng.rand_double()) |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
297 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
298 |
59
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
299 @instruction(9) |
144
cadfc5e5ad7a
Fix a stupid inversion of properties.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
140
diff
changeset
|
300 def set_random_float2(self, variable_id, amp, minval): |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
301 self._setval(variable_id, self._getval(minval) + self._getval(amp) * self._game.prng.rand_double()) |
59
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
302 |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
303 |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
304 @instruction(10) |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
305 def store_x(self, variable_id): |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
306 self._setval(variable_id, self._enemy.x) |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
307 |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
308 |
63
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
309 @instruction(14) |
65
0efec109f798
Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
310 @instruction(21) |
0efec109f798
Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
311 def substract(self, variable_id, a, b): |
0efec109f798
Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
312 #TODO: 14 takes only ints and 21 only floats. |
0efec109f798
Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
313 # The original engine dereferences the variables in the type it waits for, so this isn't exactly the correct implementation, but the data don't contain such case. |
0efec109f798
Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
314 self._setval(variable_id, self._getval(a) - self._getval(b)) |
63
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
315 |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
316 |
87 | 317 @instruction(13) |
318 @instruction(20) | |
319 def add(self, variable_id, a, b): | |
320 #TODO: 13 takes only ints and 20 only floats. | |
321 # The original engine dereferences the variables in the type it waits for, so this isn't exactly the correct implementation, but the data don't contain such case. | |
322 self._setval(variable_id, self._getval(a) + self._getval(b)) | |
323 | |
324 | |
63
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
325 @instruction(15) |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
326 def multiply_int(self, variable_id, a, b): |
65
0efec109f798
Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
327 #TODO: takes only ints. |
0efec109f798
Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
328 self._setval(variable_id, self._getval(a) * self._getval(b)) |
63
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
329 |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
330 |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
331 @instruction(16) |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
332 def divide_int(self, variable_id, a, b): |
65
0efec109f798
Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
333 #TODO: takes only ints. |
0efec109f798
Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
334 self._setval(variable_id, self._getval(a) // self._getval(b)) |
63
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
335 |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
336 |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
337 @instruction(17) |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
338 def modulo(self, variable_id, a, b): |
65
0efec109f798
Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
339 self._setval(variable_id, self._getval(a) % self._getval(b)) |
63
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
340 |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
341 |
96
54929d495654
Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents:
95
diff
changeset
|
342 @instruction(18) |
54929d495654
Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents:
95
diff
changeset
|
343 def increment(self, variable_id): |
54929d495654
Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents:
95
diff
changeset
|
344 self._setval(variable_id, self._getval(variable_id) + 1) |
54929d495654
Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents:
95
diff
changeset
|
345 |
54929d495654
Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents:
95
diff
changeset
|
346 |
63
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
347 @instruction(23) |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
348 def divide_float(self, variable_id, a, b): |
65
0efec109f798
Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
349 #TODO: takes only floats. |
63
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
350 self._setval(variable_id, self._getval(a) / self._getval(b)) |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
351 |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
352 |
77
6fa6d74a049a
Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
76
diff
changeset
|
353 @instruction(25) |
6fa6d74a049a
Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
76
diff
changeset
|
354 def get_direction(self, variable_id, x1, y1, x2, y2): |
6fa6d74a049a
Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
76
diff
changeset
|
355 #TODO: takes only floats. |
147
a61c96265779
Fix a crash with ECL instruction 25
Thibaut Girka <thib@sitedethib.com>
parents:
144
diff
changeset
|
356 self._setval(variable_id, atan2(self._getval(y2) - self._getval(y1), self._getval(x2) - self._getval(x1))) |
77
6fa6d74a049a
Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
76
diff
changeset
|
357 |
6fa6d74a049a
Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
76
diff
changeset
|
358 |
155
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
359 @instruction(26) |
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
360 def float_to_unit_circle(self, variable_id): |
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
361 #TODO: takes only floats. |
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
362 self._setval(variable_id, (self._getval(variable_id) + pi) % (2*pi) - pi) |
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
363 |
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
364 |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
365 @instruction(27) |
63
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
62
diff
changeset
|
366 @instruction(28) |
65
0efec109f798
Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
367 def compare(self, a, b): |
0efec109f798
Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
368 #TODO: 27 takes only ints and 28 only floats. |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
369 a, b = self._getval(a), self._getval(b) |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
370 if a < b: |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
371 self.comparison_reg = -1 |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
372 elif a == b: |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
373 self.comparison_reg = 0 |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
374 else: |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
375 self.comparison_reg = 1 |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
376 |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
377 |
64
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
378 @instruction(29) |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
379 def relative_jump_if_lower_than(self, frame, instruction_pointer): |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
380 if self.comparison_reg == -1: |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
381 self.relative_jump(frame, instruction_pointer) |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
382 |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
383 |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
384 @instruction(30) |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
385 def relative_jump_if_lower_or_equal(self, frame, instruction_pointer): |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
386 if self.comparison_reg != 1: |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
387 self.relative_jump(frame, instruction_pointer) |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
388 |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
389 |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
390 @instruction(31) |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
391 def relative_jump_if_equal(self, frame, instruction_pointer): |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
392 if self.comparison_reg == 0: |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
393 self.relative_jump(frame, instruction_pointer) |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
394 |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
395 |
64
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
396 @instruction(32) |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
397 def relative_jump_if_greater_than(self, frame, instruction_pointer): |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
398 if self.comparison_reg == 1: |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
399 self.relative_jump(frame, instruction_pointer) |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
400 |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
401 |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
402 @instruction(33) |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
403 def relative_jump_if_greater_or_equal(self, frame, instruction_pointer): |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
404 if self.comparison_reg != -1: |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
405 self.relative_jump(frame, instruction_pointer) |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
406 |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
407 |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
408 @instruction(34) |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
409 def relative_jump_if_not_equal(self, frame, instruction_pointer): |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
410 if self.comparison_reg != 0: |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
411 self.relative_jump(frame, instruction_pointer) |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
412 |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
413 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
414 @instruction(35) |
47
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
415 def call(self, sub, param1, param2): |
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
416 self.stack.append((self.sub, self.frame, self.instruction_pointer, |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
417 self.variables, self.comparison_reg)) |
47
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
418 self.sub = sub |
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
419 self.frame = 0 |
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
420 self.instruction_pointer = 0 |
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
421 self.variables = [param1, 0, 0, 0, |
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
422 param2, 0., 0., 0., |
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
423 0, 0, 0, 0] |
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
424 |
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
425 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
426 @instruction(36) |
47
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
427 def ret(self): |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
428 self.sub, self.frame, self.instruction_pointer, self.variables, self.comparison_reg = self.stack.pop() |
47
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
429 |
1f1793e7ec8e
Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents:
43
diff
changeset
|
430 |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
431 @instruction(39) |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
432 def call_if_equal(self, sub, param1, param2, a, b): |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
433 if self._getval(a) == self._getval(b): |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
434 self.call(sub, param1, param2) |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
435 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
436 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
437 @instruction(43) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
438 def set_pos(self, x, y, z): |
74
adac26098408
Handle variables in set_pos instruction (Daiyousei...)
Thibaut Girka <thib@sitedethib.com>
parents:
70
diff
changeset
|
439 self._enemy.set_pos(self._getval(x), self._getval(y), self._getval(z)) |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
440 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
441 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
442 @instruction(45) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
443 def set_angle_speed(self, angle, speed): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
444 self._enemy.angle, self._enemy.speed = angle, speed |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
445 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
446 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
447 @instruction(46) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
448 def set_rotation_speed(self, speed): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
449 self._enemy.rotation_speed = speed |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
450 |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
451 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
452 @instruction(47) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
453 def set_speed(self, speed): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
454 self._enemy.speed = speed |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
455 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
456 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
457 @instruction(48) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
458 def set_acceleration(self, acceleration): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
459 self._enemy.acceleration = acceleration |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
460 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
461 |
70
7c1f20407b3e
Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
462 @instruction(49) |
7c1f20407b3e
Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
463 def set_random_angle(self, min_angle, max_angle): |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
464 angle = self._game.prng.rand_double() * (max_angle - min_angle) + min_angle |
70
7c1f20407b3e
Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
465 self._enemy.angle = angle |
7c1f20407b3e
Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
466 |
7c1f20407b3e
Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
467 |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
468 @instruction(50) |
70
7c1f20407b3e
Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
469 def set_random_angle_ex(self, min_angle, max_angle): |
59
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
470 if self._enemy.screen_box: |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
471 minx, miny, maxx, maxy = self._enemy.screen_box |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
472 else: |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
473 minx, miny, maxx, maxy = (0., 0., 0., 0.) |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
474 |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
475 angle = self._game.prng.rand_double() * (max_angle - min_angle) + min_angle |
59
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
476 sa, ca = sin(angle), cos(angle) |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
477 |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
478 if self._enemy.x > maxx - 96.0: |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
479 ca = -abs(ca) |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
480 elif self._enemy.x < minx + 96.0: |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
481 ca = abs(ca) |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
482 |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
483 if self._enemy.y > maxy - 48.0: |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
484 sa = -abs(sa) |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
485 elif self._enemy.y < miny + 48.0: |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
486 sa = abs(sa) |
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
487 self._enemy.angle = atan2(sa, ca) |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
488 |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
489 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
490 @instruction(51) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
491 def target_player(self, unknown, speed): |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
492 #TODO: unknown |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
493 self._enemy.speed = speed |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
494 self._enemy.angle = self._enemy.get_player_angle() |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
495 |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
496 |
76
f305c0e406d6
Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
75
diff
changeset
|
497 @instruction(56) |
f305c0e406d6
Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
75
diff
changeset
|
498 def move_to_linear(self, duration, x, y, z): |
140
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
499 self._enemy.move_to(duration, |
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
500 self._getval(x), self._getval(y), self._getval(z), |
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
501 lambda x: x) |
76
f305c0e406d6
Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
75
diff
changeset
|
502 |
f305c0e406d6
Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
75
diff
changeset
|
503 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
504 @instruction(57) |
76
f305c0e406d6
Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
75
diff
changeset
|
505 def move_to_decel(self, duration, x, y, z): |
140
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
506 self._enemy.move_to(duration, |
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
507 self._getval(x), self._getval(y), self._getval(z), |
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
508 lambda x: 2. * x - x ** 2) |
62
1f591adcea04
Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents:
59
diff
changeset
|
509 |
1f591adcea04
Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents:
59
diff
changeset
|
510 |
1f591adcea04
Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents:
59
diff
changeset
|
511 @instruction(59) |
76
f305c0e406d6
Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
75
diff
changeset
|
512 def move_to_accel(self, duration, x, y, z): |
140
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
513 self._enemy.move_to(duration, |
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
514 self._getval(x), self._getval(y), self._getval(z), |
a9d46c4b5764
Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents:
134
diff
changeset
|
515 lambda x: x ** 2) |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
516 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
517 |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
518 @instruction(61) |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
519 def stop_in(self, duration): |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
520 self._enemy.stop_in(duration, lambda x: x) |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
521 |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
522 |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
523 @instruction(63) |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
524 def stop_in_accel(self, duration): |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
525 self._enemy.stop_in(duration, lambda x: 1. - x) |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
526 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
527 |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
528 @instruction(65) |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
529 def set_screen_box(self, xmin, ymin, xmax, ymax): |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
530 self._enemy.screen_box = xmin, ymin, xmax, ymax |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
531 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
532 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
533 @instruction(66) |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
534 def clear_screen_box(self): |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
535 self._enemy.screen_box = None |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
536 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
537 |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
538 @instruction(67) |
82 | 539 def set_bullet_attributes1(self, anim, sprite_idx_offset, bullets_per_shot, |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
540 number_of_shots, speed, speed2, launch_angle, |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
541 angle, flags): |
82 | 542 self._enemy.set_bullet_attributes(67, anim, |
543 self._getval(sprite_idx_offset), | |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
544 self._getval(bullets_per_shot), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
545 self._getval(number_of_shots), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
546 self._getval(speed), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
547 self._getval(speed2), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
548 self._getval(launch_angle), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
549 self._getval(angle), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
550 flags) |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
551 |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
552 |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
553 @instruction(68) |
82 | 554 def set_bullet_attributes2(self, anim, sprite_idx_offset, bullets_per_shot, |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
555 number_of_shots, speed, speed2, launch_angle, |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
556 angle, flags): |
82 | 557 self._enemy.set_bullet_attributes(68, anim, |
558 self._getval(sprite_idx_offset), | |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
559 self._getval(bullets_per_shot), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
560 self._getval(number_of_shots), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
561 self._getval(speed), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
562 self._getval(speed2), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
563 self._getval(launch_angle), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
564 self._getval(angle), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
565 flags) |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
566 |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
567 |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
568 @instruction(69) |
82 | 569 def set_bullet_attributes3(self, anim, sprite_idx_offset, bullets_per_shot, |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
570 number_of_shots, speed, speed2, launch_angle, |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
571 angle, flags): |
82 | 572 self._enemy.set_bullet_attributes(69, anim, |
573 self._getval(sprite_idx_offset), | |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
574 self._getval(bullets_per_shot), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
575 self._getval(number_of_shots), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
576 self._getval(speed), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
577 self._getval(speed2), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
578 self._getval(launch_angle), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
579 self._getval(angle), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
580 flags) |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
581 |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
582 |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
583 @instruction(70) |
82 | 584 def set_bullet_attributes4(self, anim, sprite_idx_offset, bullets_per_shot, |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
585 number_of_shots, speed, speed2, launch_angle, |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
586 angle, flags): |
82 | 587 self._enemy.set_bullet_attributes(70, anim, |
588 self._getval(sprite_idx_offset), | |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
589 self._getval(bullets_per_shot), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
590 self._getval(number_of_shots), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
591 self._getval(speed), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
592 self._getval(speed2), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
593 self._getval(launch_angle), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
594 self._getval(angle), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
595 flags) |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
596 |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
597 |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
598 @instruction(71) |
82 | 599 def set_bullet_attributes5(self, anim, sprite_idx_offset, bullets_per_shot, |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
600 number_of_shots, speed, speed2, launch_angle, |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
601 angle, flags): |
82 | 602 self._enemy.set_bullet_attributes(71, anim, |
603 self._getval(sprite_idx_offset), | |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
604 self._getval(bullets_per_shot), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
605 self._getval(number_of_shots), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
606 self._getval(speed), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
607 self._getval(speed2), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
608 self._getval(launch_angle), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
609 self._getval(angle), |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
610 flags) |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
611 |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
612 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
613 @instruction(74) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
614 def set_bullet_attributes6(self, anim, sprite_idx_offset, bullets_per_shot, |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
615 number_of_shots, speed, speed2, launch_angle, |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
616 angle, flags): |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
617 #TODO |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
618 self._enemy.set_bullet_attributes(74, anim, |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
619 self._getval(sprite_idx_offset), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
620 self._getval(bullets_per_shot), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
621 self._getval(number_of_shots), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
622 self._getval(speed), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
623 self._getval(speed2), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
624 self._getval(launch_angle), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
625 self._getval(angle), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
626 flags) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
627 |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
628 |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
629 @instruction(75) |
106 | 630 def set_bullet_attributes7(self, anim, sprite_idx_offset, bullets_per_shot, |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
631 number_of_shots, speed, speed2, launch_angle, |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
632 angle, flags): |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
633 #TODO |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
634 self._enemy.set_bullet_attributes(75, anim, |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
635 self._getval(sprite_idx_offset), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
636 self._getval(bullets_per_shot), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
637 self._getval(number_of_shots), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
638 self._getval(speed), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
639 self._getval(speed2), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
640 self._getval(launch_angle), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
641 self._getval(angle), |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
642 flags) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
643 |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
82
diff
changeset
|
644 |
78
bcf965ede96c
Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents:
77
diff
changeset
|
645 @instruction(76) |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
646 def set_bullet_interval(self, value): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
647 self._enemy.bullet_launch_interval = value |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
648 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
649 |
78
bcf965ede96c
Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents:
77
diff
changeset
|
650 @instruction(77) |
bcf965ede96c
Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents:
77
diff
changeset
|
651 def set_bullet_interval_ex(self, value): |
82 | 652 self._enemy.bullet_launch_interval = value |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
653 self._enemy.bullet_launch_timer = int(self._game.prng.rand_double() * value) #TODO: check |
78
bcf965ede96c
Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents:
77
diff
changeset
|
654 |
bcf965ede96c
Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents:
77
diff
changeset
|
655 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
656 @instruction(78) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
657 def set_delay_attack(self): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
658 self._enemy.delay_attack = True |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
659 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
660 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
661 @instruction(79) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
662 def set_no_delay_attack(self): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
663 self._enemy.delay_attack = False |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
664 |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
665 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
666 @instruction(81) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
667 def set_bullet_launch_offset(self, x, y, z): |
134
e9ac3640280b
Add support for enemy spawnling enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
128
diff
changeset
|
668 self._enemy.bullet_launch_offset = (self._getval(x), self._getval(y)) |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
669 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
670 |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
671 @instruction(82) |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
672 def set_extended_bullet_attributes(self, *attributes): |
102
ad9297e0fbf2
Handle variables in ECL instruction 82
Thibaut Girka <thib@sitedethib.com>
parents:
100
diff
changeset
|
673 self._enemy.extended_bullet_attributes = tuple(self._getval(attr) for attr in attributes) |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
674 |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
675 |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
147
diff
changeset
|
676 @instruction(83) |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
147
diff
changeset
|
677 def change_bullets_into_star_items(self): |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
678 self._game.change_bullets_into_star_items() |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
147
diff
changeset
|
679 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
147
diff
changeset
|
680 |
95
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
93
diff
changeset
|
681 @instruction(93) |
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
93
diff
changeset
|
682 def set_spellcard(self, unknown, number, name): |
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
93
diff
changeset
|
683 #TODO: display it on the game. |
155
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
684 #TODO: change the background. |
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
685 #TODO: make the enemies more resistants (and find how). |
160
606468ab4f7b
Clean up bullets when starting a spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
159
diff
changeset
|
686 self._game.change_bullets_into_star_items() |
155
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
687 print("%d - %s" % (number+1, name)) |
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
688 |
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
689 |
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
690 @instruction(94) |
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
691 def end_spellcard(self): |
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
692 #TODO: return everything back to normal |
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
693 #TODO: give the spellcard bonus. |
ed86bec43b93
Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
154
diff
changeset
|
694 self._game.change_bullets_into_star_items() |
95
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
93
diff
changeset
|
695 |
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
93
diff
changeset
|
696 |
134
e9ac3640280b
Add support for enemy spawnling enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
128
diff
changeset
|
697 @instruction(95) |
e9ac3640280b
Add support for enemy spawnling enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
128
diff
changeset
|
698 def pop_enemy(self, sub, x, y, z, life, bonus_dropped, unknown2): |
159
4684d311a32d
Remove remaining pop_enemy/new_enemy mess
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
699 self._game.ecl_runner._pop_enemy(sub, 0, self._getval(x), self._getval(y), 0, life, bonus_dropped, unknown2, 0) # TODO: check about unknown values |
134
e9ac3640280b
Add support for enemy spawnling enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
128
diff
changeset
|
700 |
e9ac3640280b
Add support for enemy spawnling enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
128
diff
changeset
|
701 |
154
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
702 @instruction(96) |
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
703 def kill_enemies(self): |
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
704 for enemy in self._game.enemies: |
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
705 enemy.killed() |
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
706 |
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
707 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
708 @instruction(97) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
709 def set_anim(self, sprite_index): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
710 self._enemy.set_anim(sprite_index) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
711 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
712 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
713 @instruction(98) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
714 def set_multiple_anims(self, default, end_left, end_right, left, right): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
715 self._enemy.movement_dependant_sprites = end_left, end_right, left, right |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
716 self._enemy.set_anim(default) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
717 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
718 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
719 @instruction(100) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
720 def set_death_anim(self, sprite_index): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
721 self._enemy.death_anim = sprite_index % 256 #TODO |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
722 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
723 |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
724 @instruction(101) |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
725 def set_boss_mode(self, unknown): |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
726 #TODO: unknown |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
727 self._game.boss = self._enemy |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
728 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
55
diff
changeset
|
729 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
730 @instruction(103) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
731 def set_hitbox(self, width, height, depth): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
732 self._enemy.hitbox = (width, height) |
152
86807b8a63bd
Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
151
diff
changeset
|
733 self._enemy.hitbox_half_size = (width / 2., height / 2.) |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
734 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
735 |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
736 @instruction(104) |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
737 def set_collidable(self, collidable): |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
738 """Defines whether the enemy is “collidable”. |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
739 A collision between a collidable enemy and the player will kill the player. |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
740 """ |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
741 self._enemy.collidable = bool(collidable & 1) |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
742 |
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
743 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
744 @instruction(105) |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
745 def set_damageable(self, damageable): |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
746 self._enemy.damageable = bool(damageable & 1) |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
747 |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
748 |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
749 @instruction(107) |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
750 def set_death_flags(self, death_flags): |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
751 self._enemy.death_flags = death_flags |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
752 |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
753 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
754 @instruction(108) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
755 def set_death_callback(self, sub): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
756 self._enemy.death_callback = sub |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
757 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
758 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
759 @instruction(109) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
760 def memory_write(self, value, index): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
761 #TODO |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
762 #XXX: this is a hack to display bosses although we don't handle MSG :) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
763 if index == 0: |
103
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
764 self._enemy.boss_callback = value |
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
765 else: |
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
102
diff
changeset
|
766 raise Exception #TODO |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
767 |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
768 |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
769 @instruction(111) |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
770 def set_life(self, value): |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
771 self._enemy.life = value |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
772 |
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
773 |
67
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
774 @instruction(112) |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
775 def set_ellapsed_time(self, value): |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
776 """Sets the enemy's frame counter. |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
777 This is used for timeouts, where the framecounter is compared to the |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
778 timeout value (what's displayed is (enemy.timeout - enemy.frame) // 60). |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
779 """ |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
780 self._enemy.frame = value |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
781 |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
782 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
783 @instruction(113) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
784 def set_low_life_trigger(self, value): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
785 self._enemy.low_life_trigger = value |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
786 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
787 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
788 @instruction(114) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
789 def set_low_life_callback(self, sub): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
790 self._enemy.low_life_callback = sub |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
791 |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
792 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
793 @instruction(115) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
794 def set_timeout(self, timeout): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
795 self._enemy.timeout = timeout |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
796 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
797 |
67
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
798 @instruction(116) |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
799 def set_timeout_callback(self, sub): |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
800 self._enemy.timeout_callback = sub |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
801 |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
802 |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
803 @instruction(117) |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
804 def set_touchable(self, value): |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
805 """Defines whether the enemy is “touchable”. |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
806 Bullets only collide with an enemy if it is “touchable”. |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
807 Likewise, ReimuA's homing attacks only target “touchable” enemies. |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
808 """ |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
809 self._enemy.touchable = bool(value) |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
810 |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
65
diff
changeset
|
811 |
154
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
812 @instruction(119) |
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
813 def drop_some_bonus(self, number): |
165
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
814 bonus = 0 if self._enemy.select_player().state.power < 128 else 1 |
154
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
815 for i in range(number): |
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
816 #TODO: find the formula in the binary. |
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
817 self._game.drop_bonus(self._enemy.x - 64 + self._game.prng.rand_uint16() % 128, |
165
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
818 self._enemy.y - 64 + self._game.prng.rand_uint16() % 128, |
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
819 bonus) |
154
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
820 |
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
821 |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
822 @instruction(120) |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
823 def set_automatic_orientation(self, flags): |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
824 #TODO: does it change anything else than the sprite's rotation? |
82 | 825 self._enemy.automatic_orientation = bool(flags & 1) |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
826 |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
827 |
107
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
828 @instruction(121) |
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
829 def call_special_function(self, function, arg): |
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
830 if function == 0: # Cirno |
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
831 if arg == 0: |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
832 for bullet in self._game.bullets: |
107
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
833 bullet.speed = bullet.angle = 0. |
128
8ba018617829
Fix Cirno's freezing bullets
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
834 bullet.delta = (0., 0.) |
8ba018617829
Fix Cirno's freezing bullets
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
835 bullet.set_anim(sprite_idx_offset=15) #TODO: check |
107
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
836 else: |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
837 for bullet in self._game.bullets: |
107
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
838 bullet.speed = 2.0 #TODO |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
839 bullet.angle = self._game.prng.rand_double() * pi #TODO |
128
8ba018617829
Fix Cirno's freezing bullets
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
840 bullet.delta = (cos(bullet.angle) * bullet.speed, sin(bullet.angle) * bullet.speed) |
107
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
841 else: |
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
842 logger.warn("Unimplemented special function %d!", function) |
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
843 |
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
844 |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
845 @instruction(123) |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
846 def skip_frames(self, frames): |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
847 #TODO: is that all? |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
848 self.frame += self._getval(frames) |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
849 |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
74
diff
changeset
|
850 |
154
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
851 @instruction(124) |
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
852 def drop_specific_bonus(self, _type): |
165
c8c60291c56f
Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
160
diff
changeset
|
853 #TODO: if _type < 0, “drop” an bullet animation instead of a bonus (never used). |
154
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
854 self._game.drop_bonus(self._enemy.x, self._enemy.y, _type) |
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
855 |
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
856 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
857 @instruction(126) |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
858 def set_remaining_lives(self, lives): |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
859 self._enemy.remaining_lives = lives |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
860 |