Example #1
0
class EMGeneratorBuilding(Building):
    def __init__(self):
        Building.__init__(self)
        self.load_shapes("weapon")
        self.stunned_ships = {}
        self.indicator = None

    def update(self, planet, dt):
        if not self.indicator:
            self.indicator = RangeIndicator(planet.pos,
                                            planet.DEFENSE_RANGE +
                                            planet.get_radius(),
                                            PICO_PINK,
                                            line_length=2,
                                            line_space=5)
            planet.scene.game_group.add(self.indicator)
            planet.selected_graphics.append(self.indicator)
        threats = planet.get_threats()
        for ship in threats:
            if ship not in self.stunned_ships:
                ship.set_state("stunned")
                self.stunned_ships[ship] = True

    def kill(self):
        if self.indicator:
            self.indicator.kill()
        Building.kill(self)
Example #2
0
class ScalingDamageAuraBuilding(AuraBuilding):
    def __init__(self):
        super().__init__()
        self.targeting = "mine"
        self.indicator = None
        self.load_shapes("lab")

    def update(self, planet, dt):
        if not self.indicator:
            self.indicator = RangeIndicator(planet.pos,
                                            self.aura_radius,
                                            PICO_BLUE,
                                            line_length=2,
                                            line_space=5)
            planet.scene.game_group.add(self.indicator)
            planet.selected_graphics.append(self.indicator)
        self.aura_radius = max(
            305 - len(planet.scene.get_civ_planets(planet.owning_civ)) * 55,
            80)
        if self.aura_radius != self.indicator.radius:
            self.indicator.radius = self.aura_radius
            self.indicator._generate_image()
        return super().update(planet, dt)

    def apply(self, ship, planet):
        ship.add_effect(status_effect.DamageBoostEffect(ship, planet))

    def unapply(self, ship, planet):
        ship.remove_all_effects_by_name("damage_boost")
Example #3
0
class Alien3Void(SpaceObject):
    def __init__(self, scene, attached, radius, color=PICO_BLACK):
        super().__init__(scene, attached.pos)
        self.attached = attached
        self.radius = radius
        self._layer = -1
        self.color = color
        self._generate_image()
        self.offset = (0.5, 0.5)
        self.target_radius = self.radius
        self.ring = RangeIndicator(self.pos, self.radius + 1.5, self.color, 2,
                                   5)
        self.ring._layer = -2
        self.scene.game_group.add(self.ring)

    def _generate_image(self):
        r = int(self.radius)
        self._width = r * 2
        self._height = r * 2
        self.image = pygame.Surface((self._width, self._height),
                                    pygame.SRCALPHA)
        pygame.draw.circle(self.image, PICO_BLACK, (r, r), r, 0)
        num = r
        #for i in range(num):
        #    theta = i / (num-1) * 6.2818
        #    p = helper.from_angle(theta) * r
        #    self.image.set_at((p + V2(r, r)), PICO_LIGHTGRAY)

        self._recalc_rect()

    def grow(self):
        if self.radius < 50:
            self.target_radius = self.radius + 10
        elif self.radius < 80:
            self.target_radius = self.radius + 5

    def update(self, dt):
        self.pos = self.attached.pos
        self.ring.pos = self.attached.pos
        if self.radius < self.target_radius:
            self.radius += 1 * dt
            self._generate_image()
            self.ring.radius = self.radius + 1.5
            self.ring._generate_image()

        if random.random() > 0.93:
            pos = helper.random_angle() * random.random(
            ) * self.radius + self.pos
            p = Particle([PICO_LIGHTGRAY, PICO_DARKGRAY], 1, pos, 0.25,
                         helper.random_angle() * 3)
            p._layer = -1
            self.scene.game_group.add(p)

        return super().update(dt)

    def kill(self):
        self.ring.kill()
        return super().kill()
Example #4
0
 def __init__(self, scene, attached, radius, color=PICO_BLACK):
     super().__init__(scene, attached.pos)
     self.attached = attached
     self.radius = radius
     self._layer = -1
     self.color = color
     self._generate_image()
     self.offset = (0.5, 0.5)
     self.target_radius = self.radius
     self.ring = RangeIndicator(self.pos, self.radius + 1.5, self.color, 2,
                                5)
     self.ring._layer = -2
     self.scene.game_group.add(self.ring)
Example #5
0
 def update(self, planet, dt):
     if not self.indicator:
         self.indicator = RangeIndicator(planet.pos,
                                         planet.DEFENSE_RANGE +
                                         planet.get_radius(),
                                         PICO_PINK,
                                         line_length=2,
                                         line_space=5)
         planet.scene.game_group.add(self.indicator)
         planet.selected_graphics.append(self.indicator)
     threats = planet.get_threats()
     for ship in threats:
         if ship not in self.stunned_ships:
             ship.set_state("stunned")
             self.stunned_ships[ship] = True
Example #6
0
 def update(self, planet, dt):
     if not self.indicator:
         self.indicator = RangeIndicator(planet.pos,
                                         self.aura_radius,
                                         PICO_BLUE,
                                         line_length=2,
                                         line_space=5)
         planet.scene.game_group.add(self.indicator)
         planet.selected_graphics.append(self.indicator)
     self.aura_radius = max(
         305 - len(planet.scene.get_civ_planets(planet.owning_civ)) * 55,
         80)
     if self.aura_radius != self.indicator.radius:
         self.indicator.radius = self.aura_radius
         self.indicator._generate_image()
     return super().update(planet, dt)
Example #7
0
 def update(self, planet, dt):
     if not self.indicator:
         self.indicator = RangeIndicator(planet.pos,
                                         planet.DEFENSE_RANGE +
                                         planet.get_radius(),
                                         PICO_PINK,
                                         line_length=2,
                                         line_space=5)
         planet.scene.game_group.add(self.indicator)
         planet.selected_graphics.append(self.indicator)
     self.fire_time += dt
     threats = planet.get_threats()
     if self.fire_time > self.FIRE_RATE and threats:
         t = random.choice(threats)
         delta = t.pos - planet.pos
         _, angle = delta.as_polar()
         angle *= 3.14159 / 180
         angle += random.random() * 1.5 - 0.75
         self.fire_time = 0
         b = bullet.Bullet(planet.pos +
                           helper.from_angle(angle) * planet.get_radius(),
                           t,
                           planet,
                           vel=helper.from_angle(angle) * 20,
                           mods={
                               'homing': 1,
                               "damage_base": 10 * planet.planet_weapon_mul,
                               "blast_radius": 10,
                               "color": PICO_WHITE,
                               "life": 5,
                               "missile_speed": 0.5
                           })
         planet.scene.game_group.add(b)
Example #8
0
 def update(self, planet, dt):
     if not self.indicator:
         self.indicator = RangeIndicator(planet.pos,
                                         self.aura_radius,
                                         PICO_BLUE,
                                         line_length=2,
                                         line_space=5)
         planet.scene.game_group.add(self.indicator)
         planet.selected_graphics.append(self.indicator)
     return super().update(planet, dt)
Example #9
0
    def update_fleet_markers(self, point):
        for m in self.fleet_markers:
            m.kill()

        self.fleet_markers = []
        for fleet in self.current_fleets:
            if (point - fleet.pos).length_squared() < (fleet.radius + 5) ** 2:
                m = RangeIndicator(fleet.pos, fleet.radius + 3, PICO_DARKGREEN, 2, 2)
                self.scene.ui_group.add(m)
                self.fleet_markers.append(m)
Example #10
0
    def setup_cursor_type(self, cursor):
        if self.joystick_overlay:
            self.joystick_overlay.kill()
            self.joystick_overlay = joystickcursor.JoystickCursor(self.scene, self.scene.game.last_joystick_pos[0])
            self.scene.ui_group.add(self.joystick_overlay)
            self.joystick_overlay.set_button_options(["[*x*] Select"])

        res = self.scene.game.game_resolution

        if self.panel:
            self.panel.kill()
        if cursor == "allied_planet":
            self.cursor_icon = SimpleSprite(V2(0,0), "assets/i-planet-cursor.png")
            self.hover_filter = self.filter_my_planets
            self.selection_info_text = text.Text("Select one of your Planets to apply upgrade", "big", V2(res.x / 2, res.y / 2), PICO_WHITE, multiline_width=180,shadow=PICO_BLACK, flash_color=PICO_YELLOW)
        elif cursor == "any_planet":
            self.cursor_icon = SimpleSprite(V2(0,0), "assets/i-planet-cursor.png")
            self.hover_filter = self.filter_any_planets
            self.selection_info_text = text.Text("Select any Planet to apply upgrade", "big", V2(res.x / 2, res.y / 2), PICO_WHITE, multiline_width=180,shadow=PICO_BLACK, flash_color=PICO_YELLOW)            
        elif cursor == "allied_fleet":
            self.scene.fleet_managers['my'].generate_selectable_objects()
            self.cursor_icon = SimpleSprite(V2(0,0), "assets/i-fleet-cursor.png")
            self.hover_filter = self.filter_my_fleets
            self.selection_info_text = text.Text("Select one of your Fleets to apply upgrade", "big", V2(res.x / 2, res.y / 2), PICO_WHITE, multiline_width=180,shadow=PICO_BLACK, flash_color=PICO_YELLOW)
        elif cursor == "point":
            self.cursor_icon = SimpleSprite(V2(0,0), "assets/i-point-cursor.png")
            self.hover_filter = self.filter_only_ui
            self.selection_info_text = text.Text("Select a point", "big", V2(res.x / 2, res.y / 2), PICO_WHITE, multiline_width=180,shadow=PICO_BLACK, flash_color=PICO_YELLOW)
        elif cursor == "nearby":
            self.cursor_icon = SimpleSprite(V2(0,0), "assets/i-point-cursor.png")
            self.range = RangeIndicator(self.selected_targets[0].pos, self.NEARBY_RANGE, PICO_LIGHTGRAY)
            self.scene.ui_group.add(self.range)
            self.extras.append(self.range)
            self.hover_filter = self.filter_only_ui
            self.selection_info_text = text.Text("Select a point nearby", "big", V2(res.x / 2, res.y / 2), PICO_WHITE, multiline_width=180,shadow=PICO_BLACK, flash_color=PICO_YELLOW)

        self.cursor_icon.offset = (0.5, 0.5)
        self.cursor_icon._recalc_rect()
        self.scene.ui_group.add(self.cursor_icon)
        self.selection_info_text.offset = (0.5,0.5)
        self.selection_info_text.layer = 15    
        self.scene.ui_group.add(self.selection_info_text)                             
        self.scene.pause_sprite.set_exceptions([s for s in self.scene.game_group.sprites() if self.hover_filter(s)])
Example #11
0
 def update(self, planet, dt):
     if not self.indicator:
         self.indicator = RangeIndicator(planet.pos,
                                         self.RANGE,
                                         PICO_PINK,
                                         line_length=2,
                                         line_space=5)
         planet.scene.game_group.add(self.indicator)
         planet.selected_graphics.append(self.indicator)
     self.fire_time += dt
     threats = [
         o for o in planet.scene.get_enemy_objects(planet.owning_civ)
         if (o.pos - planet.pos).length_squared() < self.RANGE**2
         and o.health > 0 and not o.stealth
     ]
     if self.fire_time > self.FIRE_RATE and threats:
         self.fire_time = 0
         t = random.choice(threats)
         delta = t.pos - planet.pos
         _, angle = delta.as_polar()
         angle *= 3.14159 / 180
         angle += random.random() * 1.5 - 0.75
         b = bullet.Bullet(planet.pos +
                           helper.from_angle(angle) * planet.get_radius(),
                           t,
                           planet,
                           vel=helper.from_angle(angle) * 20,
                           mods={
                               'homing': 1,
                               "damage_base": 10 * planet.planet_weapon_mul,
                               "blast_radius": 10,
                               "color": PICO_WHITE,
                               "life": 5,
                               "missile_speed": 0.5
                           })
         planet.scene.game_group.add(b)
Example #12
0
    def update(self, dt):
        self.time += dt

        self.health_bar.pos = self.pos + V2(0, -self.height / 2)

        if self.time > 1.0 and not self.jumped:
            self.jumped = True
            bad_location = True
            i = 0
            while bad_location:
                np = V2(
                    self.scene.game.game_resolution.x * 0.66,
                    self.scene.game.game_resolution.y * 0.4
                ) + helper.random_angle() * random.random() * (50 + i * 10)
                _, dsq = helper.get_nearest(np, self.scene.get_planets())
                if dsq > 50**2:
                    bad_location = False
                i += 1
            delta = np - self.pos
            dn = helper.try_normalize(delta)
            side = V2(dn.y, -dn.x)
            for i in range(12):
                color = random.choice(
                    [PICO_RED, PICO_RED, PICO_ORANGE, PICO_YELLOW, PICO_WHITE])
                z = random.randint(-12, 12)
                l1 = LaserParticle(self.pos + side * z / 2,
                                   np - dn * (10 - abs(z)) + side * z, color,
                                   random.random())
                self.scene.game_group.add(l1)
            self.pos = np

        self.frame = int(self.time * 3) % 15
        if self.state == self.STATE_CINEMATIC_TRAVELING:
            self.target_planet, sqdist = helper.get_nearest(
                self.pos, self.planets_to_revive)
            if self.target_planet:
                #delta = self.target_planet.pos - self.pos
                if sqdist < REVIVING_PLANET_CLOSE_RANGE**2:
                    self.state = self.STATE_CINEMATIC_POPULATING
                    self.emit = ['bosscolonist']
                    num = 2
                    if len(self.planets_to_revive) == len(self.ships_on_board):
                        num = 1
                    if len(self.planets_to_revive) > len(self.ships_on_board):
                        num = 0
                    for i in range(num):
                        self.emit.append(self.ships_on_board.pop(0))
                    self.emit_timer = 5.0
                    if self.target_planet.owning_civ == self.scene.player_civ:
                        possible_evacs = self.scene.get_civ_planets(
                            self.scene.player_civ)
                        possible_evacs.remove(self.target_planet)
                        if possible_evacs:
                            possible_evacs = helper.nearest_order(
                                V2(0, self.scene.game.game_resolution.y // 2),
                                possible_evacs)
                            evac_target = random.choice(possible_evacs[0:3])
                            for ship, amt in self.target_planet.ships.items():
                                for i in range(amt):
                                    self.target_planet.emit_ship(
                                        ship, {"to": evac_target})
                            if self.target_planet.population:
                                self.target_planet.emit_ship(
                                    "colonist", {
                                        "to": evac_target,
                                        "num": self.target_planet.population
                                    })
                    return
                towards_planet = self.scene.flowfield.get_vector(
                    self.pos, self.target_planet, 5)
                self.velocity += towards_planet * dt * ACCEL

        if self.state == self.STATE_CINEMATIC_POPULATING:
            self.brake(dt)
            self.emit_timer -= dt
            if not self.emit:
                if self.emit_timer < -3:
                    self.planets_to_revive.remove(self.target_planet)
                    if self.planets_to_revive:
                        self.state = self.STATE_CINEMATIC_TRAVELING
                    else:
                        self.state = self.STATE_GAME_WAITING
                        self.range_indicator = RangeIndicator(
                            self.pos, REINCARNATE_RANGE, PICO_ORANGE, 1, 5)
                        self.scene.ui_group.add(self.range_indicator)
            else:
                if self.emit_timer < 0:
                    if self.target_planet.owning_civ == self.scene.player_civ:
                        self.target_planet.change_owner(None)
                    self.emit_timer = 1.0
                    name = self.emit.pop(0)
                    ctor = SHIPS_BY_NAME[name]
                    ship = ctor(self.scene, self.pos, self.owning_civ)
                    if 'colonist' in name:
                        ship.set_pop(3)
                    ship.set_target(self.target_planet)
                    self.scene.game_group.add(ship)
                    pass

        if self.state == self.STATE_GAME_WAITING:
            self.wander(dt)
            self.wait_time -= dt
            if self.wait_time < 0:
                self.state = self.STATE_GAME_TRAVELING
                self.travel_target = None

        if self.state == self.STATE_GAME_TRAVELING:
            if not self.travel_target:
                # Pick only fleets targeting a neutral or player planet
                fleets = [
                    f
                    for f in self.scene.fleet_managers['enemy'].current_fleets
                    if f.target.owning_civ != self.owning_civ
                    and isinstance(f.target, planet.Planet)
                ]
                if fleets:
                    self.travel_target = random.choice(fleets).target
                else:
                    self.state = self.STATE_GAME_WAITING
                    self.wait_time = 5
                    self.wander_center = V2(self.pos)
            if self.travel_target:
                delta = self.travel_target.pos - self.pos
                if delta.length_squared() > (REINCARNATE_RANGE - 10)**2:
                    accel = self.scene.flowfield.get_vector(
                        self.pos, self.travel_target, 10) * ACCEL
                    self.velocity += accel * dt
                else:
                    self.state = self.STATE_GAME_WAITING
                    self.wander_center = V2(self.pos)
                    self.wait_time = 30

        objs = self.scene.get_planets() + self.scene.get_hazards()
        nearest, dsq = helper.get_nearest(self.pos, objs)
        if dsq < 40**2:
            delta = nearest.pos - self.pos
            self.velocity += -helper.try_normalize(delta) * ACCEL / 2 * dt

        if self.velocity.length_squared() > self.max_speed**2:
            self.velocity = helper.try_normalize(
                self.velocity) * self.max_speed

        self.pos += self.velocity * dt
        if self.range_indicator:
            self.range_indicator.pos = self.pos

        if self.state in [self.STATE_GAME_WAITING, self.STATE_GAME_TRAVELING]:
            self.update_reincarnation()

        return super().update(dt)