def generate(self, space_game, ship): # def create_enemy_star(self): self.enemies = [] self.x = randint(100, CANVAS_WIDTH - 100) self.y = randint(100, CANVAS_HEIGHT - 100) while vector_len(self.x - self.ship.x, self.y - self.ship.y) < 200: self.x = randint(100, CANVAS_WIDTH - 100) self.y = randint(100, CANVAS_HEIGHT - 100) for d in range(18): self.dx, self.dy = direction_to_dxdy(d * 20) self.enemy = Enemy(self, self.x, self.y, self.dx * ENEMY_BASE_SPEED, self.dy * ENEMY_BASE_SPEED) self.enemies.append(self.enemy) return self.enemies # def create_enemy_from_edges(self): self.x, self.y = random_edge_position() self.vx, self.vy = normalize_vector(self.ship.x - self.x, self.ship.y - self.y) self.vx *= ENEMY_BASE_SPEED self.vy *= ENEMY_BASE_SPEED self.enemy = Enemy(self, self.x, self.y, self.vx, self.vy) return [self.enemy]
def fire(self): if self.app.bullet_count() >= MAX_NUM_BULLETS: return dx, dy = direction_to_dxdy(-self.angle) bullet0 = TieBullet(self.app, self.x, self.y, dx * BULLET_BASE_SPEED, dy * BULLET_BASE_SPEED) self.app.add_enemy(bullet0)
def fire(self): if self.app.bullet_count() >= MAX_NUM_BULLETS: return dx, dy = direction_to_dxdy(self.direction) bullet = Bullet(self.app, self.x, self.y, dx * BULLET_BASE_SPEED, dy * BULLET_BASE_SPEED) self.app.add_bullet(bullet)
def update(self): dx, dy = direction_to_dxdy(self.direction) self.x += dx * SHIP_SPEED self.y += dy * SHIP_SPEED if self.is_turning_left: self.turn_left() elif self.is_turning_right: self.turn_right()
def generate(self, space_game, ship): enemies = [] x = randint(100, CANVAS_WIDTH - 100) y = randint(100, CANVAS_HEIGHT - 100) while vector_len(x - ship.x, y - ship.y) < 200: x = randint(100, CANVAS_WIDTH - 100) y = randint(100, CANVAS_HEIGHT - 100) for d in range(18): dx, dy = direction_to_dxdy(d * 20) enemy = Enemy(space_game, x, y, dx * ENEMY_BASE_SPEED, dy * ENEMY_BASE_SPEED) enemies.append(enemy) return enemies
def create_enemy_star(self): enemies = [] x = randint(100, CANVAS_WIDTH - 100) y = randint(100, CANVAS_HEIGHT - 100) while vector_len(x - self.ship.x, y - self.ship.y) < 200: x = randint(100, CANVAS_WIDTH - 100) y = randint(100, CANVAS_HEIGHT - 100) for d in range(18): dx, dy = direction_to_dxdy(d * 20) enemy = Enemy(self, x, y, dx * ENEMY_BASE_SPEED, dy * ENEMY_BASE_SPEED) enemies.append(enemy) return enemies
def generate(self, space_game, ship): self.enemies = [] self.x = randint(100, CANVAS_WIDTH - 100) self.y = randint(100, CANVAS_HEIGHT - 100) while vector_len(self.x - self.ship.x, self.y - self.ship.y) < 200: self.x = randint(100, CANVAS_WIDTH - 100) self.y = randint(100, CANVAS_HEIGHT - 100) for d in range(18): self.dx, self.dy = direction_to_dxdy(d * 20) self.enemy = Enemy(self, self.x, self.y, self.dx * ENEMY_BASE_SPEED, self.dy * ENEMY_BASE_SPEED) self.enemies.append(self.enemy) return self.enemies
def generate(self, space_game, ship): ## ## # TODO: extracted from method create_enemy_star self.ship = ship enemies = [] x = randint(100, CANVAS_WIDTH - 100) y = randint(100, CANVAS_HEIGHT - 100) while vector_len(x - self.ship.x, y - self.ship.y) < 200: x = randint(100, CANVAS_WIDTH - 100) y = randint(100, CANVAS_HEIGHT - 100) for d in range(18): dx, dy = direction_to_dxdy(d * 20) enemy = Enemy(self.ship, x, y, dx * ENEMY_BASE_SPEED, dy * ENEMY_BASE_SPEED) enemies.append(enemy) return enemies
def turbo_start(self): dx, dy = direction_to_dxdy(self.direction) self.x += dx * 2 * SHIP_SPEED self.y += dy * 2 * SHIP_SPEED