comparison pytouhou/game/bullet.py @ 88:2cc60137d368

Ugly implementation of three new attack flags.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 03 Sep 2011 17:44:48 -0700
parents a87a3c080585
children 1513f5626656
comparison
equal deleted inserted replaced
87:fda176f07d6d 88:2cc60137d368
59 59
60 if flags & 1: 60 if flags & 1:
61 self.speed_interpolator = Interpolator((speed + 5.,)) 61 self.speed_interpolator = Interpolator((speed + 5.,))
62 self.speed_interpolator.set_interpolation_start(0, (speed + 5.,)) 62 self.speed_interpolator.set_interpolation_start(0, (speed + 5.,))
63 self.speed_interpolator.set_interpolation_end(16, (speed,)) 63 self.speed_interpolator.set_interpolation_end(16, (speed,))
64 if flags & 448:
65 self.speed_interpolator = Interpolator((speed,))
66 self.speed_interpolator.set_interpolation_start(0, (speed,))
67 self.speed_interpolator.set_interpolation_end(attributes[0] - 1, (0,)) # TODO: really -1? Without, the new speed isn’t set.
68
69
70 def get_player_angle(self):
71 return atan2(self.player.y - self.y, self.player.x - self.x)
64 72
65 73
66 def is_visible(self, screen_width, screen_height): 74 def is_visible(self, screen_width, screen_height):
67 if self._sprite: 75 if self._sprite:
68 tx, ty, tw, th = self._sprite.texcoords 76 tx, ty, tw, th = self._sprite.texcoords
113 121
114 #TODO: flags 122 #TODO: flags
115 x, y = self.x, self.y 123 x, y = self.x, self.y
116 124
117 if self.flags & 16: 125 if self.flags & 16:
118 #TODO: duration, count 126 duration = self.attributes[0]
119 length, angle = self.attributes[4:6] 127 length, angle = self.attributes[4:6]
120 angle = self.angle if angle < -900.0 else angle #TODO: is that right? 128 if self.frame < duration:
121 dx = cos(self.angle) * self.speed + cos(angle) * length 129 angle = self.angle if angle < -900.0 else angle #TODO: is that right?
122 dy = sin(self.angle) * self.speed + sin(angle) * length 130 dx = cos(self.angle) * self.speed + cos(angle) * length
123 self.speed = (dx ** 2 + dy ** 2) ** 0.5 131 dy = sin(self.angle) * self.speed + sin(angle) * length
124 self.angle = atan2(dy, dx) 132 self.speed = (dx ** 2 + dy ** 2) ** 0.5
133 self.angle = atan2(dy, dx)
125 elif self.flags & 32: 134 elif self.flags & 32:
126 #TODO: duration, count 135 #TODO: count
127 #TODO: check 136 #TODO: check
137 duration, count = self.attributes[0:2]
128 acceleration, angular_speed = self.attributes[4:6] 138 acceleration, angular_speed = self.attributes[4:6]
129 self.speed += acceleration 139 if self.frame < duration:
130 self.angle += angular_speed 140 self.speed += acceleration
141 self.angle += angular_speed
142 elif self.flags & 448:
143 #TODO: check
144 frame, count = self.attributes[0:2]
145 if count > 0:
146 angle, speed = self.attributes[4:6]
147 if frame == self.frame:
148 self._sprite._removed = True
149 count = count - 1
150
151 if self.flags & 64:
152 self.angle = self.angle + angle
153 elif self.flags & 128:
154 self.angle = self.get_player_angle() + angle
155 elif self.flags & 256:
156 self.angle = angle
157
158 if count:
159 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.
161 else:
162 self.speed = speed
163
164 self.attributes[1] = count
131 #TODO: other flags 165 #TODO: other flags
132 166
133 if self.speed_interpolator: 167 if self.speed_interpolator:
134 self.speed_interpolator.update(self.frame) 168 self.speed_interpolator.update(self.frame)
135 self.speed, = self.speed_interpolator.values 169 self.speed, = self.speed_interpolator.values