def generate_bullets_auto(x, y, target, gamma): pos_0 = (x + 96 * cos(gamma + 0.25*pi), y - 96 * sin(gamma + 0.25*pi)) pos_1 = (x + 96 * cos(gamma - 0.25*pi), y - 96 * sin(gamma - 0.25*pi)) angle_0 = calculate_angle(*pos_0, *target) angle_1 = calculate_angle(*pos_1, *target) return [RegularBullet(*pos_0, -1, 1.5, angle_0, Body(SMALL_BUL_BODY_1)), RegularBullet(*pos_1, -1, 1.5, angle_1, Body(SMALL_BUL_BODY_1))]
def generate_bullets(self, x, y, target, gamma): xo, yo = x + 90 * cos(gamma + 0.75*pi), y - 90 * sin(gamma + 0.75*pi) angle_0 = calculate_angle(xo, yo, *target) pos_0 = (xo + 40 * cos(angle_0), yo - 40 * sin(angle_0)) xo, yo = x + 90 * cos(gamma - 0.75*pi), y - 90 * sin(gamma - 0.75*pi) angle_1 = calculate_angle(xo, yo, *target) pos_1 = (xo + 40 * cos(angle_1), yo - 40 * sin(angle_1)) return [RegularBullet(*pos_0, self.bul_dmg, self.bul_vel, angle_0, Body(self.bul_body)), RegularBullet(*pos_1, self.bul_dmg, self.bul_vel, angle_1, Body(self.bul_body))]
def append_bullet(self, x, y, bullets, target): angle = calculate_angle(x, y, *target) xo = x + 23 * cos(angle) yo = y - 23 * sin(angle) bullets.append( RegularBullet(xo, yo, self.bul_dmg, self.bul_vel, angle, Body(self.bul_body)))
def transport_player(self, direction): self.transportation = True self.level_generator.update(self.room.encode_mobs(self.room.mobs), direction, self.player.state[0], self.player.health) self.level_generator.setup_game_map(self.gui.pause_menu.map_window.game_map) self.level_generator.setup_room(self.room) offset, destination = self.get_offset_and_destination(direction) self.room.move_objects(offset) self.player.move(*offset) self.camera.stop_shaking() self.camera.update(*self.player.pos, 0) distance = hypot(*(self.player.pos - destination)) player_vel = distance / c.TRANSPORTATION_TIME alpha = calculate_angle(*self.player.pos, *destination) self.player.set_transportation_vel(alpha, player_vel) self.player.clear_bullets() self.background.set_trail_pos(*self.player.pos, distance, alpha) self.background.set_destination_circle_pos(destination) self.run_transportation(*offset) self.room.reset() self.player.stop() self.clock.tick() self.transportation = False
def generate_bullets(self, x, y, target, gamma): angle = calculate_angle(x, y, *target) xo, yo = self.get_reference_point(x, y, angle) return [ EllipticBullet(xo, yo, self.bul_dmg, self.bul_vel, angle, self.bul_body) ]
def generate_bullets(self, x, y, target, gamma): angle = calculate_angle(x, y, *target) pos_0 = (x + 20 * cos(angle + 0.74*pi), y - 20 * sin(angle + 0.74*pi)) pos_1 = (x + 20 * cos(angle - 0.74*pi), y - 20 * sin(angle - 0.74*pi)) return [(RegularBullet(*pos_0, self.bul_dmg, self.bul_vel, angle, Body(self.bul_body))), (RegularBullet(*pos_1, self.bul_dmg, self.bul_vel, angle, Body(self.bul_body)))]
def activate(self, x, y, gamma, target, bullets): self.time -= self.cooldown_time xo, yo = x + 80 * cos(gamma), y - 80 * sin(gamma) angle = calculate_angle(xo, yo, *target) pos = (xo + 34 * cos(angle), yo - 34 * sin(angle)) bullets.append( b.RegularBullet(*pos, 0, 0.7, angle, Body(STICKY_BUL_BODY)))
def get_missiles_coords(pos, health, beta): beta = calculate_angle(c.SCR_W2, c.SCR_H2, *pg.mouse.get_pos()) pos_0 = pos + np.array( [65 * cos(beta + 0.43 * pi), -65 * sin(beta + 0.43 * pi)]) pos_1 = pos + np.array( [65 * cos(beta - 0.43 * pi), -65 * sin(beta - 0.43 * pi)]) return pos_0, pos_1
def append_small_bullet(self, x, y, bullets, target, gamma): xo, yo = x + 30 * cos(gamma), y - 30 * sin(gamma) angle = calculate_angle(xo, yo, *target) xo, yo = xo + 23 * cos(angle), yo - 23 * sin(angle) bullets.append( RegularBullet(xo, yo, self.bul_dmg, self.bul_vel, angle, Body(self.bul_body)))
def get_missiles_coords(pos, health, beta): beta = calculate_angle(c.SCR_W2, c.SCR_H2, *pg.mouse.get_pos()) pos_0 = pos + np.array( [66 * cos(beta + 0.88 * pi), -66 * sin(beta + 0.88 * pi)]) pos_1 = pos + np.array( [66 * cos(beta - 0.88 * pi), -66 * sin(beta - 0.88 * pi)]) pos_2 = pos + np.array([63 * cos(beta), -63 * sin(beta)]) return [pos_0, pos_1, pos_2]
def update_body(self, body): beta = calculate_angle(c.SCR_W2, c.SCR_H2, *pg.mouse.get_pos()) for i in range(1, len(body.circles) - 6): body.circles[i].dx = self.offsets[i - 1][0] * self.dist * cos( beta + self.offsets[i - 1][1]) body.circles[i].dy = -self.offsets[i - 1][0] * self.dist * sin( beta + self.offsets[i - 1][1])
def append_bullet_2(self, x, y, bullets, target, gamma): pos = [x - 35 * cos(gamma), y + 35 * sin(gamma)] angle = calculate_angle(*pos, *target) pos[0] += 35 * cos(angle) pos[1] -= 35 * sin(angle) bullets.append( RegularBullet(*pos, self.bul_dmg, self.bul_vel, angle, Body(self.bul_body)))
def generate_bullets(self, x, y, target, gamma): angle = calculate_angle(x, y, *target) coords = self.get_reference_point(x, y, angle) return [ RegularBullet(*coords, self.bul_dmg, self.bul_vel, angle, Body(self.bul_body)) ]
def append_big_bullet(x, y, bullets, gamma, target): x = x - 70 * cos(gamma) y = y + 70 * sin(gamma) angle = calculate_angle(x, y, *target) x += 44 * cos(angle) y -= 44 * sin(angle) bullets.append( RegularBullet(x, y, -15, 0.55, angle, Body(BIG_BUL_BODY_2)))
def append_small_bullet(x, y, bullets, gamma, target): x = x + 12 * cos(gamma) y = y - 12 * sin(gamma) angle = calculate_angle(x, y, *target) x += 24 * cos(angle) y -= 24 * sin(angle) bullets.append( RegularBullet(x, y, -2, 0.55, angle, Body(SMALL_BUL_BODY_2)))
def generate_bullets(self, x, y, target, gamma): angle = calculate_angle(x, y, *target) xo, yo = self.get_reference_point(x, y, angle) pos_0 = xo + 6 * sin(angle), yo + 6 * cos(angle) pos_1 = xo - 6 * sin(angle), yo - 6 * cos(angle) return [RegularBullet(*pos_0, self.bul_dmg, self.bul_vel, angle, Body(self.bul_body)), RegularBullet(*pos_1, self.bul_dmg, self.bul_vel, angle, Body(self.bul_body))]
def set_vel(self, target_x, target_y): """ Method is called when a target intersected with bullet's searching area. Sets x- and y- velocity components according to target position. """ angle = calculate_angle(self.x, self.y, target_x, target_y) self.vel_x = self.vel * cos(angle) self.vel_y = -self.vel * sin(angle)
def generate_bullets(self, x, y, target, gamma): xo, yo = x, y + 210 angle = calculate_angle(xo, yo, *target) coords = (xo + self.radius * cos(angle), yo - self.radius * sin(angle)) return [ RegularBullet(*coords, self.bul_dmg, self.bul_vel, angle, Body(self.bul_body)) ]
def generate_bullets(self, x, y, target, gamma): angle = calculate_angle(x, y, *target) xo, yo = self.get_reference_point(x, y, angle) pos_0 = (xo, yo) pos_1 = (xo + 15 * sin(angle - 0.17*pi), yo + 15 * cos(angle - 0.17*pi)) pos_2 = (xo - 15 * sin(angle + 0.17*pi), yo - 15 * cos(angle + 0.17*pi)) return [RegularBullet(*pos_0, self.bul_dmg, self.bul_vel, angle, Body(self.bul_body)), RegularBullet(*pos_1, self.bul_dmg, self.bul_vel, angle - 0.17 * pi, Body(self.bul_body)), RegularBullet(*pos_2, self.bul_dmg, self.bul_vel, angle + 0.17 * pi, Body(self.bul_body))]
def generate_bullets(self, x, y, target, gamma): angle = calculate_angle(x, y, *target) xo, yo = self.get_reference_point(x, y, angle) pos_0 = (xo, yo) pos_1 = (xo + 53 * cos(angle + 0.48*pi), yo - 53 * sin(angle + 0.48*pi)) pos_2 = (xo + 53 * cos(angle - 0.48*pi), yo - 53 * sin(angle - 0.48*pi)) return [(RegularBullet(*pos_0, -5, 0.75, angle, Body(BIG_BUL_BODY_1))), (RegularBullet(*pos_1, -1, 0.1, angle, Body(SMALL_BUL_BODY_1))), (RegularBullet(*pos_2, -1, 0.1, angle, Body(SMALL_BUL_BODY_1)))]
def generate_bullets(self, x, y, target, gamma): angle = calculate_angle(x, y, *target) xo, yo = self.get_reference_point(x, y, angle) angles = self.get_bullets_angles(angle) coords = self.get_bullets_coords(xo, yo, angles) bullets = [] for i in range(5): bullets.append(RegularBullet(*coords[i], self.bul_dmg, self.bul_vel, angles[i], Body(self.bul_body))) return bullets
def generate_bullets(self, x, y, target, gamma): angle = calculate_angle(x, y, *target) xo, yo = self.get_reference_point(x, y, angle) sina, cosa = sin(angle), cos(angle) coords = [(xo, yo), (xo + 14*sina, yo + 14*cosa), (xo - 14*sina, yo - 14*cosa), (xo + 28*sina - 4*cosa, yo + 28*cosa + 4*sina), (xo - 28*sina - 4*cosa, yo - 28*cosa + 4*sina)] bullets = [] for pos in coords: bullets.append(RegularBullet(*pos, self.bul_dmg, self.bul_vel, angle, Body(self.bul_body))) return bullets
def go_to_player(self, x, y, dt): self.alpha = calculate_angle(self.x, self.y, x, y) dr = self.vel * dt + self.acc * dt * dt / 2 dist = hypot(self.x - x, self.y - y) if dr > dist: self.x = x self.y = y else: self.x += dr * cos(self.alpha) self.y -= dr * sin(self.alpha) self.vel += self.acc * dt if self.vel >= self.max_vel: self.vel = self.max_vel self.acc = 0
def update_pos(self, x, y, target, beta, gamma): angle = self.alpha + gamma self.x = x + self.dist * cos(angle) + self.dx self.y = y - self.dist * sin(angle) + self.dy if self.adjusts_to_target: if self.dist: beta = calculate_angle(self.x, self.y, target[0], target[1]) angle = self.adj_alpha + beta if self.adj_dist: self.adj_x = self.adj_dist * cos(angle) self.adj_y = -self.adj_dist * sin(angle) self.x += self.adj_x self.y += self.adj_y if self.radius >= 8: self.update_glares(angle)
def count_gamma(self): dt = 0.01 if self.w > 0 else -0.01 x, y = self.trajectory(self.time + dt) return calculate_angle(self.x, self.y, x, y)
def get_bullet_pos(pos): mouse_pos = pg.mouse.get_pos() alpha = calculate_angle(c.SCR_W2, c.SCR_H2, *mouse_pos) return pos + np.array([-64 * cos(alpha), 64 * sin(alpha)])
def get_explosion_pos(pos): mouse_pos = pg.mouse.get_pos() alpha = calculate_angle(c.SCR_W2, c.SCR_H2, *mouse_pos) return pos + np.array([-49 * cos(alpha), 49 * sin(alpha)])
def activate(self, pos, bullets): self.time = 0 beta = calculate_angle(c.SCR_W2, c.SCR_H2, *pg.mouse.get_pos()) coords = pos + np.array([51 * cos(beta), -51 * sin(beta)]) bullets.append(b.FrangibleBullet(*coords, beta, Body(BIG_BUL_BODY_1)))
def activate(self, x, y, target, bullets): self.time -= self.cooldown_time angle = calculate_angle(x, y, *target) pos = (x + 120 * cos(angle), y - 120 * sin(angle)) bullets.append(b.ExplodingBullet(*pos, angle))
def update(self, dt, target_x=0, target_y=0): angle = calculate_angle(self.x, self.y, target_x, target_y) self.update_vel(angle) self.update_pos(dt) self.body.update(self.x, self.y, dt, [target_x, target_y])