comparison pytouhou/game/bullet.py @ 89:1513f5626656

Fix attack flags implementation
author Thibaut Girka <thib@sitedethib.com>
date Sun, 04 Sep 2011 09:36:51 +0200
parents 2cc60137d368
children 630e9045e851
comparison
equal deleted inserted replaced
88:2cc60137d368 89:1513f5626656
121 121
122 #TODO: flags 122 #TODO: flags
123 x, y = self.x, self.y 123 x, y = self.x, self.y
124 124
125 if self.flags & 16: 125 if self.flags & 16:
126 duration = self.attributes[0] 126 frame, count = self.attributes[0:2]
127 length, angle = self.attributes[4:6] 127 length, angle = self.attributes[4:6]
128 if self.frame < duration: 128 angle = self.angle if angle < -900.0 else angle #TODO: is that right?
129 angle = self.angle if angle < -900.0 else angle #TODO: is that right? 129 dx = cos(self.angle) * self.speed + cos(angle) * length
130 dx = cos(self.angle) * self.speed + cos(angle) * length 130 dy = sin(self.angle) * self.speed + sin(angle) * length
131 dy = sin(self.angle) * self.speed + sin(angle) * length 131 self.speed = (dx ** 2 + dy ** 2) ** 0.5
132 self.speed = (dx ** 2 + dy ** 2) ** 0.5 132 self.angle = atan2(dy, dx)
133 self.angle = atan2(dy, dx) 133 if self.frame == frame: #TODO: include last frame, or not?
134 if count > 0:
135 self.attributes[1] -= 1
136 self.frame = 0
137 else:
138 self.flags ^= 16
134 elif self.flags & 32: 139 elif self.flags & 32:
135 #TODO: count
136 #TODO: check 140 #TODO: check
137 duration, count = self.attributes[0:2] 141 frame, count = self.attributes[0:2]
138 acceleration, angular_speed = self.attributes[4:6] 142 acceleration, angular_speed = self.attributes[4:6]
139 if self.frame < duration: 143 self.speed += acceleration
140 self.speed += acceleration 144 self.angle += angular_speed
141 self.angle += angular_speed 145 if self.frame == frame:
146 if count > 0:
147 self.attributes[1] -= 1
148 else:
149 self.flags ^= 32
142 elif self.flags & 448: 150 elif self.flags & 448:
143 #TODO: check 151 #TODO: check
144 frame, count = self.attributes[0:2] 152 frame, count = self.attributes[0:2]
145 if count > 0: 153 angle, speed = self.attributes[4:6]
146 angle, speed = self.attributes[4:6] 154 if frame == self.frame:
147 if frame == self.frame: 155 count = count - 1
148 self._sprite._removed = True
149 count = count - 1
150 156
151 if self.flags & 64: 157 if self.flags & 64:
152 self.angle = self.angle + angle 158 self.angle = self.angle + angle
153 elif self.flags & 128: 159 elif self.flags & 128:
154 self.angle = self.get_player_angle() + angle 160 self.angle = self.get_player_angle() + angle
155 elif self.flags & 256: 161 elif self.flags & 256:
156 self.angle = angle 162 self.angle = angle
157 163
158 if count: 164 if count:
159 self.speed_interpolator.set_interpolation_start(self.frame, (speed,)) 165 self.speed_interpolator.set_interpolation_start(self.frame, (speed,))
160 self.speed_interpolator.set_interpolation_end(self.frame + frame - 1, (0,)) # TODO: really -1? Without, the new speed isn’t set. 166 self.speed_interpolator.set_interpolation_end(self.frame + frame - 1, (0,)) # TODO: really -1? Without, the new speed isn’t set.
161 else: 167 else:
162 self.speed = speed 168 self.flags &= ~448
169 self.speed = speed
163 170
164 self.attributes[1] = count 171 self.attributes[1] = count
165 #TODO: other flags 172 #TODO: other flags
166 173
167 if self.speed_interpolator: 174 if self.speed_interpolator:
168 self.speed_interpolator.update(self.frame) 175 self.speed_interpolator.update(self.frame)
169 self.speed, = self.speed_interpolator.values 176 self.speed, = self.speed_interpolator.values