annotate pytouhou/game/enemy.py @ 154:364935f6e313

Implement enemy killing.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 09 Oct 2011 16:55:18 -0700
parents 86807b8a63bd
children ebfd328e700c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
1 # -*- encoding: utf-8 -*-
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
2 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
4 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
6 ## it under the terms of the GNU General Public License as published
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
7 ## by the Free Software Foundation; version 3 only.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
8 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
9 ## This program is distributed in the hope that it will be useful,
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
12 ## GNU General Public License for more details.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
13 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
14
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
15
20
6ebf9539c077 Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents: 18
diff changeset
16 from pytouhou.utils.interpolator import Interpolator
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
17 from pytouhou.vm.eclrunner import ECLRunner
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
18 from pytouhou.vm.anmrunner import ANMRunner
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
19 from pytouhou.game.sprite import Sprite
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
20 from pytouhou.game.bullet import Bullet
154
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
21 from pytouhou.game.item import Item
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
22 from math import cos, sin, atan2, pi
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
23
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
24
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
25 class Enemy(object):
154
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
26 def __init__(self, pos, life, _type, bonus_dropped, anm_wrapper, game, pop_enemy):
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
27 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
28 self._anm_wrapper = anm_wrapper
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
29 self._sprite = None
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
30 self._anmrunner = None
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
31 self._removed = False
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
32 self._type = _type
154
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
33 self._bonus_dropped = bonus_dropped
56
299de3a9b69f Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
34 self._was_visible = False
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
35
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
36 self.frame = 0
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
37
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
38 self.x, self.y = pos
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
39 self.life = life
36
f46c18872796 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 34
diff changeset
40 self.max_life = life
67
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 62
diff changeset
41 self.touchable = True
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 62
diff changeset
42 self.damageable = True
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 62
diff changeset
43 self.death_flags = 0
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
44 self.extended_bullet_attributes = (0, 0, 0, 0, 0., 0., 0., 0.)
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
45 self.bullet_attributes = None
36
f46c18872796 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 34
diff changeset
46 self.bullet_launch_offset = (0, 0)
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
47 self.death_callback = None
103
789994275968 Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents: 100
diff changeset
48 self.boss_callback = None
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
49 self.low_life_callback = None
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
50 self.low_life_trigger = None
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
51 self.timeout = None
67
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 62
diff changeset
52 self.timeout_callback = None
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
53 self.remaining_lives = -1
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
54
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 73
diff changeset
55 self.automatic_orientation = False
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 73
diff changeset
56
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
57 self.bullet_launch_interval = 0
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
58 self.bullet_launch_timer = 0
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
59 self.delay_attack = False
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
60
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
61 self.death_anim = None
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
62 self.movement_dependant_sprites = None
22
fa87db09fc3a Fix Rumia's animations
Thibaut Girka <thib@sitedethib.com>
parents: 21
diff changeset
63 self.direction = None
20
6ebf9539c077 Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents: 18
diff changeset
64 self.interpolator = None #TODO
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
65 self.speed_interpolator = None
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
66 self.angle = 0.
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
67 self.speed = 0.
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
68 self.rotation_speed = 0.
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
69 self.acceleration = 0.
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
70
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
71 self.hitbox = (0, 0)
152
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 151
diff changeset
72 self.hitbox_half_size = (0, 0)
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
73 self.screen_box = None
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
74
134
e9ac3640280b Add support for enemy spawnling enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 132
diff changeset
75 self.pop_enemy = pop_enemy
e9ac3640280b Add support for enemy spawnling enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 132
diff changeset
76
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
77
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
78 def set_bullet_attributes(self, type_, anim, sprite_idx_offset,
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
79 bullets_per_shot, number_of_shots, speed, speed2,
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
80 launch_angle, angle, flags):
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
81 self.bullet_attributes = (type_, 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: 75
diff changeset
82 number_of_shots, speed, speed2, launch_angle,
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
83 angle, flags)
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
84 if not self.delay_attack:
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
85 self.fire()
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
86
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
87
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
88 def fire(self):
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
89 (type_, type_idx, sprite_idx_offset, bullets_per_shot, number_of_shots,
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
90 speed, speed2, launch_angle, angle, flags) = self.bullet_attributes
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
91
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
92 bullet_type = self._game.bullet_types[type_idx]
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
93
109
e93a7ed4f203 Implement bullet_launch_offset thing
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
94 ox, oy = self.bullet_launch_offset
e93a7ed4f203 Implement bullet_launch_offset thing
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
95 launch_pos = self.x + ox, self.y + oy
e93a7ed4f203 Implement bullet_launch_offset thing
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
96
104
6c59d0eeb5fa Implement ECL instruction 75 in the same exact way as 102h.exe
Thibaut Girka <thib@sitedethib.com>
parents: 103
diff changeset
97 if speed2 < 0.3:
6c59d0eeb5fa Implement ECL instruction 75 in the same exact way as 102h.exe
Thibaut Girka <thib@sitedethib.com>
parents: 103
diff changeset
98 speed2 = 0.3
6c59d0eeb5fa Implement ECL instruction 75 in the same exact way as 102h.exe
Thibaut Girka <thib@sitedethib.com>
parents: 103
diff changeset
99
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
100 self.bullet_launch_timer = 0
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
101
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
102 player = self.select_player()
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
103
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
104 if type_ in (67, 69, 71):
132
fba45c37ec99 Fix initial angle of bullets with bullet_launch_offset enabled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 130
diff changeset
105 launch_angle += self.get_player_angle(player, launch_pos)
135
c53d91300c1c Implement instruction 74.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 134
diff changeset
106 if type_ in (69, 70, 71, 74):
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
107 angle = 2. * pi / bullets_per_shot
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
108 if type_ == 71:
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
109 launch_angle += pi / bullets_per_shot
104
6c59d0eeb5fa Implement ECL instruction 75 in the same exact way as 102h.exe
Thibaut Girka <thib@sitedethib.com>
parents: 103
diff changeset
110 if type_ != 75:
6c59d0eeb5fa Implement ECL instruction 75 in the same exact way as 102h.exe
Thibaut Girka <thib@sitedethib.com>
parents: 103
diff changeset
111 launch_angle -= angle * (bullets_per_shot - 1) / 2.
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
112
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
113 bullets = self._game.bullets
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
114 nb_bullets_max = self._game.nb_bullets_max
106
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 105
diff changeset
115
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
116 for shot_nb in range(number_of_shots):
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
117 shot_speed = speed if shot_nb == 0 else speed + (speed2 - speed) * float(shot_nb) / float(number_of_shots)
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
118 bullet_angle = launch_angle
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
119 for bullet_nb in range(bullets_per_shot):
143
ea21bb37febe Add max bullets limit
Thibaut Girka <thib@sitedethib.com>
parents: 135
diff changeset
120 if nb_bullets_max is not None and len(bullets) == nb_bullets_max:
ea21bb37febe Add max bullets limit
Thibaut Girka <thib@sitedethib.com>
parents: 135
diff changeset
121 break
ea21bb37febe Add max bullets limit
Thibaut Girka <thib@sitedethib.com>
parents: 135
diff changeset
122
135
c53d91300c1c Implement instruction 74.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 134
diff changeset
123 if type_ == 75: # 102h.exe@0x4138cf
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
124 bullet_angle = self._game.prng.rand_double() * (launch_angle - angle) + angle
135
c53d91300c1c Implement instruction 74.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 134
diff changeset
125 if type_ in (74, 75): # 102h.exe@0x4138cf
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
126 shot_speed = self._game.prng.rand_double() * (speed - speed2) + speed2
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
127 bullets.append(Bullet(launch_pos, bullet_type, sprite_idx_offset,
106
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 105
diff changeset
128 bullet_angle, shot_speed,
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 105
diff changeset
129 self.extended_bullet_attributes,
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
130 flags, player, self._game))
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
131 bullet_angle += angle
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
132
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
133
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
134 def select_player(self, players=None):
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
135 return (players or self._game.players)[0] #TODO
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
136
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
137
132
fba45c37ec99 Fix initial angle of bullets with bullet_launch_offset enabled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 130
diff changeset
138 def get_player_angle(self, player=None, pos=None):
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
139 player = player or self.select_player()
132
fba45c37ec99 Fix initial angle of bullets with bullet_launch_offset enabled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 130
diff changeset
140 x, y = pos or (self.x, self.y)
fba45c37ec99 Fix initial angle of bullets with bullet_launch_offset enabled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 130
diff changeset
141 return atan2(player.y - y, player.x - x)
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
142
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
143
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
144 def set_anim(self, index):
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
145 self._sprite = Sprite()
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
146 self._anmrunner = ANMRunner(self._anm_wrapper, index, self._sprite)
105
572740acdb25 A few changes in the execution order to match 102h.exe
Thibaut Girka <thib@sitedethib.com>
parents: 104
diff changeset
147 self._anmrunner.run_frame()
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
148
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
149
152
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 151
diff changeset
150 def collide(self, player):
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 151
diff changeset
151 if self.touchable:
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 151
diff changeset
152 #TODO: animation
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 151
diff changeset
153 #TODO: doesn’t always kill herself (a boss for example), search how
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 151
diff changeset
154 self._removed = True
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 151
diff changeset
155 player.die()
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 151
diff changeset
156
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 151
diff changeset
157
154
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
158 def killed(self):
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
159 if self.touchable:
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
160 if 0 <= self._bonus_dropped < 256:
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
161 self._game.drop_bonus(self.x, self.y, 0)
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
162 elif -256 <= self._bonus_dropped < 0:
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
163 pass #TODO: should be random, search how it is done.
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
164
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
165 #TODO: use self.death_flags
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
166 self._removed = True
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
167
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
168
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
169 def set_pos(self, x, y, z):
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
170 self.x, self.y = x, y
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
171 self.interpolator = Interpolator((x, y))
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
172 self.interpolator.set_interpolation_start(self._game.frame, (x, y))
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
173
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
174
62
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
175 def move_to(self, duration, x, y, z, formula):
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
176 if not self.interpolator:
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
177 frame = self._game.frame
62
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
178 self.interpolator = Interpolator((self.x, self.y), formula)
100
5c40cc1b8019 Use game's frame for interpolation. No more time manipulation interfering with interpolators!
Thibaut Girka <thib@sitedethib.com>
parents: 98
diff changeset
179 self.interpolator.set_interpolation_start(frame, (self.x, self.y))
5c40cc1b8019 Use game's frame for interpolation. No more time manipulation interfering with interpolators!
Thibaut Girka <thib@sitedethib.com>
parents: 98
diff changeset
180 self.interpolator.set_interpolation_end(frame + duration - 1, (x, y))
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
181
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 73
diff changeset
182 self.speed = 0.
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 73
diff changeset
183 self.angle = atan2(y - self.y, x - self.x)
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
184
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 73
diff changeset
185
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 73
diff changeset
186 def stop_in(self, duration, formula):
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
187 if not self.speed_interpolator:
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
188 frame = self._game.frame
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 73
diff changeset
189 self.speed_interpolator = Interpolator((self.speed,), formula)
100
5c40cc1b8019 Use game's frame for interpolation. No more time manipulation interfering with interpolators!
Thibaut Girka <thib@sitedethib.com>
parents: 98
diff changeset
190 self.speed_interpolator.set_interpolation_start(frame, (self.speed,))
5c40cc1b8019 Use game's frame for interpolation. No more time manipulation interfering with interpolators!
Thibaut Girka <thib@sitedethib.com>
parents: 98
diff changeset
191 self.speed_interpolator.set_interpolation_end(frame + duration - 1, (0.,))
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
192
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 73
diff changeset
193 self.speed = 0.
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 73
diff changeset
194
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
195
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
196 def is_visible(self, screen_width, screen_height):
73
e4af16a019d3 Do not remove enemies as soon as they lose their animation (Daiyousei...)
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
197 if self._sprite:
e4af16a019d3 Do not remove enemies as soon as they lose their animation (Daiyousei...)
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
198 tx, ty, tw, th = self._sprite.texcoords
e4af16a019d3 Do not remove enemies as soon as they lose their animation (Daiyousei...)
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
199 if self._sprite.corner_relative_placement:
e4af16a019d3 Do not remove enemies as soon as they lose their animation (Daiyousei...)
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
200 raise Exception #TODO
e4af16a019d3 Do not remove enemies as soon as they lose their animation (Daiyousei...)
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
201 else:
e4af16a019d3 Do not remove enemies as soon as they lose their animation (Daiyousei...)
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
202 tx, ty, tw, th = 0., 0., 0., 0.
29
afa91be769ae Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents: 23
diff changeset
203
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
204 x, y = self.x, self.y
73
e4af16a019d3 Do not remove enemies as soon as they lose their animation (Daiyousei...)
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
205 max_x = tw / 2.
e4af16a019d3 Do not remove enemies as soon as they lose their animation (Daiyousei...)
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
206 max_y = th / 2.
29
afa91be769ae Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents: 23
diff changeset
207
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
208 if (max_x < x - screen_width
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
209 or max_x < -x
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
210 or max_y < y - screen_height
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
211 or max_y < -y):
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
212 return False
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
213 return True
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
214
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
215
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
216 def update(self):
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
217 x, y = self.x, self.y
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
218 if self.interpolator:
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
219 self.interpolator.update(self._game.frame)
20
6ebf9539c077 Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents: 18
diff changeset
220 x, y = self.interpolator.values
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
221
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
222 self.speed += self.acceleration #TODO: units? Execution order?
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
223 self.angle += self.rotation_speed #TODO: units? Execution order?
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
224
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
225
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
226 if self.speed_interpolator:
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
227 self.speed_interpolator.update(self._game.frame)
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
228 self.speed, = self.speed_interpolator.values
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
229
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
230
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
231 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
232 if self._type & 2:
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
233 x -= dx
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
234 else:
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
235 x += dx
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
236 y += dy
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
237
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
238 if self.movement_dependant_sprites:
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
239 #TODO: is that really how it works? Almost.
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
240 # Sprite determination is done only once per changement, and is
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
241 # superseeded by ins_97.
62
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
242 end_left, end_right, left, right = self.movement_dependant_sprites
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
243 if x < self.x and self.direction != -1:
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
244 self.set_anim(left)
22
fa87db09fc3a Fix Rumia's animations
Thibaut Girka <thib@sitedethib.com>
parents: 21
diff changeset
245 self.direction = -1
62
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
246 elif x > self.x and self.direction != +1:
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
247 self.set_anim(right)
22
fa87db09fc3a Fix Rumia's animations
Thibaut Girka <thib@sitedethib.com>
parents: 21
diff changeset
248 self.direction = +1
62
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
249 elif x == self.x and self.direction is not None:
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
250 self.set_anim({-1: end_left, +1: end_right}[self.direction])
22
fa87db09fc3a Fix Rumia's animations
Thibaut Girka <thib@sitedethib.com>
parents: 21
diff changeset
251 self.direction = None
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
252
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
253
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
254 if self.screen_box:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
255 xmin, ymin, xmax, ymax = self.screen_box
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
256 x = max(xmin, min(x, xmax))
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
257 y = max(ymin, min(y, ymax))
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
258
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
259
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
260 self.x, self.y = x, y
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
261
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
262 #TODO
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
263 if self._anmrunner and not self._anmrunner.run_frame():
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
264 self._anmrunner = None
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
265
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
266 if self._sprite:
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
267 if self._sprite._removed:
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
268 self._sprite = None
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
269 else:
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 109
diff changeset
270 self._sprite.update_orientation(self.angle,
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 109
diff changeset
271 self.automatic_orientation)
36
f46c18872796 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 34
diff changeset
272
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
273
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
274 if self.bullet_launch_interval != 0:
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
275 self.bullet_launch_timer += 1
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
276 if self.bullet_launch_timer == self.bullet_launch_interval:
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
277 self.fire()
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
278
154
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
279 if self.life <= 0:
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
280 self.killed()
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
281
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
282 self.frame += 1
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
283