comparison pytouhou/vm/eclrunner.py @ 318:1366cefd0334

Move callbacks handling inside Enemy.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 17 May 2012 14:15:19 +0200
parents f0be7ea62330
children 1a4ffdda8735
comparison
equal deleted inserted replaced
317:8579c43c124c 318:1366cefd0334
147 self.frame = 0 147 self.frame = 0
148 self.sub = sub 148 self.sub = sub
149 self.instruction_pointer = 0 149 self.instruction_pointer = 0
150 150
151 151
152 def handle_callbacks(self):
153 #TODO: implement missing callbacks and clean up!
154 enm = self._enemy
155 if enm.life <= 0 and enm.touchable:
156 death_flags = enm.death_flags & 7
157
158 enm.die_anim()
159
160 if death_flags < 4:
161 if enm.bonus_dropped > -1:
162 enm.drop_particles(7, 0)
163 self._game.drop_bonus(enm.x, enm.y, enm.bonus_dropped)
164 elif enm.bonus_dropped == -1:
165 if self._game.deaths_count % 3 == 0:
166 enm.drop_particles(10, 0)
167 self._game.drop_bonus(enm.x, enm.y, self._game.bonus_list[self._game.next_bonus])
168 self._game.next_bonus = (self._game.next_bonus + 1) % 32
169 else:
170 enm.drop_particles(4, 0)
171 self._game.deaths_count += 1
172 else:
173 enm.drop_particles(4, 0)
174
175 if death_flags == 0:
176 enm.removed = True
177 return
178
179 if death_flags == 1:
180 enm.touchable = False
181 elif death_flags == 2:
182 pass # Just that?
183 elif death_flags == 3:
184 #TODO: disable boss mode
185 enm.damageable = False
186 enm.life = 1
187 enm.death_flags = 0
188
189 if death_flags != 0 and enm.death_callback > -1:
190 self.switch_to_sub(enm.death_callback)
191 enm.death_callback = -1
192 elif enm.life <= enm.low_life_trigger and enm.low_life_callback > -1:
193 self.switch_to_sub(enm.low_life_callback)
194 enm.low_life_callback = -1
195 elif enm.timeout != -1 and enm.frame == enm.timeout:
196 enm.frame = 0
197 if enm.timeout_callback > -1:
198 self.switch_to_sub(enm.timeout_callback)
199 enm.timeout_callback = -1
200 elif enm.touchable:
201 enm.life = 0
202 elif enm.death_callback > -1:
203 self.switch_to_sub(enm.death_callback)
204 enm.death_callback = -1
205 enm.timeout = -1 #TODO: check
206 else:
207 raise Exception('What the hell, man!')
208
209
210 def run_iteration(self): 152 def run_iteration(self):
211 # Process script 153 # Process script
212 while self.running: 154 while self.running:
213 try: 155 try:
214 frame, instr_type, rank_mask, param_mask, args = self._ecl.subs[self.sub][self.instruction_pointer] 156 frame, instr_type, rank_mask, param_mask, args = self._ecl.subs[self.sub][self.instruction_pointer]
232 else: 174 else:
233 callback(self, *args) 175 callback(self, *args)
234 logger.debug('executed opcode %d (args: %r)', instr_type, args) 176 logger.debug('executed opcode %d (args: %r)', instr_type, args)
235 177
236 self.frame += 1 178 self.frame += 1
237
238 # Handle callbacks
239 self.handle_callbacks()
240 179
241 180
242 def _getval(self, value): 181 def _getval(self, value):
243 if -10012 <= value <= -10001: 182 if -10012 <= value <= -10001:
244 return self.variables[int(-10001-value)] 183 return self.variables[int(-10001-value)]