def fire(self, scene): scene.sm.transition(levelstates.TankFireState(scene, self)) dx,dy = OFFSETS_FROM_DIRS[self.last_move_direction] self.fire_obj = framesprite.FrameSprite("assets/tankfire.png", 12) self.fire_obj.set_frame(self.last_move_direction) scene.ui_group.add(self.fire_obj) off = (0,0) if self.last_move_direction == 0: off = (-2, -9) elif self.last_move_direction == 1: off = (0, -8) elif self.last_move_direction == 2: off = (2, -9) elif self.last_move_direction == 3: off = (0, -4) self.fire_obj.move((self.gx + dx) * game.TILESIZE + off[0], (self.gy + dy) * game.TILESIZE + off[1]) self.step_animation = self.post_fire_step_animation self.set_frame(self._frame // 2 + 8) self.bullet_obj = framesprite.FrameSprite("assets/tankshell.png", 8) self.bullet_obj.set_frame(self.last_move_direction) scene.ui_group.add(self.bullet_obj) off = (0,0) if self.last_move_direction == 0: off = (-2, -6) elif self.last_move_direction == 1: off = (2, -8) elif self.last_move_direction == 2: off = (2, -6) elif self.last_move_direction == 3: off = (2, 0) self.bullet_obj.move((self.gx + dx) * game.TILESIZE + off[0], (self.gy + dy) * game.TILESIZE + off[1]) sound.play("tankfire")
def enter(self): self.scene.load() self.tileselect = framesprite.FrameSprite("assets/objects.png", 12) self.scene.ui_group.add(self.tileselect) self.decoselect = framesprite.FrameSprite("assets/tiles.png", 12) self.scene.ui_group.add(self.decoselect) self.decoselect.rect = (0, 12, self.decoselect.rect[2], self.decoselect.rect[3]) self.decoselect.set_frame(15) self.deco = 0
def add_star(self, filled): x = len(self.stars) * 32 + 120 - 45 y = 163 s = framesprite.FrameSprite("assets/bigstar.png", 29) s.set_frame((0, 1)[filled]) s.move(x, y) self.stars.append(s) self.scene.ui_group.add(s)
def add_anim(self, img, width, frames, pos): s = framesprite.FrameSprite(img, width) self.group.add(s) s._image_name = img s.allowed_frames = frames s.allowed_frame_index = 0 s.set_frame(frames[0]) s.move(*pos) self.animated.append(s)
def enter(self): sound.play("factory") self.num_steps = 0 w = self.scene.snake[0] self.scene.game_group.add(w) self.scene.animatedsprites.append(w) self.flag = framesprite.FrameSprite("assets/flag.png", 12) self.scene.game_group.add(self.flag) self.scene.animatedsprites.append(self.flag) self.steps = text.Text("0", "small", (0, 0)) self.scene.ui_group.add(self.steps) self.position_extras() self.enemies_to_control = [] self.cell_arrow = framesprite.FrameSprite("assets/cellarrow.png", 9) self.cell_arrow.move(-10, -10) self.scene.ui_group.add(self.cell_arrow) self.scene.animatedsprites.append(self.cell_arrow) self.update_steps()
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 load(self): gx, gy = game.RES[0] // game.TILESIZE, game.RES[1] // game.TILESIZE self.tilemap = tilemap.Tilemap( game.TILESIZE, gx, gy, pygame.image.load( resource_path("assets/tiles.png")).convert_alpha()) self.background_group = pygame.sprite.Group() self.background_group.add(self.tilemap) self.game_group = pygame.sprite.LayeredUpdates() self.ui_group = pygame.sprite.Group() self.tutorial_group = pygame.sprite.Group() self.tanks = [] self.overlay = framesprite.FrameSprite("assets/gameoverlay.png", 240) self.ui_group.add(self.overlay) self.worker_queue = tilemap.Tilemap( 12, 20, 1, pygame.image.load( resource_path("assets/workericon.png")).convert_alpha()) self.worker_queue.rect = (2, 1, 240, 12) self.ui_group.add(self.worker_queue) self.animatedsprites = [] self.road_grid = [] self.object_grid = [] self.factories = [] self.cityhalls = [] for row in range(gy): self.object_grid.append([]) self.road_grid.append([]) for col in range(gx): self.object_grid[-1].append(None) self.road_grid[-1].append(False) try: self.tilemap.load("levels/%s_tiles.csv" % self.level_file) self.load_objects("levels/%s_objects.csv" % self.level_file) except Exception as e: traceback.print_exc() self.tilemap.load("levels/empty_tiles.csv") self.load_objects("levels/empty_objects.csv") self.level_file = "empty" self.queued_workers = 0 self.start_tile = None
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 enter(self): self.selection = framesprite.FrameSprite("assets/cursor.png", 16) self.scene.ui_group.add(self.selection) self.scene.animatedsprites.append(self.selection) self.update_selection()
def update_selection(self): (lvl, name1, name2, pos, *extras) = LEVELS[self.selected_level] name2 = "%d - %s" % (self.selected_level + 1, name2) self.scroll = SCROLLS[name1] self.arrow.move(pos[0] - self.scroll[0] - 13, pos[1] - self.scroll[1] - 18) self.back_group.remove(self.popup_sprites) self.popup_sprites = [] y = self.scroll[1] + 10 w, h = (text.FONTS['big'].get_rect(name1)[2] + 12, 50) w2 = text.FONTS['small'].get_rect(name2)[2] + 12 w = max(w, w2, 120) fw = w + 43 x = self.scroll[0] + 120 - fw / 2 city = text.Text(name1, "big", (x + 5, y + 5), color=(game.BGCOLOR), border=False) background = pygame.sprite.Sprite() background.image = pygame.Surface((fw, h)) background.rect = (x, y, background.image.get_size()[0] + 10, background.image.get_size()[1]) background.image.fill(game.FGCOLOR) pygame.draw.rect(background.image, game.FGCOLOR, (0, 0, w, h)) pygame.draw.rect(background.image, game.BGCOLOR, (w, 1, fw - w - 1, h - 2)) pygame.draw.rect(background.image, game.BGCOLOR, (1, 1, w - 2, h - 2), 1) desc = text.Text(name2, "small", (x + 5, y + 21), color=(game.BGCOLOR), border=False) self.popup_sprites.append(background) self.popup_sprites.append(city) self.popup_sprites.append(desc) savestate = self.game.save.get_level_state(self.selected_level) for i in range(3): star = framesprite.FrameSprite("assets/star.png", 13) star.move(x + 6 + i * 15, y + 32) if i < savestate['stars']: star.set_frame(1) self.popup_sprites.append(star) if savestate['beaten']: steptext = "%d Steps" % savestate['steps'] stepwidth = text.FONTS['small'].get_rect(steptext)[2] steps = text.Text(steptext, "small", (x + w - 6 - stepwidth, y + 35), color=(game.BGCOLOR), border=False) self.popup_sprites.append(steps) self.make_minimap(x + w, y + 7) self.back_group.add(self.popup_sprites) city_index = CITIES.index(name1) if name1 == CITIES[0]: self.prev_text.set_pos(0, -20) else: self.prev_text.set_text("< " + CITIES[city_index - 1]) self.prev_text.set_pos(5, 160) if name1 == CITIES[-1]: self.next_text.set_pos(0, -20) else: self.next_text.set_text(CITIES[city_index + 1] + " >") self.next_text.set_pos(235 - self.next_text.rect[2], 160)