Mercurial > touhou
annotate pytouhou/game/bullet.py @ 255:a0d6b1915591
Fix bullet removal condition.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 22 Jan 2012 19:47:40 +0100 |
parents | cb329dca4758 |
children | 507dfd6efe0c |
rev | line source |
---|---|
84 | 1 # -*- encoding: utf-8 -*- |
2 ## | |
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> | |
4 ## | |
5 ## This program is free software; you can redistribute it and/or modify | |
6 ## it under the terms of the GNU General Public License as published | |
7 ## by the Free Software Foundation; version 3 only. | |
8 ## | |
9 ## This program is distributed in the hope that it will be useful, | |
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 ## GNU General Public License for more details. | |
13 ## | |
14 | |
163
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
15 from math import cos, sin, atan2, pi |
84 | 16 |
86
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
17 from pytouhou.utils.interpolator import Interpolator |
84 | 18 from pytouhou.vm.anmrunner import ANMRunner |
19 from pytouhou.game.sprite import Sprite | |
20 | |
21 | |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
232
diff
changeset
|
22 |
84 | 23 class Bullet(object): |
123 | 24 def __init__(self, pos, bullet_type, sprite_idx_offset, |
232
8843e26f80c3
Hopefully implement “accelerating” bullets
Thibaut Girka <thib@sitedethib.com>
parents:
220
diff
changeset
|
25 angle, speed, attributes, flags, target, game, |
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:
163
diff
changeset
|
26 player_bullet=False, damage=0, hitbox=None): |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
149
diff
changeset
|
27 self._game = game |
84 | 28 self._sprite = None |
29 self._anmrunner = None | |
30 self._removed = False | |
31 self._launched = False | |
123 | 32 self._bullet_type = bullet_type |
255
a0d6b1915591
Fix bullet removal condition.
Thibaut Girka <thib@sitedethib.com>
parents:
246
diff
changeset
|
33 self._was_visible = True |
84 | 34 |
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:
163
diff
changeset
|
35 if hitbox: |
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:
163
diff
changeset
|
36 self.hitbox_half_size = (hitbox[0] / 2., hitbox[1] / 2.) |
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:
163
diff
changeset
|
37 else: |
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:
163
diff
changeset
|
38 self.hitbox_half_size = (bullet_type.hitbox_size / 2., bullet_type.hitbox_size / 2.) |
142
c7f0fd9d2145
Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents:
127
diff
changeset
|
39 |
86
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
40 self.speed_interpolator = None |
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
41 self.frame = 0 |
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
42 self.grazed = False |
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
43 |
232
8843e26f80c3
Hopefully implement “accelerating” bullets
Thibaut Girka <thib@sitedethib.com>
parents:
220
diff
changeset
|
44 self.target = target |
84 | 45 |
46 self.sprite_idx_offset = sprite_idx_offset | |
47 | |
48 self.flags = flags | |
49 self.attributes = list(attributes) | |
50 | |
51 self.x, self.y = pos | |
52 self.angle = angle | |
53 self.speed = speed | |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
54 dx, dy = cos(angle) * speed, sin(angle) * speed |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
55 self.delta = dx, dy |
84 | 56 |
163
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
57 self.player_bullet = player_bullet |
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:
163
diff
changeset
|
58 self.damage = damage |
163
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
59 |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
60 #TODO |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
61 if flags & 14: |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
62 if flags & 2: |
123 | 63 index = bullet_type.launch_anim2_index |
64 launch_mult = bullet_type.launch_anim_penalties[0] | |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
65 elif flags & 4: |
123 | 66 index = bullet_type.launch_anim4_index |
67 launch_mult = bullet_type.launch_anim_penalties[1] | |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
68 else: |
123 | 69 index = bullet_type.launch_anim8_index |
70 launch_mult = bullet_type.launch_anim_penalties[2] | |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
71 self.launch_delta = dx * launch_mult, dy * launch_mult |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
72 self._sprite = Sprite() |
123 | 73 self._anmrunner = ANMRunner(bullet_type.anm_wrapper, |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
74 index, self._sprite, |
123 | 75 bullet_type.launch_anim_offsets[sprite_idx_offset]) |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
76 self._anmrunner.run_frame() |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
77 else: |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
78 self.launch() |
88
2cc60137d368
Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
86
diff
changeset
|
79 |
163
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
80 if self.player_bullet: |
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
81 self._sprite.angle = angle - pi |
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
82 else: |
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
83 self._sprite.angle = angle |
86
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
84 |
84 | 85 |
86 def is_visible(self, screen_width, screen_height): | |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
87 tx, ty, tw, th = self._sprite.texcoords |
123 | 88 x, y = self.x, self.y |
84 | 89 |
90 max_x = tw / 2. | |
91 max_y = th / 2. | |
92 | |
123 | 93 if (max_x < x - screen_width |
94 or max_x < -x | |
95 or max_y < y - screen_height | |
96 or max_y < -y): | |
84 | 97 return False |
98 return True | |
99 | |
100 | |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
101 def set_anim(self, sprite_idx_offset=None): |
107
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
102 if sprite_idx_offset is not None: |
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
103 self.sprite_idx_offset = sprite_idx_offset |
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
104 |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
105 bt = self._bullet_type |
107
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
106 self._sprite = Sprite() |
163
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
107 if self.player_bullet: |
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
108 self._sprite.angle = self.angle - pi |
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
109 else: |
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
110 self._sprite.angle = self.angle |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
111 self._anmrunner = ANMRunner(bt.anm_wrapper, bt.anim_index, |
107
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
112 self._sprite, self.sprite_idx_offset) |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
113 self._anmrunner.run_frame() |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
114 |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
115 |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
116 def launch(self): |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
117 self._launched = True |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
118 self.set_anim() |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
119 if self.flags & 1: |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
120 self.speed_interpolator = Interpolator((self.speed + 5.,), 0, |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
121 (self.speed,), 16) |
246
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
122 self.update = self.update_speed |
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
123 else: |
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
124 self.update = self.update_full |
107
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
125 |
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
106
diff
changeset
|
126 |
156
ebfd328e700c
Rename a few functions, move a few things around...
Thibaut Girka <thib@sitedethib.com>
parents:
152
diff
changeset
|
127 def collide(self): |
161
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
128 self.cancel() |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
129 |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
130 |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
131 def cancel(self): |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
132 # Cancel animation |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
133 bt = self._bullet_type |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
134 self._sprite = Sprite() |
163
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
135 if self.player_bullet: |
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
136 self._sprite.angle = self.angle - pi |
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
137 else: |
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
138 self._sprite.angle = self.angle |
161
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
139 self._anmrunner = ANMRunner(bt.anm_wrapper, bt.cancel_anim_index, |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
140 self._sprite, bt.launch_anim_offsets[self.sprite_idx_offset]) |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
141 self._anmrunner.run_frame() |
163
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
142 self.delta = self.delta[0] / 2., self.delta[1] / 2. |
161
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
143 |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
144 # Change update method |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
145 self.update = self.update_cancel |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
146 |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
147 # Do not use this one for collisions anymore |
163
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
148 if self.player_bullet: |
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
149 self._game.players_bullets.remove(self) |
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
150 else: |
ee0bbde02c48
Implement player bullets in Bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
161
diff
changeset
|
151 self._game.bullets.remove(self) |
161
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
152 self._game.cancelled_bullets.append(self) |
152
86807b8a63bd
Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
151
diff
changeset
|
153 |
86807b8a63bd
Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
151
diff
changeset
|
154 |
84 | 155 def update(self): |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
156 dx, dy = self.launch_delta |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
157 self.x += dx |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
158 self.y += dy |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
159 |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
160 if not self._anmrunner.run_frame(): |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
161 self.launch() |
84 | 162 |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
163 |
161
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
164 def update_cancel(self): |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
165 dx, dy = self.delta |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
166 self.x += dx |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
167 self.y += dy |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
168 |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
169 if not self._anmrunner.run_frame(): |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
170 self._removed = True |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
171 |
7e7368356445
Add bullet cancel anim support
Thibaut Girka <thib@sitedethib.com>
parents:
158
diff
changeset
|
172 |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
173 def update_simple(self): |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
174 dx, dy = self.delta |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
175 self.x += dx |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
176 self.y += dy |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
177 |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
178 |
246
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
179 def update_speed(self): |
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
180 if self.speed_interpolator: |
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
181 self.speed_interpolator.update(self.frame) |
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
182 self.speed, = self.speed_interpolator.values |
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
183 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed |
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
184 self.x, self.y = self.x + dx, self.y + dy |
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
185 self.frame += 1 |
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
186 else: |
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
187 self.update = self.update_full |
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
188 self.update() |
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
189 |
cb329dca4758
Use the correct behaviour for flag 1 in bullet.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
236
diff
changeset
|
190 |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
191 def update_full(self): |
120
4300a832f033
Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents:
114
diff
changeset
|
192 sprite = self._sprite |
4300a832f033
Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents:
114
diff
changeset
|
193 |
4300a832f033
Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents:
114
diff
changeset
|
194 if self._anmrunner is not None and not self._anmrunner.run_frame(): |
4300a832f033
Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents:
114
diff
changeset
|
195 self._anmrunner = None |
84 | 196 |
197 #TODO: flags | |
198 x, y = self.x, self.y | |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
199 dx, dy = self.delta |
84 | 200 |
86
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
201 if self.flags & 16: |
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
202 length, angle = self.attributes[4:6] |
89
1513f5626656
Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents:
88
diff
changeset
|
203 angle = self.angle if angle < -900.0 else angle #TODO: is that right? |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
204 dx, dy = dx + cos(angle) * length, dy + sin(angle) * length |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
232
diff
changeset
|
205 self.speed = (dx ** 2 + dy ** 2) ** 0.5 |
145
30338dc33a7b
Fix bullet orientation in some cases (Meiling's last spellcard)
Thibaut Girka <thib@sitedethib.com>
parents:
142
diff
changeset
|
206 self.angle = sprite.angle = atan2(dy, dx) |
30338dc33a7b
Fix bullet orientation in some cases (Meiling's last spellcard)
Thibaut Girka <thib@sitedethib.com>
parents:
142
diff
changeset
|
207 if sprite.automatic_orientation: |
30338dc33a7b
Fix bullet orientation in some cases (Meiling's last spellcard)
Thibaut Girka <thib@sitedethib.com>
parents:
142
diff
changeset
|
208 sprite._changed = True |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
209 self.delta = dx, dy |
149
3673d55a8448
Fix bullet flags 16 and 32 handling
Thibaut Girka <thib@sitedethib.com>
parents:
145
diff
changeset
|
210 if self.frame == self.attributes[0]: #TODO: include last frame, or not? |
3673d55a8448
Fix bullet flags 16 and 32 handling
Thibaut Girka <thib@sitedethib.com>
parents:
145
diff
changeset
|
211 self.flags ^= 16 |
86
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
212 elif self.flags & 32: |
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
213 #TODO: check |
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
214 acceleration, angular_speed = self.attributes[4:6] |
89
1513f5626656
Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents:
88
diff
changeset
|
215 self.speed += acceleration |
1513f5626656
Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents:
88
diff
changeset
|
216 self.angle += angular_speed |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
217 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
218 self.delta = dx, dy |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
219 sprite.angle = self.angle |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
220 if sprite.automatic_orientation: |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
221 sprite._changed = True |
149
3673d55a8448
Fix bullet flags 16 and 32 handling
Thibaut Girka <thib@sitedethib.com>
parents:
145
diff
changeset
|
222 if self.frame == self.attributes[0]: |
3673d55a8448
Fix bullet flags 16 and 32 handling
Thibaut Girka <thib@sitedethib.com>
parents:
145
diff
changeset
|
223 self.flags ^= 32 |
88
2cc60137d368
Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
86
diff
changeset
|
224 elif self.flags & 448: |
2cc60137d368
Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
86
diff
changeset
|
225 #TODO: check |
2cc60137d368
Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
86
diff
changeset
|
226 frame, count = self.attributes[0:2] |
89
1513f5626656
Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents:
88
diff
changeset
|
227 angle, speed = self.attributes[4:6] |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
228 if self.frame % frame == 0: |
89
1513f5626656
Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents:
88
diff
changeset
|
229 count = count - 1 |
88
2cc60137d368
Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
86
diff
changeset
|
230 |
124
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
231 if self.frame != 0: |
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
232 self.speed = speed |
88
2cc60137d368
Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
86
diff
changeset
|
233 |
124
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
234 if self.flags & 64: |
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
235 self.angle += angle |
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
236 elif self.flags & 128: |
232
8843e26f80c3
Hopefully implement “accelerating” bullets
Thibaut Girka <thib@sitedethib.com>
parents:
220
diff
changeset
|
237 self.angle = atan2(self.target.y - y, self.target.x - x) + angle |
124
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
238 elif self.flags & 256: |
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
239 self.angle = angle |
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
240 |
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
241 dx, dy = cos(self.angle) * speed, sin(self.angle) * speed |
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
242 self.delta = dx, dy |
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
243 sprite.angle = self.angle |
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
244 if sprite.automatic_orientation: |
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
245 sprite._changed = True |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
246 |
127 | 247 if count >= 0: |
124
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
248 self.speed_interpolator = Interpolator((self.speed,), self.frame, |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
249 (0.,), self.frame + frame - 1) |
89
1513f5626656
Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents:
88
diff
changeset
|
250 else: |
1513f5626656
Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents:
88
diff
changeset
|
251 self.flags &= ~448 |
88
2cc60137d368
Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
86
diff
changeset
|
252 |
89
1513f5626656
Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents:
88
diff
changeset
|
253 self.attributes[1] = count |
86
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
254 #TODO: other flags |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
255 elif not self.speed_interpolator and self._anmrunner is None: |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
256 self.update = self.update_simple |
86
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
257 |
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
258 if self.speed_interpolator: |
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
259 self.speed_interpolator.update(self.frame) |
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
260 self.speed, = self.speed_interpolator.values |
124
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
261 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed |
f06e96dbed4e
Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
262 self.delta = dx, dy |
86
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
263 |
84 | 264 self.x, self.y = x + dx, y + dy |
265 | |
86
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
266 self.frame += 1 |
a87a3c080585
Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents:
85
diff
changeset
|
267 |