def shoot(self): if ml.time() - self.firing_timer >= ( 1 / ml.get_upgrade_values('Attack Speed')): shot_angles = ml.multi_shot_angles( ml.get_upgrade_values('Multi Shot'), 90, 10) for i in range(ml.get_upgrade_values('Multi Shot')): PlayerBullet(self.rect.centerx, self.rect.y, ml.get_upgrade_values('Bullet Speed'), ml.get_upgrade_values('Damage'), shot_angles[i], self.homing_shots_active) self.firing_timer = ml.time()
def shoot(timer, bullet_data, firing_data, burst_counter=0): # TODO clean up shoot() documentation """ All-encompassing method for shooting. Mix and match arguments to achieve desired patterns. -- timer should be a time from ml.time(). -- firing_speed limits the rate. If the shoot is successful, returns the current ml.time() to reset the timer, otherwise returns the original timer. -- interval is the angular gap between multi-shot bullets. -- angle determines the angle that the bullet is first fired at. If not defined, firing angle will be random from 0 to 360. If defined, aim will override angle. -- random_arc modifies the angle of the shot by random.uniform(-random_arc, random_arc). -- burst, if greater than 0, sets method to burst mode. It will shoot a number of times equal to burst with burst_delay time between each shot. In burst mode, firing_speed acts as the delay, in seconds, between bursts, rather than the number of attacks per second. burst_counter keeps track of how far through the burst it has gotten. In burst mode, method will return 2 values. The first will be a ml.time(). If the burst has completed, it will return a new ml.time(), otherwise it will return the original timer. The second value will be the incremented counter, or 0 if the burst has finished. The new burst counter should be passed back in the next time the method is called. See enemybullet.BulletData for further documentation. Usage: self.timer = self.omni_shot(args) Burst mode: self.timer, self.burst_counter = self.omni_shot(args) """ parent = bullet_data.parent firing_speed = firing_data.firing_speed interval = firing_data.interval aim = firing_data.aim multi = firing_data.multi random_arc = firing_data.random_arc burst = firing_data.burst burst_delay = firing_data.burst_delay counter = burst_counter angle = firing_data.angle if burst: if aim: shot_angle = ml.angle_to_point(parent.rect.center, ml.player.rect.center) elif angle is None: shot_angle = random.uniform(0, 360) else: shot_angle = angle if counter < burst and ml.time() - timer >= burst_delay: shot_angles = ml.multi_shot_angles(multi, shot_angle, interval) for arc_shot in range(multi): EnemyBullet(bullet_data, angle=shot_angles[arc_shot] + random.uniform(-random_arc, random_arc)) return ml.time(), counter + 1 else: # Reset counter if ml.time() - timer >= firing_speed: counter = 0 return timer, counter elif ml.time() - timer >= (1 / firing_speed): if aim: shot_angle = ml.angle_to_point(parent.rect.center, ml.player.rect.center) elif angle is None: shot_angle = random.uniform(0, 360) else: shot_angle = angle shot_angles = ml.multi_shot_angles(multi, shot_angle, interval) for arc_shot in range(multi): EnemyBullet( bullet_data, angle=shot_angles[arc_shot] + random.uniform(-random_arc, random_arc), ) return ml.time() return timer