def next_cursor(self): if not self.cursors_remaining: apply_upgrade_with_target(self.civ, self.up, self.targets) self.scene.finish_player_upgrade(self.civ) self.scene.get_civ_sm(self.civ).transition( CursorState(self.scene, self.civ, self.input_mode)) return self.current_cursor = self.cursors_remaining.pop(0) if self.cursor_icon: self.cursor_icon.kill() if self.joystick_overlay: self.joystick_overlay.set_button_options(["[*x*] Apply Upgrade"]) if self.current_cursor == "allied_planet": self.cursor_icon = simplesprite.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) if self.current_cursor == "any_planet": self.cursor_icon = simplesprite.SimpleSprite( V2(0, 0), "assets/i-planet-cursor.png") self.hover_filter = self.filter_any_planets elif self.current_cursor == "allied_fleet": self.scene.fleet_managers[self.civ].generate_selectable_objects() self.cursor_icon = simplesprite.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 self.current_cursor == "point": self.cursor_icon = simplesprite.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 self.current_cursor == "nearby": self.cursor_icon = simplesprite.SimpleSprite( V2(0, 0), "assets/i-point-cursor.png") self.range = rangeindicator.RangeIndicator(self.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)
def start(self): self.background_group = pygame.sprite.Group() self.game_group = pygame.sprite.LayeredDirty() self.ui_group = pygame.sprite.LayeredDirty() self.sm = states.Machine(states.UIEnabledState(self)) self.bg = simplesprite.SimpleSprite(self.game.game_offset, "assets/intro-sm-1.png") self.bg.image = upscale.pixel(self.bg.image, 4) self.bg.pos = V2( self.game.game_resolution.x / 2 - self.bg.image.get_width() / 2, self.game.game_resolution.y / 2 - self.bg.image.get_height() / 2) self.background_group.add(self.bg) self.mockup = text.Text("Mockup Art", "big", V2(30, 30)) self.ui_group.add(self.mockup) self.stage = 0 self.time = 0 self.tutorial_speed = 1 self.tut = TutorialMessage("") self.tut.pos = V2(self.game.game_resolution.x / 2 - 172, self.game.game_resolution.y - 54) self.tut._reposition_children() self.ui_group.add(self.tut) self.tut.add_all_to_group(self.ui_group) self.tut.set_visible(False)
def start(self): self.group = pygame.sprite.Group() bg = simplesprite.SimpleSprite("assets/menubg.png", (0,0)) self.group.add(bg) self.selected_item_index = 0 self.items = {} self.items['start'] = text.Text("START", "small", (20, 75)) self.items['music'] = text.Text("MUSIC", "small", (20, 90)) self.items['sound'] = text.Text("SOUND", "small", (20, 105)) self.items['resolution'] = text.Text("RESOLUTION", "small", (20, 120)) self.items['credits'] = text.Text("CREDITS", "small", (20, 135)) self.items['exit'] = text.Text("EXIT", "small", (20, 150)) self.item_names = list(self.items.keys()) for item in self.items.values(): self.group.add(item) self.update_selection() self.music_meter = simplesprite.SimpleSprite("assets/settingmeter.png", (80, 89)) self.group.add(self.music_meter) self.sound_meter = simplesprite.SimpleSprite("assets/settingmeter.png", (80, 104)) self.group.add(self.sound_meter) self.resolution_display = text.Text("1x1", "small", (100, 120)) self.group.add(self.resolution_display) self.update_settings() sound.play_music("overworld") self.animated = [] self.add_anim("assets/flag.png", 12, [0,1,2,3], (24,12)) self.add_anim("assets/worker.png", 12, [2,3], (24,18)) self.add_anim("assets/factory.png", 12, [0,1,2], (12,18)) self.add_anim("assets/factory.png", 12, [0,1,2], (12,28)) self.add_anim("assets/police.png", 12, [4,5], (168,30)) self.add_anim("assets/police.png", 12, [2,3], (168 + 24,30 +24)) self.add_anim("assets/soldier.png", 14, [0,1], (144, 150)) self.add_anim("assets/soldier.png", 14, [0,1], (144, 162)) self.timer = 0
def click_new(self): #self.game.scene = newgamescene.NewGameScene(self.game) #self.game.scene.start() self.takeoff_earth = simplesprite.SimpleSprite(V2(0, 0)) self.takeoff_earth.base_image = pygame.Surface( self.game.game_resolution, pygame.SRCALPHA) self.takeoff_earth.base_image.blit(self.bg_earth.image, self.bg_earth.pos) self.takeoff_earth.base_image.blit(self.bg_enemies.image, self.bg_enemies.pos) self.takeoff_earth.image = self.takeoff_earth.base_image self.game_group.add(self.takeoff_earth) self.mode = MODE_TAKEOFF self.logo.kill()
def start(self): self.scroll = (0, 0) self.back_group = pygame.sprite.Group() self.fore_group = pygame.sprite.Group() self.levelobjs = [] self.map = simplesprite.SimpleSprite("assets/worldmaplayout.png", (0, 0)) self.back_group.add(self.map) for i, level in enumerate(LEVELS): x, y = level[3][0], level[3][1] obj = framesprite.FrameSprite("assets/mapflag copy.png", 12) if self.game.save.get_level_state(i)['beaten']: obj.set_frame(1) obj.move(x - 6, y - 10) self.levelobjs.append((obj, level)) self.back_group.add(obj) self.popup_sprites = [] self.arrow = framesprite.FrameSprite("assets/selectarrow.png", 11) self.arrow.move(-11, -11) self.animated.append(self.arrow) self.fore_group.add(self.arrow) self.next_text = text.Text(">", "small", (0, -20)) self.prev_text = text.Text("<", "small", (0, -20)) self.fore_group.add(self.next_text) self.fore_group.add(self.prev_text) overlay = simplesprite.SimpleSprite("assets/mapoverlay.png", (0, 0)) self.fore_group.add(overlay) self.selected_level = self.starting_level_index self.update_selection() self.flash_index = 0 sound.play_music('overworld')
def __init__(self, save): pygame.display.set_icon(pygame.image.load(resource_path("assets/icon_2_256.png"))) pygame.mixer.pre_init(buffer=512) pygame.init() self.save = save self.scaled_screen = pygame.display.set_mode((RES[0] * SCALE, RES[1] * SCALE)) pygame.display.set_caption("Picket Puzzle") sound.init() self.screen = pygame.Surface(RES) if len(sys.argv) > 1 and DEV: if sys.argv[1] == 'credits': self.scene = creditsscene.CreditsScene(self) else: self.scene = levelscene.LevelScene(self, sys.argv[1]) else: self.scene = alphascene.AlphaScene(self) self.playing_level_index = None self.vignette = simplesprite.SimpleSprite("assets/vignette.png", (0,0))
def create_mods_ui(self): self.mods_controls = [] TITLES = { 'fragile_planets': 'Fragility', 'low_range': 'Fuel Crisis', 'worker_loss': 'Perilous Frontier', 'low_oxygen': 'Oxygen Leak', 'small_army': 'Skeleton Crew', 'terraform': 'Barysi Terraform', 'hacking': 'Network Hack', 'void': 'Void Beacon', 'timeloop': 'Time Loop', } BODIES = { 'fragile_planets': 'Your planets have [!-75% health]. [^+10% Score]', 'low_range': 'All ships have [!limited fuel]. [Fighters] have [!-35% fuel]. [^+10% Score]', 'worker_loss': 'Worker ships [!lose 1 population] when launched. [^+10% Score]', 'low_oxygen': 'Start with [!-50% Oxygen]. [^+10% Score]', 'small_army': 'Maximum army size is [!10]. [^+10% Score]', 'terraform': 'Capturing a planet converts [^30%] of its [Iron] to [Ice] or [Gas]. Requires [!+1 challenge]', 'hacking': '33% chance to [^gain control] of an enemy ship if you destroy it in deep space. Requires [!+1 challenge]', 'void': 'Your planets eminate a [^Void Field]. Requires [!+1 challenge]', 'timeloop': 'In each sector, +3 random planets are time looped. Requires [!+2 challenges]', } REQS = { 'fragile_planets': 1, 'low_range': 2, 'worker_loss': 4, 'low_oxygen': 6, 'small_army': 10, 'terraform': 1, 'hacking': 3, 'void': 7, 'timeloop': 15 } x1 = self.game.game_resolution.x / 2 - (((31 * 5) + (4 * 4)) / 2) y1 = self.game.game_resolution.y / 2 bg = simplesprite.SimpleSprite(V2(x1, y1), "assets/mods_bg.png") self.ui_group.add(bg) ct1 = text.Text("Modifiers", "small", V2(x1 - 10, y1 + 9), multiline_width=100) ct1.offset = (1, 0) self.ui_group.add(ct1) self.modifiers_info = text.Text("0", "small", V2(x1 - 10, y1 + 20), PICO_GREEN, multiline_width=100) self.modifiers_info.offset = (1, 0) self.ui_group.add(self.modifiers_info) ct2 = text.Text("Challenges", "small", V2(x1 - 10, y1 + 63), multiline_width=100) ct2.offset = (1, 0) self.ui_group.add(ct2) self.challenges_info = text.Text("0/0", "small", V2(x1 - 10, y1 + 74), PICO_GREEN, multiline_width=100) self.challenges_info.offset = (1, 0) self.ui_group.add(self.challenges_info) self.negative_mods = [] self.positive_mods = [] for i, nm in enumerate([ 'fragile_planets', 'low_range', 'worker_loss', 'low_oxygen', 'small_army' ]): def make_onclick(nm): return lambda *args: self.click_challenge(nm, *args) x = x1 + i * 35 + 3 y = y1 + 56 title = "Locked" body = "Victories to unlock: %d" % REQS[nm] if self.game.save.victories >= REQS[nm]: title = TITLES[nm] body = BODIES[nm] b = ModifierButton(nm, V2(x, y), "assets/mod_%s.png" % nm, make_onclick(nm), title, body) if self.game.save.victories >= REQS[nm]: b.set_state("disabled") self.ui_group.add(b) self.negative_mods.append(b) for i, nm in enumerate(['terraform', 'hacking', 'void', 'timeloop']): def make_onclick(nm): return lambda *args: self.click_modifier(nm, *args) x = x1 + i * 35 + 3 y = y1 + 3 title = "Locked" body = "Victories to unlock: %d" % REQS[nm] if self.game.save.victories >= REQS[nm]: title = TITLES[nm] body = BODIES[nm] b = ModifierButton(nm, V2(x, y), "assets/mod_%s.png" % nm, make_onclick(nm), title, body) if self.game.save.victories >= REQS[nm]: b.set_state("disabled") self.ui_group.add(b) self.positive_mods.append(b) self.continue_button = button.Button( V2(self.game.game_resolution.x / 2, y1 + 100), "Continue to mission", "small", self.click_continue_to_mission) self.continue_button.offset = (0.5, 0) self.ui_group.add(self.continue_button) self.mods_controls = [ self.positive_mods, self.negative_mods, [self.continue_button] ]
def start(self): self.joy = joyresolver.JoyResolver(self.on_joy_press) self.set_starting_button = False self.background_group = pygame.sprite.LayeredDirty() self.game_group = pygame.sprite.LayeredDirty() self.ui_group = pygame.sprite.LayeredDirty() self.parallax = [] self.stars = [] self.choices = [] self.current_choice = 2 self.using_joy = True self.mode = MODE_START self.takeoff_time = 0 self.run_challenges = [] self.run_modifiers = [] minx = -200 miny = -200 maxx = self.game.game_resolution.x + 200 maxy = self.game.game_resolution.y + 200 for i in range(320): s = framesprite.FrameSprite( V2(random.randint(minx, maxx), random.randint(miny, maxy)), "assets/bgstar.png", 11) s.frame = 4 + random.randint(0, 1) self.background_group.add(s) self.parallax.append(Parallaxed(s, 0.05)) self.stars.append(s) for i in range(90): s = framesprite.FrameSprite( V2(random.randint(minx, maxx), random.randint(miny, maxy)), "assets/bgstar.png", 11) s.frame = 2 + random.randint(0, 1) self.background_group.add(s) self.parallax.append(Parallaxed(s, 0.1)) self.stars.append(s) for i in range(40): s = framesprite.FrameSprite( V2(random.randint(minx, maxx), random.randint(miny, maxy)), "assets/bgstar.png", 11) s.frame = 0 + random.randint(0, 1) self.background_group.add(s) self.parallax.append(Parallaxed(s, 0.2)) self.stars.append(s) earth_pos = self.game.game_offset + V2(120, 140) self.bg_earth = simplesprite.SimpleSprite(earth_pos, "assets/title-earth.png") self.game_group.add(self.bg_earth) self.parallax.append(Parallaxed(self.bg_earth, 1)) self.bg_enemies = IntelOption(self, earth_pos + V2(-165, 7), "assets/title-enemies.png", 251, onclick=self.click_intel) self.game_group.add(self.bg_enemies) self.bg_enemies.visible = False self.choices.append(self.bg_enemies) res = self.game.game_resolution self.bg_multiplayer = MultiplayerOption(self, V2(res.x * 0.2, res.y / 8), "assets/title-multiplayer.png", 58, onclick=self.click_multiplayer) self.parallax.append(Parallaxed(self.bg_multiplayer, 0.15)) self.game_group.add(self.bg_multiplayer) self.choices.append(self.bg_multiplayer) self.bg_multiplayer.visible = False self.bg_continue = None if self.game.run_info.started: self.bg_continue = ContinueOption(self, V2(res.x * 0.4, res.y / 8), "assets/title-continue.png", frame_width=109, onclick=self.click_continue) self.parallax.append(Parallaxed(self.bg_continue, 0.05)) self.game_group.add(self.bg_continue) self.choices.append(self.bg_continue) self.bg_newgame_path = simplesprite.SimpleSprite( earth_pos + V2(150, -32), "assets/title-newgame-path.png") self.bg_newgame_path.visible = False self.game_group.add(self.bg_newgame_path) self.bg_newgame = NewGameOption(self, earth_pos + V2(265, -39), "assets/title-newgame-ship.png", onclick=self.click_new) self.bg_newgame.visible = False self.game_group.add(self.bg_newgame) self.choices.append(self.bg_newgame) self.bg_options = OptionsOption(self, V2(res.x * 3 / 4, res.y * 0.55), "assets/title-options.png", onclick=self.click_options) self.parallax.append(Parallaxed(self.bg_options, 1.5)) self.game_group.add(self.bg_options) self.choices.append(self.bg_options) self.bg_options.visible = False self.bg_exit = ExitOption(self, V2(res.x * 0.7, res.y * 0.8), "assets/title-exit.png", onclick=self.click_exit) self.parallax.append(Parallaxed(self.bg_exit, 5)) self.game_group.add(self.bg_exit) self.choices.append(self.bg_exit) self.bg_exit.visible = False self.logo = hqlogo.HQLogo(earth_pos + V2(89, 103), delay=6.25) self.logo.offset = (0.5, 0.5) self.game_group.add(self.logo) l = MenuOptionLabel( self.bg_enemies.pos + V2(78, -2) + V2(22, -6) + V2(-4, -4), self.bg_enemies.pos + V2(78, -2) + V2(-4, -4), "Intel") self.bg_enemies.label = l self.ui_group.add(l) l = MenuOptionLabel( self.bg_multiplayer.pos + V2(-28, -2) + V2(-22, -6) + V2(-4, -4), self.bg_multiplayer.pos + V2(-28, -2) + V2(-4, -4), "Multiplayer") self.bg_multiplayer.label = l self.ui_group.add(l) if self.bg_continue: l = MenuOptionLabel( self.bg_continue.pos + V2(18, 22) + V2(42, -24) + V2(-4, -4), self.bg_continue.pos + V2(18, 22) + V2(-4, -4), "Continue") self.bg_continue.label = l self.ui_group.add(l) t = "New Game" if self.game.save.victories > 0: t = "New Game [^+]" l = MenuOptionLabel( self.bg_newgame.pos + V2(38, 26) + V2(22, 6) + V2(-4, -4), self.bg_newgame.pos + V2(38, 26) + V2(-4, -4), t) self.bg_newgame.label = l self.ui_group.add(l) l = MenuOptionLabel( self.bg_options.pos + V2(-30, 2) + V2(-22, -3) + V2(-4, -4), self.bg_options.pos + V2(-30, 2) + V2(-4, -4), "Options") self.bg_options.label = l self.ui_group.add(l) l = MenuOptionLabel( self.bg_exit.pos + V2(9, 16) + V2(22, 1) + V2(-4, -4), self.bg_exit.pos + V2(9, 16) + V2(-4, -4), "Exit") self.bg_exit.label = l self.ui_group.add(l) x = 340 * (self.game.game_resolution.x / game.RES[0]) y = self.game.game_resolution.y / 2 - 50 if self.game.first_load: self.game.first_load = False self.time = 0 else: self.skip_intro() self.sm = states.Machine(states.UIEnabledState(self))
def setup_players(self): self.meters = {} # Make a civ for each player for i in range(self.num_players): uipos = UI_POSITIONS[self.num_players][i] if uipos.x == 1: uipos.x = self.game.game_resolution.x - 104 if uipos.y == 1: uipos.y = self.game.game_resolution.y - 60 c = civ.MultiplayerCiv(self, uipos) c.worker_loss = 1 c.color = PLAYER_COLORS[i] c.name = PLAYER_NAMES[i] self.player_civs.append(c) self.player_input_sms[i] = states.Machine( inputstates.CursorState(self, c, self.game.player_inputs[i].input_type)) self.player_game_speed_inputs[c] = 0 self.meters[c] = {} for j, r in enumerate(['iron', 'ice', 'gas']): self.meters[c][r] = meter.Meter(V2(uipos.x + 19, uipos.y + 3 + j * 14), 80, 9, economy.RESOURCE_COLORS[r], c.upgrade_limits.data[r], tick_x=120) self.meters[c][r].stay = True self.ui_group.add( simplesprite.SimpleSprite( V2(uipos.x + 6, uipos.y + 2 + j * 14), "assets/i-%s.png" % r)) self.ui_group.add(self.meters[c][r]) bp = None if uipos.x < self.game.game_resolution.x / 2: bp = V2(uipos.x + 110, uipos.y + 5) else: bp = V2(uipos.x - 50, uipos.y + 5) ub = button.Button( bp, "Up", "small", (lambda c: (lambda: self.player_mouse_click_upgrade(c)) )(c), # Closure to capture civ None, None, "assets/i-iron.png", PICO_LIGHTGRAY, fixed_width=46) ub.visible = False self.ui_group.add(ub) self.player_upgrade_buttons[i] = ub ut = text.Text("", "small", bp + V2(24, 22), shadow=PICO_BLACK) ut.offset = (0.5, 0) self.ui_group.add(ut) self.player_upgrade_texts[i] = ut # target target = text.Text("", "small", uipos + V2(6, 44), shadow=PICO_BLACK, multiline_width=200) self.ui_group.add(target) self.player_targets[i] = target self.radar = Explosion(V2(300, 180), [PICO_GREEN], 1.25, self.game.game_resolution.x) self.ui_group.add(self.radar)
def add_ui_elements(self): self.meters = {} self.upgrade_texts = {} for i, r in enumerate(self.player_civ.resources.data.keys()): self.meters[r] = Meter(V2(19, 3 + i * 14), 120, 9, RESOURCE_COLORS[r], self.player_civ.upgrade_limits.data[r], tick_x=120) self.meters[r].stay = True self.ui_group.add( simplesprite.SimpleSprite(V2(6, 2 + i * 14), "assets/i-%s.png" % r)) self.ui_group.add(self.meters[r]) self.upgrade_texts[r] = Text("", "small", V2(144, 4 + i * 14), multiline_width=200) self.ui_group.add(self.upgrade_texts[r]) self.player_civ.resources.on_change(self.on_civ_resource_change) # Set up blueprint and memory crystal buttons self.saved_upgrade_buttons = {} upy = 50 def make_reward_icon(frame, h): img = FrameSprite(V2(3, upy), "assets/reward_icons.png", 23) img.frame = frame self.ui_group.add(img) self.ui_group.add( Line(V2(2, upy + 12), V2(7, upy + 12), PICO_YELLOW)) self.ui_group.add( Line(V2(2, upy + 11), V2(2, upy + h), PICO_YELLOW)) if self.game.run_info.saved_technologies: make_reward_icon( 2, len(self.game.run_info.saved_technologies) * 27 + 17) upy += 17 for u in self.game.run_info.saved_technologies: upicon = UpgradeIcon(V2(3, upy), u, self.on_click_saved_upgrade, tooltip=True) self.saved_upgrade_buttons[u] = upicon self.ui_group.add(upicon) upy += 27 if self.game.run_info.blueprints: upy += 10 make_reward_icon(3, len(self.game.run_info.blueprints) * 27 + 17) upy += 17 for u in self.game.run_info.blueprints: upicon = UpgradeIcon(V2(3, upy), u, self.on_click_saved_upgrade, tooltip=True) self.saved_upgrade_buttons[u] = upicon self.ui_group.add(upicon) upy += 27 if game.DEV: self.ui_group.add( Button( V2(self.game.game_resolution.x - 50, self.game.game_resolution.y - 20), 'Win', 'small', self.dev_win)) self.ui_group.add( Button( V2(self.game.game_resolution.x - 110, self.game.game_resolution.y - 20), 'Lose', 'small', self.dev_lose)) self.player_ship_info = CivShipUI( V2(self.game.game_resolution.x - 70, 24), self.player_civ) #self.ui_group.add(self.player_ship_info) self.player_pop_info = text.Text("Ships: 0/0", "small", V2(self.game.game_resolution.x - 6, 24), PICO_WHITE, shadow=PICO_BLACK) self.player_pop_info.offset = (1, 0) self.ui_group.add(self.player_pop_info) self.o2_meter = o2meter.O2Meter(V2(self.game.game_resolution.x - 86, 6)) if self.options == "oxygen": self.game.run_info.o2 = 0 self.o2_meter.o2 = self.game.run_info.o2 self.o2_meter._generate_image() self.ui_group.add(self.o2_meter) self.stage_name = stagename.StageName(V2(0, 100), self.stage_num, self.title, self.description) self.ui_group.add(self.stage_name) if self.title == "": self.stage_name.kill() self.upkeep_indicator = upkeepindicator.UpkeepIndicator(self) #self.ui_group.add(self.upkeep_indicator) self.pause_sprite = pauseoverlay.PauseOverlay() self.pause_sprite.layer = 5 self.ui_group.add(self.pause_sprite) self.game.game_speed_input = 0