Exemplo n.º 1
0
    def make_frozen_sprite(self, ship):
        outline_mask = pygame.mask.from_surface(ship.image, 127)
        surf = outline_mask.to_surface(setcolor=(*PICO_WHITE,255), unsetcolor=(0,0,0,0))      

        color_mask = pygame.mask.from_threshold(ship.image, (*PICO_GREEN,255), (2,2,2,255))
        surf2 = color_mask.to_surface(setcolor=(*PICO_BLUE,255), unsetcolor=(0,0,0,0))
        surf.blit(surf2,(0,0))
        s = SimpleSprite(ship.pos, surf)
        s.offset = (0.5,0.5)
        return s
Exemplo n.º 2
0
 def __init__(self, pos, sheet, frame_width):
     SimpleSprite.__init__(self, pos, sheet)
     self._sheet_width = self._width
     self._sheet = self.image
     self._frame = 0
     self._frame_width = frame_width
     self._width = self._frame_width
     self._update_image()
     self.rect = pygame.Rect(0, 0, self._width, self._height)
     self._num_frames = self._sheet_width // self._frame_width
Exemplo n.º 3
0
 def on_select(self, upgrade):
     if upgrade.cursor == None:
         self.pending_upgrade = upgrade
         self.scene.my_civ.civ_upgrades.append(upgrade.name)
         upgrade().apply(self.scene.my_civ)
         self.finish()
     else:
         self.pending_upgrade = upgrade
         self.cursor_type = upgrade.cursor
         self.cursor_icon = SimpleSprite(V2(0,0), "assets/i-planet-cursor.png")
         self.cursor_icon.offset = (0.5, 0.5)
         self.cursor_icon._recalc_rect()
         self.scene.ui_group.add(self.cursor_icon)
         self.hover_filter = lambda x:(x.get_selection_info() and x.get_selection_info()['type'] == 'planet' and x.owning_civ == self.scene.my_civ)
         self.panel.kill()
Exemplo n.º 4
0
    def __init__(self, pos, planet_from, planet_to, on_order):
        super().__init__(pos, planet_from)
        self.planet_from = planet_from
        self.planet_to = planet_to
        self.on_order = on_order

        self.tab = {'text': "Send Ships", 'color': PICO_PINK}

        ships = {**self.planet_from.ships}
        ships['colonist'] = self.planet_from.population

        y = 0
        self.sliders = {}
        for ship in ships.keys():
            if ships[ship]:
                if ship == "colonist":
                    name = "Worker"
                else:
                    name = ship.title()

                self.add(SimpleSprite((0, 0), 'assets/i-%s.png' % ship),
                         V2(0, y))
                self.add(
                    Text("%ss" % name, "small", (0, 0), PICO_WHITE, False),
                    V2(14, y + 2))
                slider = Slider(V2(0, 0), 80, 0, ships[ship])
                self.add(slider, V2(0, y + 12))
                self.sliders[ship] = slider
                y += 45

        self.add(Button(V2(0, 0), "LAUNCH", "small", self.on_launch_click),
                 V2(20, y))

        self.redraw()
Exemplo n.º 5
0
    def __init__(self, store, onclick):
        super().__init__(V2(5,5), store)
        self.padding = 3 # ??
        self.store = store
        
        self.tab = {'text':"Sector %d" % store.coords[0], 'color':(0,0,0,0)}

        w = 145

        self.add(Line(V2(0,0), V2(w,0), PICO_SKIN), (V2(0,0)))
        self.add(Rectangle(V2(0,0), (82, 16), PICO_SKIN), V2(w - 82,0))
        self.add(SimpleSprite(V2(0,0), "assets/panel-shop.png"), V2(7,5))
        
        self.add(Text("Shop", "small", (0,0), PICO_BLACK, False, multiline_width=100), V2(94,3)) 
        self.add(Text("Trade Credits\nfor items", "small", (0,0), PICO_WHITE, False, multiline_width=120, center=False), V2(65,25)) 

        self.add(Line(V2(0,0), V2(w,0), PICO_SKIN), (V2(0,52)))
        self.add(Line(V2(0,0), V2(w,0), PICO_SKIN), (V2(0,54)))

        if store.playable or game.DEV:
            t = "VISIT"
            if game.Game.inst.input_mode == "joystick":
                t = "[*x*] VISIT"
            self.button = Button(V2(0,0), t, 'small', lambda:onclick(store), color=PICO_PINK)
            self.add(self.button, V2(36, 70))
            self.add(Line(V2(0,0), V2(w,0), PICO_DARKBLUE), (V2(0,94)))

        self.redraw()
Exemplo n.º 6
0
    def rebuild(self):
        for ci in self._controls:
            ci['control'].kill()
        self._controls = []

        self.add(SimpleSprite(V2(0, 0), "assets/shopgraphic.png"), V2(24, 0))
        self.add(Text("Shop", "logo", V2(0, 0), multiline_width=140),
                 V2(90, 12))

        btn = Button(V2(0, 0), "Done", "big", self.on_done, color=PICO_WHITE)
        self.add(btn, V2(310, 260) - V2(btn.width, btn.height))

        self.add(text.Text("O2", "small", V2(0, 0), PICO_LIGHTGRAY),
                 V2(210, 165))
        self.add(
            text.Text(get_time_string(game.Game.inst.run_info.o2), "big",
                      V2(0, 0), PICO_WHITE), V2(210, 175))

        self.add(text.Text("Credits", "small", V2(0, 0), PICO_LIGHTGRAY),
                 V2(210, 200))
        self.add(
            text.Text("%dC" % game.Game.inst.run_info.credits, "big", V2(0, 0),
                      PICO_WHITE), V2(210, 210))

        self.add_panel(V2(0, 0), self.store_data['offerings'][0])
        self.add_panel(V2(1, 0), self.store_data['offerings'][1])
        self.add_panel(V2(0, 1), self.store_data['offerings'][2])

        self.redraw()
        self.add_all_to_group(self.groups()[0])
Exemplo n.º 7
0
    def __init__(self, pos, planet_from, planet_to, on_order):
        super().__init__(pos, planet_to)
        self.planet_from = planet_from
        self.planet_to = planet_to
        self.on_order = on_order

        siegers_only = isinstance(self.planet_to, asteroid.Asteroid)

        self.tab = {'text': "Send Ships", 'color': PICO_PINK}

        ships = {**self.planet_from.ships}
        ships['colonist'] = self.planet_from.population

        y = 0
        self.sliders = {}
        for ship in ships.keys():
            if ships[ship]:
                if ship == "colonist":
                    name = "Worker"
                else:
                    name = SHIPS_BY_NAME[ship].get_display_name()

                color = PICO_WHITE
                disabled = False
                if siegers_only and not SHIPS_BY_NAME[ship].BOMBS:
                    disabled = True
                    color = PICO_DARKGRAY
                self.add(SimpleSprite((0, 0), 'assets/i-%s.png' % ship),
                         V2(0, y))
                self.add(Text("%ss" % name, "small", (0, 0), color, False),
                         V2(14, y + 2))
                disable_nums = None
                if self.planet_from.owning_civ.worker_loss > 0:
                    disable_nums = list(
                        range(1, self.planet_from.owning_civ.worker_loss + 1))
                slider = Slider(V2(0, 0),
                                80,
                                0,
                                ships[ship],
                                disabled=disabled,
                                disable_nums=disable_nums)
                self.add(slider, V2(0, y + 12))
                self.sliders[ship] = slider
                y += 45

        if not self.sliders:
            self.add(Text("No ships!", "small", V2(0, 0)), V2(0, 0))
            y += 25

        t = "LAUNCH"
        if game.Game.inst.input_mode == "joystick":
            t = "[*x*] LAUNCH"
        if not self.sliders:
            t = "BACK"
            if game.Game.inst.input_mode == "joystick":
                t = "[*circle*] BACK"
        self.add(Button(V2(0, 0), t, "small", self.on_launch_click), V2(20, y))

        self.redraw()
Exemplo n.º 8
0
    def __init__(self, scene, pos, owning_civ):
        super().__init__(scene, pos, owning_civ)
        self._set_player_ship_sprite_sheet()
        self.busters = 2
        self.max_busters = 2
        self.buster_time = 1.0
        self.states['siege']['enter'] = self.enter_state_siege
        self.comm_radius = 100
        self.owning_civ.comm_objects.append(self)

        self.buster_display = SimpleSprite(V2(0, 0), None)
        self.buster_display.offset = (0.5, 0)
        self.buster_display.layer = 5
        self._generate_buster_display()
        self.scene.game_group.add(self.buster_display)

        self.enter_stealth_time = 1
Exemplo n.º 9
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)])
Exemplo n.º 10
0
    def __init__(self, pos):
        super().__init__(pos, None)
        self.padding = 10
        self.tab = {'text':"Help", 'color':PICO_GREEN}

        y = 0
        def add_text(txt):
            nonlocal y
            t = Text(txt, "small", (0,0), PICO_WHITE, False, 350, center=False)
            self.add(t, V2(26,y))
            y += t.height + 12

        add_text("To order your units around, click and drag from your planet to a target planet. Workers can take control of neutral or heavily damaged planets.")
        add_text("Planets you control generate resources every few seconds based on how many workers are on the planet (population) and which resources are available there. Population also grows over time.")
        add_text("Larger planets have a higher maximum population. Adding workers above that number doesn't help. Click on a planet to see its stats.")
        add_text("Your resources: Iron, Ice, and Gas, accumulate in the meters in the top left. When a resource meter is full, you can UPGRADE!")
        add_text("Each resource provides its own unique upgrades, but upgrades come in three types: BASE CONSTRUCTION, SHIP PRODUCTION, and TECHNOLOGY.")
        add_text("The aliens have started colonizing planets, and will only get more powerful over time. Good luck!")

        self.add(SimpleSprite((0,0), 'assets/help-1.png'), V2(0,0))
        self.add(SimpleSprite((0,0), 'assets/help-2.png'), V2(0,36))
        self.add(SimpleSprite((0,0), 'assets/i-pop.png'), V2(4,95))
        self.add(SimpleSprite((0,0), 'assets/help-3.png'), V2(0,126))
        self.add(SimpleSprite((0,0), 'assets/help-4.png'), V2(0,166))
        self.add(SimpleSprite((0,0), 'assets/help-5.png'), V2(0,206))

        self.redraw()
Exemplo n.º 11
0
 def create_o2_row(self, row, y):
     price = 60
     elem = SimpleSprite(V2(0, 0), "assets/i-o2.png")
     sib = StoreItemButton(V2(225, y) + self.game.game_offset,
                           elem,
                           "Oxygen - 600",
                           "Gain +600 seconds of Oxygen.",
                           price,
                           bought='o2' in self.bought,
                           can_afford=self.game.run_info.credits >= price,
                           onclick=lambda: self.buy_o2(price, 600))
     self.ui_group.add(sib)
     self.ui_group.add(elem)
     self.buttons.append([sib])
Exemplo n.º 12
0
 def create_levelup_row(self, row, y):
     ship = row['ship']
     elem = SimpleSprite(V2(0, 0), "assets/i-%s.png" % ship)
     price = 100
     lvl = self.game.run_info.ship_levels[ship] + 1
     if 'levelup' in self.bought:
         lvl -= 1
     sib = StoreItemButton(V2(225, y) + self.game.game_offset,
                           elem,
                           "%s Level %d" % (ship.title(), lvl),
                           "Improve health and damage of all %ss" %
                           ship.title(),
                           price,
                           bought='levelup' in self.bought,
                           can_afford=self.game.run_info.credits >= price,
                           onclick=lambda: self.buy_levelup(price, ship))
     self.ui_group.add(sib)
     self.ui_group.add(elem)
     self.buttons.append([sib])
Exemplo n.º 13
0
class UpgradeState(UIEnabledState):
    NEARBY_RANGE = 70
    is_basic_joystick_panel = True
    def __init__(self, scene):
        UIEnabledState.__init__(self, scene)
        self.pending_upgrade = None
        self.cursor_icon = None
        self.selection_info_text = None
        #self.back_button = None
        self.current_cursor = None

    def enter(self):
        sound.play("panel")
        self.scene.paused = True
        resource = self.scene.player_civ.upgrades_stocked[0]
        is_new_roll = len(self.scene.player_civ.offered_upgrades) == 0
        offered_upgrades = self.scene.player_civ.offer_upgrades(resource)
        self.panel = UpgradePanel(V2(0,0), offered_upgrades, resource, self.on_select, self.on_reroll, is_new_roll)
        self.panel.add_all_to_group(self.scene.ui_group)
        self.panel.position_nicely(self.scene)
        
        self.hover_filter = self.filter_only_panel_ui
        self.selected_targets = []
        self.extras = []
        super().enter()
        self.panel.fade_in(speed=3)

    def filter_my_planets(self, x):
        return (
            x.get_selection_info() and
            x.get_selection_info()['type'] == 'planet' and
            x.owning_civ == self.scene.player_civ and 
            x.upgradeable and
            x.is_buildable()
        )

    def filter_any_planets(self, x):
        return (
            x.get_selection_info() and
            x.get_selection_info()['type'] == 'planet'
        )        

    def filter_my_fleets(self, x):
        return (
            x.get_selection_info() and x.get_selection_info()['type'] == 'fleet' and x.owning_civ == self.scene.player_civ
        )

    def get_joystick_cursor_controls(self):
        l = []
        if self.panel:
            return self.panel.joystick_controls

    def exit(self):
        self.hover_filter = lambda x:True
        self.scene.paused = False
        if self.selection_info_text:
            self.selection_info_text.kill()
        if self.cursor_icon:
            self.cursor_icon.kill()
        #if self.back_button:
        #    self.back_button.kill()
        super().exit()

    def finish(self, target=None, cancel = False):
        for extra in self.extras:
            extra.kill()
        self.extras = []        
        if not cancel:
            self.scene.player_civ.upgrades_stocked.pop(0)
            self.scene.player_civ.register_research(self.pending_upgrade.name)
            self.scene.player_civ.clear_offers()
            sound.play("upgrade2")
            self.scene.pop_asset_button()
        if self.panel:
            self.panel.kill()
        if self.joystick_overlay:
            self.joystick_overlay.kill()
        self.scene.sm.transition(levelstates.PlayState(self.scene))

    def on_reroll(self):
        self.scene.player_civ.clear_offers()
        self.panel.kill()
        self.scene.game.run_info.rerolls -= 1
        resource = self.scene.player_civ.upgrades_stocked[0]
        self.panel = UpgradePanel(V2(0,0), self.scene.player_civ.offer_upgrades(resource), resource, self.on_select, self.on_reroll, True)
        self.panel.add_all_to_group(self.scene.ui_group)
        self.panel.position_nicely(self.scene)
        self.panel.fade_in(speed=10)

        if self.joystick_overlay:
            self.joystick_overlay.kill()
            self.joystick_overlay = joystickcursor.JoystickPanelCursor(self.scene, self.get_joystick_cursor_controls())
            self.scene.ui_group.add(self.joystick_overlay)

    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)])

    def on_select(self, upgrade):
        if isinstance(upgrade.cursor, list):
            self.cursors = upgrade.cursor[::]
        else:
            self.cursors = [upgrade.cursor]

        self.current_cursor = self.cursors.pop(0)

        if self.current_cursor == None:
            self.pending_upgrade = upgrade
            self.scene.player_civ.upgrades.append(upgrade)
            upgrade().apply(self.scene.player_civ)
            self.scene.ui_group.add(FunNotification(self.pending_upgrade.title, None))
            self.finish()
        else:
            self.pending_upgrade = upgrade
            self.setup_cursor_type(self.current_cursor)
            #self.back_button = Button(V2(game.RES[0] / 2, game.RES[1] - 5), "Back", "small", self.on_back)
            #self.back_button.offset = (0.5, 1)
            #self.scene.ui_group.add(self.back_button)            

    def next_selection_step(self):
        sound.play("click1")
        for extra in self.extras:
            extra.kill()
        self.extras = []

        if self.selection_info_text:
            self.selection_info_text.kill()
        if self.cursor_icon:
            self.cursor_icon.kill()

        if self.cursors:
            self.current_cursor = self.cursors.pop(0)
            self.setup_cursor_type(self.current_cursor)
        else:
            u = self.pending_upgrade().apply(*self.selected_targets)
            self.finish(target=self.selected_targets[0])

    def mouse_input(self, input, event):
        handled = super().mouse_input(input, event)
        if handled and input != "menu":
            return
        if self.cursor_icon:
            if input in ["mouse_move", "mouse_drag"]:
                self.cursor_icon.pos = event.gpos + V2(10,10)

        if self.current_cursor:
            if input == "menu":
                self.on_back()

            if input == "click" and self.hover_sprite:
                sel = self.hover_sprite.get_selection_info()
                if sel:
                    if self.current_cursor == "allied_planet" and sel['type'] == "planet" and self.hover_sprite.owning_civ == self.scene.player_civ:
                        self.selected_targets.append(self.hover_sprite)
                        self.next_selection_step()
                        return

                    if self.current_cursor == "any_planet" and sel['type'] == "planet":
                        self.selected_targets.append(self.hover_sprite)
                        self.next_selection_step()
                        return                        

                    if self.current_cursor == "allied_fleet" and sel['type'] == "fleet":
                        self.selected_targets.append(self.hover_sprite)
                        self.scene.fleet_managers['my'].destroy_selectable_objects()
                        self.next_selection_step()
                        return

            if input == "click" and self.current_cursor == "point":
                self.selected_targets.append(event.gpos)
                self.next_selection_step()
                return

            if input == "click" and self.current_cursor == "nearby":
                if (event.gpos - self.selected_targets[0].pos).length_squared() < self.NEARBY_RANGE ** 2:
                    self.selected_targets.append(event.gpos)
                    self.next_selection_step()
                    return                

        else:
            if input == "menu":
                self.finish(cancel = True)

            if input == "click":
                pr = pygame.Rect(self.panel.x, self.panel.y, self.panel.width, self.panel.height)
                if not pr.collidepoint(event.gpos):
                    self.finish(cancel = True)    

    def joystick_input(self, input, event):
        if input == "back":
            if self.pending_upgrade:
                sound.play("cancel")
                self.on_back()
            else:
                sound.play("cancel")
                self.finish(cancel = True)

        if self.pending_upgrade is None:
            self.joystick_overlay.controls = self.get_joystick_cursor_controls()
            return super().joystick_input(input, event)

        if input == "joymotion":
            self.joystick_overlay.joystick_delta(event['delta'])

        if input == "confirm":
            spr = self.joystick_overlay.nearest_obj
            if spr:
                sel = spr.get_selection_info()
                if sel:
                    if self.current_cursor == "allied_planet" and sel['type'] == "planet" and spr.owning_civ == self.scene.player_civ:
                        self.selected_targets.append(spr)
                        self.next_selection_step()
                        return

                    if self.current_cursor == "any_planet" and sel['type'] == "planet":
                        self.selected_targets.append(spr)
                        self.next_selection_step()
                        return                           

                    if self.current_cursor == "allied_fleet" and sel['type'] == "fleet":
                        self.selected_targets.append(spr)
                        self.scene.fleet_managers['my'].destroy_selectable_objects()
                        self.next_selection_step()
                        return

            if self.current_cursor == "point":
                self.selected_targets.append(self.joystick_overlay.cursor_pos)
                self.next_selection_step()
                return

            if self.current_cursor == "nearby":
                if (self.joystick_overlay.cursor_pos - self.selected_targets[0].pos).length_squared() < self.NEARBY_RANGE ** 2:
                    self.selected_targets.append(self.joystick_overlay.cursor_pos)
                    self.next_selection_step()
                    return      

    def joystick_update(self, dt):
        if self.pending_upgrade is None:
            return

        all_sprites = []
        all_sprites.extend(
            sorted(self.scene.ui_group.sprites()[::], key=lambda x:x.layer, reverse=True)
        )        
        all_sprites.extend(
            sorted(self.scene.game_group.sprites()[::], key=lambda x:x.layer, reverse=True)
        )
        selectable_sprites = [s for s in all_sprites if s.selectable and s.visible and isinstance(s, SpaceObject) and self.hover_filter(s)]

        nearest, d = get_nearest(self.joystick_overlay.cursor_pos, selectable_sprites)
        if d < 40 ** 2:
            self.joystick_overlay.set_nearest(nearest)
        else:
            self.joystick_overlay.set_nearest(None)                              
        
    def on_back(self):
        print("on_back")
        if self.cursor_icon:
            self.cursor_icon.kill()
            self.cursor_icon = None

        self.current_cursor = None

        self.cursor_type = None
        self.pending_upgrade = None
        resource = self.scene.player_civ.upgrades_stocked[0]
        self.panel = UpgradePanel(V2(0,0), self.scene.player_civ.offer_upgrades(resource), resource, self.on_select, self.on_reroll, False)
        self.panel.add_all_to_group(self.scene.ui_group)
        self.panel.position_nicely(self.scene)
        self.panel.fade_in(speed=10)
        self.hover_filter = self.filter_only_panel_ui
        #self.back_button.kill()
        #self.back_button = None
        self.selection_info_text.kill()
        self.selection_info_text = None
        self.selected_targets = []
        for extra in self.extras:
            extra.kill()
        self.extras = []   

        if self.joystick_overlay:
            self.joystick_overlay.kill()
            self.joystick_overlay = joystickcursor.JoystickPanelCursor(self.scene, self.get_joystick_cursor_controls())
            self.scene.ui_group.add(self.joystick_overlay)             

    def update(self, dt):
        if self.scene.game.input_mode == "joystick":
            self.joystick_update(dt)
        return super().update(dt)
Exemplo n.º 14
0
    def load(self):
        self.background_group = pygame.sprite.Group()
        self.game_group = pygame.sprite.LayeredDirty()
        self.ui_group = pygame.sprite.LayeredDirty()
        self.tutorial_group = pygame.sprite.Group()

        self.background_group.add(Background(V2(0, 0)))

        # Me
        homeworld = Planet(self, V2(60, game.RES[1] - 40), 7,
                           Resources(100, 0, 0))
        homeworld.change_owner(self.my_civ)
        homeworld.population = 4
        homeworld.ships['fighter'] = 2
        homeworld.add_building("mining_rate")
        self.game_group.add(homeworld)

        # Alien
        p = Planet(self, V2(420, 60), 5, Resources(70, 20, 10))
        p.change_owner(self.enemy.civ)
        p.population = 5
        p.ships['alien-fighter'] = 2
        self.game_group.add(p)
        num_planets = 2

        # TODO: Planet resources more constrained
        while num_planets < 15:
            pos = V2(random.randint(30, game.RES[0] - 30),
                     random.randint(30, game.RES[1] - 30))

            near_button = pygame.Rect(game.RES[0] / 2 - 100, game.RES[1] - 60,
                                      200, 60)
            if near_button.collidepoint(*pos.tuple()):
                continue

            near_meters = pygame.Rect(0, 0, 250, 60)
            if near_meters.collidepoint(*pos.tuple()):
                continue

            dist = 999999
            for planet in self.get_planets():
                delta = (planet.pos - pos).sqr_magnitude()
                if delta < dist:
                    dist = delta
            if dist > 70**2:
                if pos.x / 2 + (game.RES[1] - pos.y) < game.RES[1] - 100:
                    size = random.randint(4, 7)
                    if random.random() > 0.5:
                        pr = Resources(100, 0, 0)
                    else:
                        size -= 1
                        iron = random.randint(7, 10)
                        pr = Resources(iron * 10, (10 - iron) * 10, 0)
                else:
                    size = random.randint(3, 7)
                    resources = {'a': 0, 'b': 0, 'c': 0}
                    # One resource
                    ra = random.random()
                    if ra > 0.75:
                        resources['a'] = 10
                    # Two resource
                    elif ra > 0.33:
                        resources['a'] = random.randint(5, 10)
                        resources['b'] = 10 - resources['a']
                    # Three
                    else:
                        resources['a'] = random.randint(1, 7)
                        resources['b'] = random.randint(1, 10 - resources['a'])
                        resources['c'] = 10 - resources['a'] - resources['b']
                    rb = random.random()
                    if rb > 0.6:
                        pr = Resources(resources['a'] * 10,
                                       resources['b'] * 10,
                                       resources['c'] * 10)
                        size += 1
                    elif rb > 0.25:
                        pr = Resources(resources['b'] * 10,
                                       resources['a'] * 10,
                                       resources['c'] * 10)
                    else:
                        pr = Resources(resources['c'] * 10,
                                       resources['b'] * 10,
                                       resources['a'] * 10)
                        size -= 1
                self.game_group.add(Planet(self, pos, size, pr))
                num_planets += 1

        self.meters = {}
        self.upgrade_texts = {}
        for i, r in enumerate(self.my_civ.resources.data.keys()):
            self.meters[r] = Meter(V2(15,
                                      3 + i * 14), 120, 9, RESOURCE_COLORS[r],
                                   self.my_civ.upgrade_limits.data[r])
            self.meters[r].stay = True
            self.ui_group.add(
                SimpleSprite(V2(2, 2 + i * 14), "assets/i-%s.png" % r))
            self.ui_group.add(self.meters[r])
            self.upgrade_texts[r] = Text("",
                                         "small",
                                         V2(140, 4 + i * 14),
                                         multiline_width=200)
            self.ui_group.add(self.upgrade_texts[r])

        self.my_civ.resources.on_change(self.on_civ_resource_change)

        self.upgrade_button = Button(V2(game.RES[0] / 2, game.RES[1] - 4),
                                     "UPGRADE", "big", self.on_click_upgrade)
        self.upgrade_button.offset = (0.5, 1)
        self.upgrade_button._recalc_rect()
        self.upgrade_button.visible = 0
        self.ui_group.add(self.upgrade_button)

        self.help_button = Button(V2(2, 48), "Help", "small",
                                  self.on_click_help)
        self.ui_group.add(self.help_button)

        self.score_label = Text("- Score -", "small", V2(game.RES[0] - 2, 2),
                                PICO_BLUE)
        self.score_label.offset = (1, 0)
        self.score_label._recalc_rect()
        self.ui_group.add(self.score_label)

        self.score_text = Text("0", "small", V2(game.RES[0] - 2, 12),
                               PICO_BLUE)
        self.score_text.offset = (1, 0)
        self.score_text._recalc_rect()
        self.ui_group.add(self.score_text)

        self.my_civ.resources.set_resource("iron", 30)

        if self.options == "iron":
            self.my_civ.resources.set_resource("iron", 150)

        if self.options == "ice":
            self.my_civ.resources.set_resource("ice", 150)

        if self.options == "gas":
            self.my_civ.resources.set_resource("gas", 150)

        if self.options == "surround":
            for planet in self.get_civ_planets(None):
                planet.change_owner(self.enemy.civ)
                planet.add_ship("alien-fighter")
                planet.add_ship("alien-fighter")
                #self.my_civ.resources.set_resource("iron", 50)
                #self.my_civ.resources.set_resource("ice", 50)
                self.my_civ.resources.set_resource("gas", 50)

        if self.options == "fighters":
            for i in range(20):
                homeworld.add_ship("fighter")

        if self.options == "battleship":
            from ships.alienbattleship import AlienBattleship
            bs = AlienBattleship(self, V2(150, 250), self.enemy.civ)
            bs.target = homeworld
            self.game_group.add(bs)

        if self.options == "fast":
            self.game_speed = 10

        if self.options == "score":
            homeworld.change_owner(self.enemy.civ)
Exemplo n.º 15
0
    def start(self):
        self.time = 0
        self.game.save.set_run_state(self.game.run_info)
        self.game.save.save()

        self.background_group = pygame.sprite.Group()
        self.game_group = pygame.sprite.LayeredDirty()
        self.ui_group = pygame.sprite.LayeredDirty()
        self.display_group = pygame.sprite.LayeredDirty()
        self.tutorial_group = pygame.sprite.Group()

        if self.game.run_info.reward_list:
            rewards_width = len(self.game.run_info.reward_list) * 23 + 200
        else:
            rewards_width = 160

        self.background = starmapbackground.StarmapBackground(
            V2(0, 0), rewards_width)
        self.background_group.add(self.background)

        backtext = "BACK"
        if self.game.input_mode == "joystick": backtext = "[*circle*] BACK"
        self.back = button.Button(V2(5, 5),
                                  backtext,
                                  "big",
                                  self.on_back,
                                  color=PICO_WHITE)
        self.ui_group.add(self.back)

        run_path = self.game.run_info.path
        res = self.game.game_resolution

        self.grid = []
        self.nodes = []
        x = 30 + self.game.game_offset.x
        base_y = self.background.center_y / 2
        max_per_row = max([len(row) for row in self.game.run_info.data])
        for r, row in enumerate(self.game.run_info.data):
            self.grid.append([])
            for i, column in enumerate(row):
                scaling = 54 - (max_per_row * 8)
                y = base_y - scaling * (len(row) - 1) + (scaling * 2) * i
                obj = None
                reward = None
                if column['node_type'] == 'galaxy':
                    alien = ALIENS[column['alien']]
                    img = "assets/si-alien.png"
                    if column['mods']:
                        img = "assets/si-alien-mod.png"
                    if r == len(self.game.run_info.data) - 1:
                        img = "assets/si-signal.png"
                    obj = NodeSprite(self.game.run_info, (r, i), V2(x, y), img)
                    obj.offset = (0.5, 0.5)
                    rdx = 0
                    if len(column['rewards']) > 1:
                        rdx = -13
                    rewards = []
                    for rew in column['rewards']:
                        reward = FrameSprite(V2(x + 7 + rdx, y + 15),
                                             "assets/reward_icons.png", 23)
                        reward.frame = REWARD_ICONS_ORDER[rew]
                        reward.offset = (0.5, 0.5)
                        rdx += 16
                        rewards.append(reward)

                elif column['node_type'] == 'store':
                    obj = NodeSprite(self.game.run_info, (r, i), V2(x, y),
                                     "assets/si-shop.png")
                    obj.offset = (0.5, 0.5)

                self.grid[-1].append(obj)
                for j in column['links']:
                    p2 = obj.pos
                    p1 = self.grid[-2][j].pos
                    prev_obj = self.grid[-2][j]
                    path = StarPath(
                        p1, p2,
                        obj.is_travelled() and prev_obj.is_travelled(),
                        obj.is_pickable() and prev_obj.is_travelled())
                    self.game_group.add(path)
                if obj.is_travelled():
                    if r < len(run_path) - 1:
                        o = SimpleSprite(obj.pos, "assets/si-traveled.png")
                        o.offset = (0.5, 0.5)
                        self.game_group.add(o)
                else:
                    self.nodes.append(obj)
                    self.game_group.add(obj)
                    if rewards:
                        for reward in rewards:
                            self.ui_group.add(reward)

            x += 60

        p = self.grid[run_path[-1][0]][run_path[-1][1]].pos
        self.colonist = SimpleSprite(p, 'assets/si-player.png')
        self.colonist.offset = (0.5, 0.5)
        self.game_group.add(self.colonist)
        ry = self.background.center_y
        t1 = text.Text("Credits | [>%d]" % self.game.run_info.credits,
                       "small",
                       V2(res.x / 2 + rewards_width / 2 - 64, ry - 3),
                       PICO_DARKBLUE,
                       multiline_width=150)
        t1.offset = (1, 0)
        self.ui_group.add(t1)

        t2 = text.Text("O2 | [>%s]" %
                       helper.get_time_string(self.game.run_info.o2),
                       "small",
                       V2(res.x / 2 + rewards_width / 2 - 5, ry - 3),
                       PICO_DARKBLUE,
                       multiline_width=150)
        t2.offset = (1, 0)
        self.ui_group.add(t2)

        if self.game.run_info.reward_list:
            t3 = text.Text("Acquired |", "small",
                           V2(res.x / 2 - rewards_width / 2 + 8, ry - 3),
                           PICO_BLACK)
            self.ui_group.add(t3)
            rx = t3.x + 61
            for r in self.game.run_info.reward_list:
                reward = RewardWithBackground(V2(rx, ry + 1), r['name'])
                reward.offset = (0.5, 0.5)
                self.game_group.add(reward)
                rx += 23
        else:
            t1.offset = (0.5, 0)
            t1.x = res.x / 2 - 30
            t2.offset = (0.5, 0)
            t2.x = res.x / 2 + 30

        self.sm = states.Machine(StarMapState(self))
Exemplo n.º 16
0
 def __init__(self, pos, sprite_sheet=None, frame_width=None):
     SimpleSprite.__init__(self, pos)
     self._frame = 0
     if sprite_sheet:
         self.set_sprite_sheet(sprite_sheet, frame_width=frame_width)
Exemplo n.º 17
0
    def rebuild_panel(self):
        planet = self.planet
        pov_civ = self.pov_civ
        self.empty()
        self.add(Line(V2(0, 0), V2(120, 0), PICO_DARKBLUE), V2(0, 0))

        owner = "Neutral"
        color = PICO_YELLOW

        is_mine = False
        if planet.owning_civ:
            color = planet.owning_civ.color
            # If the player's point of view is passed in (multiplayer) then
            # we want the string to be based on if this is that POV civ's planet or not
            if pov_civ is not None:
                if planet.owning_civ != pov_civ:
                    owner = "Enemy"
                else:
                    owner = "Your"
                    is_mine = True
            else:
                if planet.owning_civ.is_enemy:
                    owner = "Enemy"
                else:
                    owner = "Your"
                    is_mine = True

        if not pov_civ:
            pov_civ = self.planet.scene.player_civ  # horrible.
        in_comm_range = pov_civ.in_comm_circle(planet.pos)

        self.tab = {
            'text': '%s Planet' % (owner, ),
            'color': color,
            'icon': 'assets/i-planet.png'
        }
        y = 0

        if is_mine and planet.is_zero_pop():
            t = Text("0 Pop = No Growth!",
                     "small", (0, 0),
                     PICO_BLACK,
                     multiline_width=120)
            self.add(Rectangle(V2(0, 0), (t.width + 2, 12), PICO_YELLOW),
                     V2(0, y - 1))
            self.add(t, V2(1, y + 1))
            y += 17

        if is_mine and planet.has_extra_ships():
            t = Text("Too many ships!",
                     "small", (0, 0),
                     PICO_BLACK,
                     multiline_width=120)
            self.add(Rectangle(V2(0, 0), (t.width + 2, 12), PICO_YELLOW),
                     V2(0, y - 1))
            self.add(t, V2(1, y + 1))
            y += 17

        if is_mine and planet.is_production_blocked():
            t = Text("Max Supply!",
                     "small", (0, 0),
                     PICO_BLACK,
                     multiline_width=120)
            self.add(Rectangle(V2(0, 0), (t.width + 2, 12), PICO_YELLOW),
                     V2(0, y - 1))
            self.add(t, V2(1, y + 1))
            y += 17

        self.add(
            Text("Health: %d/%d" % (planet.health, planet.get_max_health()),
                 "small", (0, 0),
                 PICO_WHITE,
                 False,
                 multiline_width=120), V2(0, y))
        y += 15
        self.add(Text("Resources", "small", (0, 0), PICO_WHITE, False),
                 V2(0, y))
        y += 15

        chart_y = y - 15
        chart_data = {}
        for r in RESOURCES:
            pr = getattr(planet.resources, r)
            if pr:
                self.add(SimpleSprite((0, 0), 'assets/i-%s.png' % r), V2(0, y))
                self.add(Text(r.title(), "small", (0, 0), PICO_WHITE, False),
                         V2(15, y + 2))
                self.add(Text("%s%%" % pr, "small", (0, 0), PICO_WHITE, False),
                         V2(40, y + 2))
                y += 15
                chart_data[RESOURCE_COLORS[r]] = pr

        self.add(PieChart((0, 0), chart_data), V2(80, chart_y - 2))

        y = max(y + 7, 41)
        self.add(Line(V2(0, 0), V2(120, 0), PICO_GREYPURPLE), V2(0, y))
        y += 5

        self.add(SimpleSprite((0, 0), 'assets/i-pop.png'), V2(44, y))
        color = PICO_WHITE
        if planet.population == 0 or planet.population >= planet.get_max_pop():
            color = PICO_YELLOW
        if planet.owning_civ == None or is_mine or in_comm_range:
            self.add(
                Text("%d/%d" % (planet.population, planet.get_max_pop()),
                     "small", (0, 0), color, False), V2(57, y + 1))
        else:
            self.add(
                Text("?/%d" % planet.get_max_pop(), "small", (0, 0), color,
                     False), V2(57, y + 1))

        y += 14
        if sum(planet.ships.values()) and (is_mine or in_comm_range):
            self.add(Line(V2(0, 0), V2(120, 0), PICO_GREYPURPLE), V2(0, y))
            y += 4
            ships_alpha = sorted(planet.ships.keys())
            maxxed = False
            if sum(planet.ships.values()) > planet.get_max_ships():
                maxxed = True
            for ship in ships_alpha:
                if planet.ships[ship] <= 0:
                    continue
                icon = SimpleSprite((0, 0), 'assets/i-%s.png' % ship)
                self.add(icon, V2(0, y))
                iconoffset = 0
                if icon.width < 5:
                    iconoffset = 15
                ship_class = SHIPS_BY_NAME[ship]

                self.add(
                    Text("%ss" % ship_class.get_display_name(),
                         "small", (0, 0),
                         PICO_WHITE,
                         False,
                         multiline_width=105), V2(15 - iconoffset, y + 2))
                color = PICO_WHITE
                if maxxed:
                    color = PICO_RED
                self.add(
                    Text("%d" % planet.ships[ship], "small", (0, 0), color,
                         False), V2(108, y + 2))
                y += 15

        if planet.buildings and is_mine:
            self.add(Line(V2(0, 0), V2(120, 0), PICO_GREYPURPLE), V2(0, y))
            y += 5
            for i, building in enumerate(planet.buildings):
                x = (i % 4) * 29
                if (i % 4) == 0 and i > 0: y += 27
                s = UpgradeIcon(V2(0, 0), building['building'].upgrade.name,
                                None, True)
                self.add(s, V2(x + 3, y))

            y += 14

        self.redraw()
Exemplo n.º 18
0
class Scout(fighter.Fighter):
    SHIP_NAME = "scout"
    SHIP_BONUS_NAME = "scout"
    BASE_HEALTH = 15
    BASE_DAMAGE = 3
    FIRE_RATE = 0.5
    FIRE_RANGE = 36
    DOGFIGHTS = True
    BOMBS = True
    FUEL = 9999

    def __init__(self, scene, pos, owning_civ):
        super().__init__(scene, pos, owning_civ)
        self._set_player_ship_sprite_sheet()
        self.busters = 2
        self.max_busters = 2
        self.buster_time = 1.0
        self.states['siege']['enter'] = self.enter_state_siege
        self.comm_radius = 100
        self.owning_civ.comm_objects.append(self)

        self.buster_display = SimpleSprite(V2(0, 0), None)
        self.buster_display.offset = (0.5, 0)
        self.buster_display.layer = 5
        self._generate_buster_display()
        self.scene.game_group.add(self.buster_display)

        self.enter_stealth_time = 1

    def set_starting_busters(self, num):
        self.max_busters = num
        self.busters = num
        self._generate_buster_display()

    def _generate_buster_display(self):
        self.buster_display.image = pygame.Surface((3 * self.max_busters, 3),
                                                   pygame.SRCALPHA)
        self.buster_display._width, self.buster_display._height = self.buster_display.image.get_size(
        )
        for i in range(self.max_busters):
            pygame.draw.ellipse(self.buster_display.image, PICO_PURPLE,
                                (i * 3, 0, 3, 3))
            if i < self.busters:
                self.buster_display.image.set_at((i * 3 + 1, 1), PICO_PINK)
            else:
                self.buster_display.image.set_at((i * 3 + 1, 1), PICO_BLACK)
        self.buster_display._recalc_rect()

    def update(self, dt):
        if self.get_stat("scout_stealth") and not self.stealth:
            self.enter_stealth_time -= dt
            if self.enter_stealth_time < 0:
                self.stealth = True
                self.enter_stealth_time = 10

        self.buster_display.pos = self.pos + V2(0, 4)

        return super().update(dt)

    def fire(self, at):
        super().fire(at)
        self.enter_stealth_time = 10

    def wants_to_dogfight(self):
        if self.stealth:
            return False
        if not isinstance(self.effective_target, planet.Planet):
            return True
        if not self.effective_target.owning_civ or self.effective_target.owning_civ == self.owning_civ:
            return True
        if (self.effective_target.pos - self.pos).length_squared() > 100**2:
            return True
        if self.busters <= 0:
            return True
        return False

    def enter_state_siege(self):
        self.buster_time = 1.3

    def prepare_bullet_mods(self):
        mods = super().prepare_bullet_mods()
        mods['shape'] = 'circle'
        mods['size'] = 1
        mods['grey_goo'] = self.get_stat("grey_goo")
        return mods

    def state_siege(self, dt):
        super().state_siege(dt)
        if self.busters > 0 and isinstance(self.effective_target,
                                           planet.Planet):
            self.buster_time -= dt
            if self.buster_time <= 0:
                self.busters -= 1
                self.buster_time = 0.5
                ang = (self.effective_target.pos - self.pos).as_polar()[1]
                ang *= 3.14159 / 180
                rvel = helper.from_angle(ang + 3.14159 + random.random() - 0.5)
                b = bullet.Bullet(self.pos,
                                  self.effective_target,
                                  self,
                                  vel=rvel,
                                  mods={
                                      'homing': 0.5,
                                      'color': PICO_PINK,
                                      'missile_speed': -0.65,
                                      'life': 15,
                                      'kill_pop': 1,
                                      'shape': 'circle',
                                      'size': 2,
                                      'trail': PICO_PINK
                                  })
                self.scene.game_group.add(b)
                self._generate_buster_display()

    def emit_thrust_particles(self):
        pvel = V2(random.random() - 0.5, random.random() - 0.5) * 5
        pvel += -self.velocity / 2
        p = particle.Particle(
            [PICO_WHITE, PICO_BLUE], 1,
            self.pos + -helper.try_normalize(self.velocity) * self.radius, 2,
            pvel)
        self.scene.add_particle(p)

    def kill(self):
        self.buster_display.kill()
        return super().kill()
Exemplo n.º 19
0
    def __init__(self, galaxy, onclick, onsignal=None):
        Panel.__init__(self, V2(5, 5), galaxy)
        self.padding = 3  # ??
        self.galaxy = galaxy

        self.tab = {
            'text': "Sector %d" % galaxy.coords[0],
            'color': (0, 0, 0, 0)
        }

        if self.galaxy.signal:
            w = 165
        else:
            w = 145

        self.add(Line(V2(0, 0), V2(w, 0), PICO_RED), (V2(0, 0)))
        self.add(Rectangle(V2(0, 0), (w - 63, 16), PICO_RED), V2(63, 0))
        self.add(SimpleSprite(V2(0, 0), "assets/panel-enemy.png"), V2(7, 5))

        self.add(
            Text("Alien Sector",
                 "small", (0, 0),
                 PICO_WHITE,
                 False,
                 multiline_width=100), V2((w - 63) / 2 + 34, 3))
        if self.galaxy.signal == "future_tech":
            self.add(
                Text("Enemy: Unknown",
                     "small", (0, 0),
                     PICO_WHITE,
                     False,
                     multiline_width=100), V2(65, 23))
            self.add(
                Text("Has Future Tech!",
                     "small", (0, 0),
                     PICO_YELLOW,
                     False,
                     multiline_width=100), V2(65, 35))
        else:
            self.add(
                Text("Enemy: Unknown",
                     "small", (0, 0),
                     PICO_WHITE,
                     False,
                     multiline_width=100), V2(65, 28))

        self.add(Line(V2(0, 0), V2(w, 0), PICO_RED), (V2(0, 52)))
        self.add(Line(V2(0, 0), V2(w, 0), PICO_RED), (V2(0, 54)))

        self.add(
            Text("Victory Reward",
                 "tiny", (0, 0),
                 PICO_GREYPURPLE,
                 False,
                 multiline_width=200), V2(w / 2 - 30, 62))
        rh = 28
        self.add(Rectangle(V2(0, 0), (w, rh), PICO_GREYPURPLE), V2(0, 77))
        reward_icon = SimpleSprite(V2(0, 0),
                                   "assets/%s.png" % galaxy.rewards[0])
        reward_name = rewardscene.REWARDS[galaxy.rewards[0]]['title']
        reward_name = "\n".join([line for line in reward_name.split(" ")])
        reward_text = Text(reward_name,
                           "small", (0, 0),
                           PICO_WHITE,
                           False,
                           multiline_width=140,
                           center=False)
        reward_width = reward_text.width + 6 + reward_icon.width
        self.add(reward_icon,
                 V2(w / 2 - reward_width / 2, 91 - reward_icon.height / 2))
        self.add(
            reward_text,
            V2(w / 2 - reward_width / 2 + reward_icon.width + 6,
               91 - reward_text.height / 2 + 2))

        if galaxy.playable or game.DEV:
            lt = "START >"
            st = "DECODE ?"
            if game.Game.inst.input_mode == "joystick":
                lt = "[*x*] START >"
                st = "[*square*] DECODE ?"
            self.launch_button = Button(V2(0, 0),
                                        lt,
                                        'small',
                                        lambda: onclick(galaxy),
                                        color=PICO_PINK)
            self.signal_button = None
            if False and self.galaxy.signal:
                self.add(self.launch_button,
                         V2(w - self.launch_button.width - 5, 121))
                self.signal_button = Button(V2(0, 0),
                                            st,
                                            'small',
                                            lambda: onsignal(galaxy),
                                            color=PICO_BLUE)
                self.add(self.signal_button, V2(5, 121))
            else:
                self.add(self.launch_button,
                         V2(w / 2 - self.launch_button.width / 2, 121))

            self.add(Line(V2(0, 0), V2(w, 0), PICO_DARKBLUE), (V2(0, 146)))

        self.redraw()
Exemplo n.º 20
0
    def __init__(self, planet):
        Panel.__init__(self, (5,5), planet)
        self.planet = planet
        
        owner = "Neutral"
        color = PICO_YELLOW
        is_mine = False
        if planet.owning_civ:
            color = planet.owning_civ.color
            if planet.owning_civ.is_enemy:
                owner = "Enemy"
            else:
                owner = "Your"
                is_mine = True

        self.tab = {'text':'%s Planet' % owner, 'color':color, 'icon':'assets/i-planet.png'}
        self.add(Text("Resources", "small", (0,0), PICO_WHITE, False), V2(0,0))
        
        y = 15
        chart_data = {}
        for r in RESOURCES:
            pr = getattr(planet.resources, r)
            if pr:
                self.add(SimpleSprite((0,0), 'assets/i-%s.png' % r), V2(0,y))
                self.add(Text(r.title(), "small", (0,0), PICO_WHITE, False), V2(15,y+2))
                self.add(Text("%s%%" % pr, "small", (0,0), PICO_WHITE, False), V2(40,y+2))
                y += 15
                chart_data[RESOURCE_COLORS[r]] = pr
      
        self.add(PieChart((0,0), chart_data), V2(70, 10))

        y = max(y + 7, 41)
        self.add(Line(V2(0,0), V2(96, 0), PICO_WHITE),V2(0, y))
        y += 5

        self.add(SimpleSprite((0,0), 'assets/i-pop.png'), V2(34,y))
        color = PICO_WHITE
        if planet.population == 0 or planet.population >= planet.get_max_pop():
            color = PICO_YELLOW
        self.add(Text("%d/%d" %(planet.population, planet.get_max_pop()), "small", (0,0), color, False), V2(47,y+1))

        if planet.ships and is_mine:
            y += 14
            self.add(Line(V2(0,0), V2(96, 0), PICO_WHITE),V2(0, y))
            y += 4
            ships_alpha = sorted(planet.ships.keys())
            for ship in ships_alpha:
                if "alien" in ship:
                    continue
                if planet.ships[ship] <= 0:
                    continue
                try:
                    self.add(SimpleSprite((0,0), 'assets/i-%s.png' % ship), V2(0,y))
                except:
                    print("ERROR FINDING ICON FOR %s" % ship)
                    pass
                self.add(Text("%ss" % ship.title(), "small", (0,0), PICO_WHITE, False), V2(15,y + 2))
                color = PICO_WHITE
                if planet.ships[ship] > planet.get_max_fighters():
                    color = PICO_RED
                self.add(Text("%d" % planet.ships[ship], "small", (0,0), color, False), V2(88,y + 2))
                y += 15

        self.redraw()
Exemplo n.º 21
0
    def start(self):
        self.group = pygame.sprite.LayeredDirty()
        self.game_group = pygame.sprite.LayeredDirty()
        self.ui_group = pygame.sprite.LayeredDirty()
        
        self.time = 0

        galaxy = self.game.run_info.get_current_level_galaxy()
        self.galaxy = galaxy
        alien_code = galaxy['alien']
        alien_obj = alien.ALIENS[alien_code]
        self.nametext = typewriter.Typewriter(alien_obj.title, "huge", V2(50, 31) + self.game.game_offset, multiline_width=500, center=False, time_offset = -1)
        self.group.add(self.nametext)
        self.group.add(typewriter.Typewriter("ALIEN FORCES", "big", V2(50, 15) + self.game.game_offset, PICO_LIGHTGRAY, multiline_width=300, center=False))
        self.loading_text = Text("Loading...", "small", V2(game.RES[0] - 70, 326) + self.game.game_offset, center=False)
        self.loading_text.offset = (0.5, 0)
        self.group.add(self.loading_text)

        self.portrait = SimpleSprite(V2(50, 65) + self.game.game_offset, "assets/%sgraphic.png" % alien_code)
        pygame.draw.rect(self.portrait.image, PICO_BLACK, (0,0,self.portrait.width, self.portrait.height), 1)
        self.group.add(self.portrait)
        self.portrait.pos = (0,-1000)
        #self.portrait.visible = False

        self.tips = []
        self.quote = None

        difficulty_width = 150
        difficulty_pos = V2(game.RES[0] / 2 - difficulty_width / 2, 175) + self.game.game_offset

        if galaxy['difficulty'] > 1:
            difficulty_pos = V2(game.RES[0] * 0.3 - difficulty_width / 2, 215) + self.game.game_offset       

        labels = ['Mining Rate', 'Attack Power', 'Tech Level']
        images = ['econ', 'attack', 'tech']
        elements = []
        for i in range(3):
            pos = difficulty_pos + V2(0, i * 20)
            t = Text(labels[i], "small", pos + V2(60, 0), PICO_ORANGE)
            t.offset = (1,0)
            self.group.add(t)
            t.visible = False
            elements.append(t)
            maxelem = 5
            if i == 2: maxelem = 3
            for z in range(maxelem):
                f = FrameSprite(pos + V2(70 + z * 14, -3), "assets/enemystrength-%s.png" % images[i], 11)
                if z >= DIFFICULTY_VALUES[galaxy['difficulty']][i]:
                    f.frame = 1
                else:
                    f.frame = 0
                self.group.add(f)
                f.visible = False
                elements.append(f)

        self.tips.append(elements)

        if galaxy['difficulty'] > 1:
            tw = 150
            if galaxy['difficulty'] < 3: i = 0
            elif galaxy['difficulty'] < 6: i = 1
            else: i = 2
            tip = alien_obj.tips[i]
            x = game.RES[0] * 0.7
            img = pygame.image.load(resource_path(tip[0]))
            s = SimpleSprite(V2(x, 165) + self.game.game_offset, img)
            s.offset = (0.5, 0)
            self.group.add(s)
            t = Text(tip[1], "small", V2(x - tw / 2, 240) + self.game.game_offset, multiline_width=tw, center=False)
            self.group.add(t)
            s.visible = False
            t.visible = False
            r = rectangle.Rectangle(V2(x - tw / 2, 169) + self.game.game_offset, (19, 11), PICO_YELLOW)
            t2 = Text("TIP", "small", V2(x - tw / 2 + 2, 171) + self.game.game_offset, PICO_BLACK)
            r.visible = False
            t2.visible = False
            self.group.add(r)
            self.group.add(t2)
            self.tips.append((r, t2))
            self.tips.append((s, t))
        else:
            self.quote = Text(alien_obj.get_quote(), "pixolde", V2(game.RES[0] / 2, 270) + self.game.game_offset, PICO_YELLOW, multiline_width=400)
            self.quote.offset = (0.5, 0)
            self.group.add(self.quote)
            self.quote.visible = False


        if galaxy['mods']:
            self.group.add(SimpleSprite(V2(61, 322) + self.game.game_offset, "assets/exclamation.png"))
            self.group.add(Text("DANGER", "small", V2(79, 320) + self.game.game_offset, PICO_YELLOW, multiline_width=400, center=False))
            self.group.add(Text(MOD_STRINGS[galaxy['mods'][0]], "small", V2(79, 330) + self.game.game_offset, PICO_WHITE, multiline_width=400, center=False))
            self.warnings = self.group.sprites()[-3:]
            for warning in self.warnings:
                warning.visible = False

        self.sm = Machine(UIEnabledState(self))
        self.game.load_in_thread(self.load_level, self.on_loaded_level)
Exemplo n.º 22
0
class UpgradeState(UIEnabledState):
    def __init__(self, scene):
        UIEnabledState.__init__(self, scene)
        self.pending_upgrade = None
        self.cursor_type = None
        self.cursor_icon = None

    def enter(self):
        self.scene.paused = True
        self.panel = UpgradePanel(V2(0,0), self.scene.my_civ.upgrades[0], self.on_select)
        self.panel.add_all_to_group(self.scene.ui_group)
        self.panel.position_nicely(self.scene)
        self.hover_filter = self.filter_only_panel_ui
        super().enter()

    def exit(self):
        self.hover_filter = lambda x:True
        self.scene.paused = False
        if self.cursor_icon:
            self.cursor_icon.kill()

    def finish(self, target=None, cancel = False):
        if not cancel:
            self.scene.ui_group.add(FunNotification(self.pending_upgrade.title, target))
            self.scene.my_civ.upgrades.pop(0)
        if self.panel:
            self.panel.kill()
        self.scene.sm.transition(PlayState(self.scene))

    def on_select(self, upgrade):
        if upgrade.cursor == None:
            self.pending_upgrade = upgrade
            self.scene.my_civ.civ_upgrades.append(upgrade.name)
            upgrade().apply(self.scene.my_civ)
            self.finish()
        else:
            self.pending_upgrade = upgrade
            self.cursor_type = upgrade.cursor
            self.cursor_icon = SimpleSprite(V2(0,0), "assets/i-planet-cursor.png")
            self.cursor_icon.offset = (0.5, 0.5)
            self.cursor_icon._recalc_rect()
            self.scene.ui_group.add(self.cursor_icon)
            self.hover_filter = lambda x:(x.get_selection_info() and x.get_selection_info()['type'] == 'planet' and x.owning_civ == self.scene.my_civ)
            self.panel.kill()

    def take_input(self, input, event):
        super().take_input(input, event)
        if self.cursor_icon:
            if input in ["mouse_move", "mouse_drag"]:
                self.cursor_icon.pos = event.gpos + V2(10,10)

            if input == "click" and self.hover_sprite:
                sel = self.hover_sprite.get_selection_info()
                if sel and sel['type'] == "planet" and self.hover_sprite.owning_civ == self.scene.my_civ:
                    u = self.pending_upgrade().apply(self.hover_sprite)
                    self.finish(target=self.hover_sprite)
        else:
            if input == "click":
                pr = pygame.Rect(self.panel.x, self.panel.y, self.panel.width, self.panel.height)
                if not pr.collidepoint(event.gpos.tuple()):
                    self.finish(cancel = True)