def initialize_state(self): if self.level_file in tutorial.tutorials: self.sm = states.Machine( levelstates.Tutorial(self, tutorial.tutorials[self.level_file]())) else: self.sm = states.Machine(self.get_starting_state())
def start(self): self.background_group = pygame.sprite.LayeredDirty() self.game_group = pygame.sprite.LayeredDirty() self.ui_group = pygame.sprite.LayeredDirty() self.bg = newgamebackground.NewGameBackground(V2(0, 0)) self.background_group.add(self.bg) self.launch = None self.loading = False self.time = 0 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_ORANGE) self.ui_group.add(self.back) self.msg = tutorialmessage.TutorialMessage("") #self.msg.offset = (0.5, 1) self.msg.pos = V2(self.game.game_resolution.x / 2, self.game.game_resolution.y - 5) self.msg.add_all_to_group(self.ui_group) self.msg._reposition_children() self.msg.set_visible(False) #self.msg.fade_in() self.sm = states.Machine(states.UIEnabledState(self))
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.background_group = pygame.sprite.LayeredDirty() self.game_group = pygame.sprite.LayeredDirty() self.ui_group = pygame.sprite.LayeredDirty() self.game.player_inputs = [] self.player_index = 0 res = self.game.game_resolution self.instructions = text.Text( "Click or press START to join the battle!", "small", V2(res.x/2, 40), multiline_width=400, ) self.instructions.offset = (0.5, 0) self.ui_group.add(self.instructions) self.back = button.Button(V2(10,10), "[*circle*] Back", "big", self.on_back) self.ui_group.add(self.back) self.start_btn = button.Button(V2(res.x/2,res.y - 40), "[*x*] Ready", "big", None) self.start_btn.disabled = True self.start_btn.offset = (0.5, 0) self.start_btn.visible = False self.ui_group.add(self.start_btn) self.sm = states.Machine(MultiplayerUIState(self)) self.game.input_mode = game.Game.INPUT_MULTIPLAYER self.player_panels = [] self.mode = "add_players"
def start(self): self.background_group = pygame.sprite.LayeredDirty() self.game_group = pygame.sprite.LayeredDirty() self.ui_group = pygame.sprite.LayeredDirty() s = intelstate.IntelStateBase(self) s.on_back = self.on_back self.sm = states.Machine(s)
def start(self): self.background_group = pygame.sprite.LayeredDirty() self.game_group = pygame.sprite.LayeredDirty() self.ui_group = pygame.sprite.LayeredDirty() self.ignore_next_resize_event = False self.selected_item_index = 0 self.items = {} x = self.game.game_resolution.x / 2 - 120 y = self.game.game_resolution.y / 2 - 120 if not self.game.save.get_setting("fullscreen"): self.game.make_resizable(True) self.menumanager = menu.Menu(self, V2(x, y)) self.setup_menu() self.sm = states.Machine(states.UIEnabledState(self)) self.drag_notice = text.Text("Drag window corner to resize", "small", V2(self.game.game_resolution.x / 2 - 70, self.game.game_resolution.y - 20), PICO_YELLOW, multiline_width=300) self.ui_group.add(self.drag_notice) self.drag_notice.visible = not self.game.save.get_setting("fullscreen")
def start(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.sm = states.Machine(None) self.rewards = self.game.run_info.get_path_galaxy()['rewards'][::] if self.game.run_info.bonus_credits > 0: self.rewards.append("credits") self.num_rewards = len(self.rewards) self.setup_next_reward()
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)) ups = {} for cat in ['buildings', 'ships', 'tech']: ups[cat] = {} for res in ['iron', 'ice', 'gas']: ups[cat][res] = {} for uc in upgrades.UPGRADE_CLASSES.values(): if uc.alien: continue f = ups[uc.category][uc.resource_type] ft = uc.family['tree'] if ft in f: f[ft].append(uc) else: f[ft] = [uc] for ci, cat in enumerate(ups.keys()): category = ups[cat] self.game_group.add( Text(cat, "big", V2(ci * 180 + 10, 5), PICO_BLACK)) y = 25 for res in category.keys(): resource = category[res] self.game_group.add( Text(res, "small", V2(ci * 180 + 10, y), PICO_BLACK)) y += 10 for fam in ups[cat][res]: family = resource[fam] x = 0 for up in sorted(family, key=lambda x: int("".join( [i for i in x.name if i.isdigit()]))): self.game_group.add( UpgradeIcon(V2(ci * 180 + 10 + x, y), up.name, tooltip=True)) x += 25 y += 25 y += 10
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 initialize_state(self): self.sm = states.Machine(self.get_starting_state())
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))
def start(self): self.background_group = pygame.sprite.Group() self.game_group = pygame.sprite.LayeredDirty() self.ui_group = pygame.sprite.LayeredDirty() self.build_shop() self.sm = states.Machine(StoreState(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)