Mercurial > touhou
annotate pytouhou/game/enemy.py @ 260:e22e0d73f614
Implement bullet flags 1024 and 2048 (bouncing bullet).
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 22 Jan 2012 22:38:58 +0100 |
parents | ea4832f843aa |
children | dd621ad72beb |
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.anmrunner import ANMRunner |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
18 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
|
19 from pytouhou.game.bullet import Bullet |
242
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
20 from pytouhou.game.effect import Effect |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
75
diff
changeset
|
21 from math import cos, sin, atan2, pi |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
22 |
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 class Enemy(object): |
171
2f3665a77f11
Add support for the last unknown value of the enemy spawning.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
167
diff
changeset
|
25 def __init__(self, pos, life, _type, bonus_dropped, die_score, anm_wrapper, game): |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
26 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
|
27 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
|
28 self._sprite = None |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
68
diff
changeset
|
29 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
|
30 self._removed = False |
183
b6d7ce644f34
Implement two new ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
182
diff
changeset
|
31 self._visible = True |
49
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 |
171
2f3665a77f11
Add support for the last unknown value of the enemy spawning.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
167
diff
changeset
|
34 self._die_score = die_score #TODO: use it |
56
299de3a9b69f
Filter out off-screen enemies (the same way the official game does)
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
35 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
|
36 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
37 self.frame = 0 |
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
38 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
39 self.x, self.y = pos |
209
005ea47e11e0
Create enemy with negative life as it should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
207
diff
changeset
|
40 self.life = 1 if life < 0 else life |
36 | 41 self.max_life = life |
67
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
62
diff
changeset
|
42 self.touchable = True |
210
f5be441d2c42
Implement collidable boolean of enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
209
diff
changeset
|
43 self.collidable = True |
67
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
62
diff
changeset
|
44 self.damageable = True |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
62
diff
changeset
|
45 self.death_flags = 0 |
177
6e8653ff2b23
Fix boss mode and don’t suicide the boss when she just want to kill the other enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
46 self.boss = False |
182
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
47 self.difficulty_coeffs = (-.5, .5, 0, 0, 0, 0) |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
75
diff
changeset
|
48 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
|
49 self.bullet_attributes = None |
36 | 50 self.bullet_launch_offset = (0, 0) |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
51 self.death_callback = None |
103
789994275968
Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents:
100
diff
changeset
|
52 self.boss_callback = None |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
53 self.low_life_callback = None |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
54 self.low_life_trigger = None |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
55 self.timeout = None |
67
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
62
diff
changeset
|
56 self.timeout_callback = None |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
57 self.remaining_lives = -1 |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
58 |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
73
diff
changeset
|
59 self.automatic_orientation = False |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
73
diff
changeset
|
60 |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
61 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
|
62 self.bullet_launch_timer = 0 |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
63 self.delay_attack = False |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
64 |
167
e483b5a7e84b
Fix default death animation.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
166
diff
changeset
|
65 self.death_anim = 0 |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
66 self.movement_dependant_sprites = None |
22 | 67 self.direction = None |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
68 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
|
69 self.speed_interpolator = None |
251
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
70 self.update_mode = 0 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
71 self.angle = 0. |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
72 self.speed = 0. |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
73 self.rotation_speed = 0. |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
74 self.acceleration = 0. |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
75 |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
76 self.hitbox = (0, 0) |
152
86807b8a63bd
Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
151
diff
changeset
|
77 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
|
78 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
|
79 |
242
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
80 self.aux_anm = 8 * [None] |
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
81 |
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
82 |
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
83 def objects(self): |
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
84 return [anm for anm in self.aux_anm if anm] |
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
85 |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
86 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
79
diff
changeset
|
87 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
|
88 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
|
89 launch_angle, angle, flags): |
182
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
90 |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
91 # Apply difficulty-specific modifiers |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
92 speed_a, speed_b, nb_a, nb_b, shots_a, shots_b = self.difficulty_coeffs |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
93 diff_coeff = self._game.difficulty / 32. |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
94 |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
95 speed += speed_a * (1. - diff_coeff) + speed_b * diff_coeff |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
96 speed2 += (speed_a * (1. - diff_coeff) + speed_b * diff_coeff) / 2. |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
97 bullets_per_shot += int(nb_a * (1. - diff_coeff) + nb_b * diff_coeff) |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
98 number_of_shots += int(shots_a * (1. - diff_coeff) + shots_b * diff_coeff) |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
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_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
|
101 number_of_shots, speed, speed2, launch_angle, |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
102 angle, flags) |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
103 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
|
104 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
|
105 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
106 |
182
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
107 def set_bullet_launch_interval(self, value, start=0.): |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
108 # Apply difficulty-specific modifiers: |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
109 value *= 1. - .4 * (self._game.difficulty - 16.) / 32. |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
110 |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
111 self.bullet_launch_interval = int(value) |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
112 self.bullet_launch_timer = int(value * start) |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
113 |
20843875ad8f
(Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents:
181
diff
changeset
|
114 |
207 | 115 def fire(self, offset=None, bullet_attributes=None, launch_pos=None): |
123 | 116 (type_, type_idx, sprite_idx_offset, bullets_per_shot, number_of_shots, |
207 | 117 speed, speed2, launch_angle, angle, flags) = bullet_attributes or self.bullet_attributes |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
79
diff
changeset
|
118 |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
119 bullet_type = self._game.bullet_types[type_idx] |
123 | 120 |
207 | 121 if not launch_pos: |
122 ox, oy = offset or self.bullet_launch_offset | |
123 launch_pos = self.x + ox, self.y + oy | |
109
e93a7ed4f203
Implement bullet_launch_offset thing
Thibaut Girka <thib@sitedethib.com>
parents:
108
diff
changeset
|
124 |
253
ea4832f843aa
Fix initial bullet speed
Thibaut Girka <thib@sitedethib.com>
parents:
251
diff
changeset
|
125 if speed < 0.3: |
ea4832f843aa
Fix initial bullet speed
Thibaut Girka <thib@sitedethib.com>
parents:
251
diff
changeset
|
126 speed = 0.3 |
104
6c59d0eeb5fa
Implement ECL instruction 75 in the same exact way as 102h.exe
Thibaut Girka <thib@sitedethib.com>
parents:
103
diff
changeset
|
127 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
|
128 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
|
129 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
79
diff
changeset
|
130 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
|
131 |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
79
diff
changeset
|
132 player = self.select_player() |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
79
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 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
|
135 launch_angle += self.get_player_angle(player, launch_pos) |
135
c53d91300c1c
Implement instruction 74.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
134
diff
changeset
|
136 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
|
137 angle = 2. * pi / bullets_per_shot |
247
fb3a263213d1
Fix instruction 70 to always fire to the right.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
242
diff
changeset
|
138 if type_ == 71 and bullets_per_shot % 2 or type_ in (69, 70) and not bullets_per_shot % 2: |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
75
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
143 bullets = self._game.bullets |
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
144 nb_bullets_max = self._game.nb_bullets_max |
106 | 145 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
79
diff
changeset
|
146 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
|
147 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
|
148 bullet_angle = launch_angle |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
79
diff
changeset
|
149 for bullet_nb in range(bullets_per_shot): |
143 | 150 if nb_bullets_max is not None and len(bullets) == nb_bullets_max: |
151 break | |
152 | |
135
c53d91300c1c
Implement instruction 74.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
134
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 shot_speed = self._game.prng.rand_double() * (speed - speed2) + speed2 |
123 | 157 bullets.append(Bullet(launch_pos, bullet_type, sprite_idx_offset, |
106 | 158 bullet_angle, shot_speed, |
159 self.extended_bullet_attributes, | |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
143
diff
changeset
|
160 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
|
161 bullet_angle += angle |
48
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
162 |
8353c33d53d4
Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
163 |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
75
diff
changeset
|
164 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
|
165 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
|
166 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
167 |
132
fba45c37ec99
Fix initial angle of bullets with bullet_launch_offset enabled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
130
diff
changeset
|
168 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
|
169 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
|
170 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
|
171 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
|
172 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
173 |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
174 def set_anim(self, index): |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
68
diff
changeset
|
175 self._sprite = Sprite() |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
68
diff
changeset
|
176 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
|
177 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
|
178 |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
179 |
166
dcf32488a2c9
Better enemy death, with animation and (hopefully) correct flags handling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
159
diff
changeset
|
180 def die_anim(self): |
248
77b83064b57e
Use the correct animation for player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
247
diff
changeset
|
181 anim = {0: 3, 1: 4, 2: 5}[self.death_anim % 256] # The TB is wanted, if index isn’t in these values the original game crashs. |
77b83064b57e
Use the correct animation for player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
247
diff
changeset
|
182 self._game.new_effect((self.x, self.y), anim) |
190
dbe6b7b2d3fc
Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
184
diff
changeset
|
183 |
dbe6b7b2d3fc
Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
184
diff
changeset
|
184 |
dbe6b7b2d3fc
Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
184
diff
changeset
|
185 def drop_particles(self, number, color): |
dbe6b7b2d3fc
Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
184
diff
changeset
|
186 #TODO: white particles are only used in stage 3 to 6, |
dbe6b7b2d3fc
Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
184
diff
changeset
|
187 # in other stages they are blue. |
dbe6b7b2d3fc
Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
184
diff
changeset
|
188 if color == 0: |
dbe6b7b2d3fc
Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
184
diff
changeset
|
189 if self._game.stage in [1, 2, 7]: |
dbe6b7b2d3fc
Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
184
diff
changeset
|
190 color = 3 |
dbe6b7b2d3fc
Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
184
diff
changeset
|
191 for i in range(number): |
193
9f58e2a6e950
Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
190
diff
changeset
|
192 self._game.new_particle((self.x, self.y), color, 4., 256) #TODO: find the real size. |
154
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
193 |
364935f6e313
Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
194 |
242
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
195 def set_aux_anm(self, number, script): |
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
196 self.aux_anm[number] = Effect((self.x, self.y), script, self._anm_wrapper) |
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
197 |
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
198 |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
199 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
|
200 self.x, self.y = x, y |
251
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
201 self.update_mode = 1 |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
202 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
|
203 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
|
204 |
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
205 |
62
1f591adcea04
Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
206 def move_to(self, duration, x, y, z, formula): |
251
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
207 frame = self._game.frame |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
208 self.speed_interpolator = None |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
209 self.update_mode = 1 |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
210 self.interpolator = Interpolator((self.x, self.y), formula) |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
211 self.interpolator.set_interpolation_start(frame, (self.x, self.y)) |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
212 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
|
213 |
251
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
214 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
|
215 |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
73
diff
changeset
|
216 |
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
73
diff
changeset
|
217 def stop_in(self, duration, formula): |
251
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
218 frame = self._game.frame |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
219 self.interpolator = None |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
220 self.update_mode = 1 |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
221 self.speed_interpolator = Interpolator((self.speed,), formula) |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
222 self.speed_interpolator.set_interpolation_start(frame, (self.speed,)) |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
223 self.speed_interpolator.set_interpolation_end(frame + duration - 1, (0.,)) |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
73
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 |
23
444ac7bca7bc
Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
22
diff
changeset
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 else: |
e4af16a019d3
Do not remove enemies as soon as they lose their animation (Daiyousei...)
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
232 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
|
233 |
123 | 234 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
|
235 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
|
236 max_y = th / 2. |
29
afa91be769ae
Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents:
23
diff
changeset
|
237 |
123 | 238 if (max_x < x - screen_width |
239 or max_x < -x | |
240 or max_y < y - screen_height | |
241 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
|
242 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
|
243 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
|
244 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
245 |
202
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
246 def check_collisions(self): |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
247 # Check for collisions |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
248 ex, ey = self.x, self.y |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
249 ehalf_size_x, ehalf_size_y = self.hitbox_half_size |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
250 ex1, ex2 = ex - ehalf_size_x, ex + ehalf_size_x |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
251 ey1, ey2 = ey - ehalf_size_y, ey + ehalf_size_y |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
252 |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
253 damages = 0 |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
254 |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
255 # Check for enemy-bullet collisions |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
256 for bullet in self._game.players_bullets: |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
257 half_size = bullet.hitbox_half_size |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
258 bx, by = bullet.x, bullet.y |
220
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
212
diff
changeset
|
259 bx1, bx2 = bx - half_size[0], bx + half_size[0] |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
212
diff
changeset
|
260 by1, by2 = by - half_size[1], by + half_size[1] |
202
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
261 |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
262 if not (bx2 < ex1 or bx1 > ex2 |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
263 or by2 < ey1 or by1 > ey2): |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
264 bullet.collide() |
220
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
212
diff
changeset
|
265 damages += bullet.damage |
202
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
266 self.drop_particles(1, 1) |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
267 |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
268 # Check for enemy-player collisions |
212
78e9957ad344
Hopefully fix enemy-player collision
Thibaut Girka <thib@sitedethib.com>
parents:
210
diff
changeset
|
269 ex1, ex2 = ex - ehalf_size_x * 2. / 3., ex + ehalf_size_x * 2. / 3. |
78e9957ad344
Hopefully fix enemy-player collision
Thibaut Girka <thib@sitedethib.com>
parents:
210
diff
changeset
|
270 ey1, ey2 = ey - ehalf_size_y * 2. / 3., ey + ehalf_size_y * 2. / 3. |
210
f5be441d2c42
Implement collidable boolean of enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
209
diff
changeset
|
271 if self.collidable: |
202
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
272 for player in self._game.players: |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
273 px, py = player.x, player.y |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
274 phalf_size = player.hitbox_half_size |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
275 px1, px2 = px - phalf_size, px + phalf_size |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
276 py1, py2 = py - phalf_size, py + phalf_size |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
277 |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
278 #TODO: box-box or point-in-box? |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
279 if not (ex2 < px1 or ex1 > px2 or ey2 < py1 or ey1 > py2): |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
280 if not self.boss: |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
281 damages += 10 |
212
78e9957ad344
Hopefully fix enemy-player collision
Thibaut Girka <thib@sitedethib.com>
parents:
210
diff
changeset
|
282 player.collide() |
202
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
283 |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
284 # Adjust damages |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
285 damages = min(70, damages) |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
286 score = (damages // 5) * 10 #TODO: give to which player? |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
287 |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
288 if self._game.spellcard: |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
289 #TODO: there is a division by 3, somewhere... where is it? |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
290 if damages <= 7: |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
291 damages = 1 if damages else 0 |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
292 else: |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
293 damages //= 7 |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
294 |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
295 # Apply damages |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
296 if self.damageable: |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
297 self.life -= damages |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
298 |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
299 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
68
diff
changeset
|
300 def update(self): |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
301 x, y = self.x, self.y |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
302 |
251
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
303 if self.update_mode == 1: |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
304 speed = 0.0 |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
305 if self.interpolator: |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
306 self.interpolator.update(self._game.frame) |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
307 x, y = self.interpolator.values |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
308 if self.speed_interpolator: |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
309 self.speed_interpolator.update(self._game.frame) |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
310 speed, = self.speed_interpolator.values |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
311 else: |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
312 speed = self.speed |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
313 self.speed += self.acceleration |
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
314 self.angle += self.rotation_speed |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
56
diff
changeset
|
315 |
251
4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents:
248
diff
changeset
|
316 dx, dy = cos(self.angle) * speed, sin(self.angle) * speed |
49
cbe1cb50f2fd
Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents:
48
diff
changeset
|
317 if self._type & 2: |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
318 x -= dx |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
319 else: |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
320 x += dx |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
321 y += dy |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
322 |
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
323 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
|
324 #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
|
325 # 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
|
326 # 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
|
327 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
|
328 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
|
329 self.set_anim(left) |
22 | 330 self.direction = -1 |
62
1f591adcea04
Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
331 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
|
332 self.set_anim(right) |
22 | 333 self.direction = +1 |
62
1f591adcea04
Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
334 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
|
335 self.set_anim({-1: end_left, +1: end_right}[self.direction]) |
22 | 336 self.direction = None |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
337 |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
338 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
339 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
|
340 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
|
341 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
|
342 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
|
343 |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
344 |
21
bf225780973f
Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
345 self.x, self.y = x, y |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
68
diff
changeset
|
346 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
68
diff
changeset
|
347 #TODO |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
68
diff
changeset
|
348 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
|
349 self._anmrunner = None |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
68
diff
changeset
|
350 |
183
b6d7ce644f34
Implement two new ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
182
diff
changeset
|
351 if self._sprite and self._visible: |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
68
diff
changeset
|
352 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
|
353 self._sprite = None |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
68
diff
changeset
|
354 else: |
120
4300a832f033
Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents:
109
diff
changeset
|
355 self._sprite.update_orientation(self.angle, |
4300a832f033
Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents:
109
diff
changeset
|
356 self.automatic_orientation) |
36 | 357 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
79
diff
changeset
|
358 |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
79
diff
changeset
|
359 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
|
360 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
|
361 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
|
362 self.fire() |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
79
diff
changeset
|
363 |
202
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
364 # Check collisions |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
365 if self.touchable: |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
366 self.check_collisions() |
d348892ef012
Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents:
197
diff
changeset
|
367 |
242
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
368 for anm in self.aux_anm: |
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
369 if anm: |
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
370 anm.x = self.x |
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
371 anm.y = self.y |
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
372 anm.update() |
1d3c8c7473a2
Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
234
diff
changeset
|
373 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
374 self.frame += 1 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
375 |