def __init__(self, state): BaseState.__init__(self) self.map = state.map self.bg = state.screen.copy() self.entry = TextEntry() self.widgets.append(self.entry) img = pygame.Surface((200, 100)) img.fill((20, 20, 20)) img.blit(FONT["small"].print_line("Enter map name:"), (20, 20)) pos = utils.center(img.get_size(), self.screen.get_size()) self.bg.blit(img, pos) self.entry.set_pos( utils.center(self.entry.get_size(), self.screen.get_size())) self.entry.draw(self.bg) self.add_kbevent(KEYDOWN, K_RETURN, callback=self.submit) self.add_kbevent(KEYDOWN, K_BACKSPACE, callback=self.entry.rem_char) self.add_kbevent(KEYDOWN, K_MINUS, callback=self.entry.add_char, arg="-") for k in xrange(97, 123): #letters self.add_kbevent(KEYDOWN, k, callback=self.entry.add_char, arg=pygame.key.name(k)) for k in xrange(48, 58): #numbers self.add_kbevent(KEYDOWN, k, callback=self.entry.add_char, arg=pygame.key.name(k))
def __init__(self, world, action_system, movement_system, free_actions_system, inventory_actions_system, inventory_pickup_system, vision_system, combat_system, damage_system, render_map_system, render_ui_system, render_blit_system, basic_ai_system, map_input_system, effects_system, essence_absorption_system, essence_drain_system, possession_system): systems = [ inventory_actions_system, # Execute inventory actions immediately on re-entry into this state essence_drain_system, effects_system, render_map_system, render_ui_system, render_blit_system, action_system, map_input_system, basic_ai_system, movement_system, free_actions_system, inventory_pickup_system, essence_absorption_system, vision_system, combat_system, possession_system, damage_system ] BaseState.__init__(self, world, systems)
def __init__(self, world, render_map_system, render_ui_system, render_look_system, render_blit_system, vision_system, target_input_system): systems = [ render_map_system, render_ui_system, render_look_system, render_blit_system, vision_system, target_input_system ] BaseState.__init__(self, world, systems)
def __init__(self, world, render_map_system, render_ui_system, render_inventory_system, render_blit_system, inventory_input_system, consoles): systems = [ render_map_system, render_ui_system, render_inventory_system, render_blit_system, inventory_input_system ] BaseState.__init__(self, world, systems) self.consoles = consoles self.consoles_inventory = consoles.layers["inventory"]
def __init__(self, world, render_map_system, render_ui_system, render_blit_system, vision_system, dead_input_system, free_actions_system, game_state, game_map): systems = [ render_map_system, render_ui_system, render_blit_system, vision_system, dead_input_system, free_actions_system ] BaseState.__init__(self, world, systems) self.game = game_state self.map = game_map
def __init__(self, world, render_menu_system, render_blit_system, menu_input_system, consoles, game_state): systems = [ render_menu_system, render_blit_system, menu_input_system ] BaseState.__init__(self, world, systems) self.consoles = consoles self.consoles_menu = consoles.layers["menu"] self.game = game_state
def pass_turn(self): """ Pass a game turn. """ for team in self.teams: for entity in self.team_entities[team]: self.move_entity(entity) self.turn += 1 self.state = BaseState(self)
def __init__(self, root_console): self.gui = GUI(root_console) self.game_console = tcod.console.Console(40, 40) self.state = BaseState(self) self.game_map = Map(self.game_console.width, self.game_console.height) self.teams = ["RED_TEAM", "BLUE_TEAM"] self.team_entities = {} for team in self.teams: self.team_entities[team] = [] self.place_team("RED_TEAM") self.place_team("BLUE_TEAM") self.turn = 0
def __init__(self, world, render_blit_system, generate_map_system): systems = [render_blit_system, generate_map_system] BaseState.__init__(self, world, systems)
def __init__(self, world, render_blit_system, save_system): systems = [render_blit_system, save_system] BaseState.__init__(self, world, systems)
def __init__(self, screen): BaseState.__init__(self) self.bg = screen.copy() filenames = os.listdir(MAP_PATH) filenames.sort() self.filenames = filenames self.page = 0 img = pygame.Surface((200, 220)) img.fill((20, 20, 20)) img.blit(FONT["small"].print_line("Select map:"), (20, 20)) pos = utils.center(img.get_size(), self.screen.get_size()) self.bg.blit(img, pos) x = 10 + pos[0] y_add = 30 + pos[1] self.map_buttons = [] for i in xrange(10): y = i * 15 + y_add button = TxtButton((180, 12), "", (20, 20, 100), callback=self.submit, arg="") button.set_pos((x, y)) button.draw(self.bg) self.widgets.append(button) self.map_buttons.append(button) self.show_buttons() button = TxtButton((50, 12), "prev", (20, 100, 20), callback=self.add_page, arg=-1) button.set_pos((10 + pos[0], y_add + 150)) button.draw(self.bg) self.widgets.append(button) button = TxtButton((50, 12), "next", (20, 100, 20), callback=self.add_page, arg=1) button.set_pos((10 + pos[0] + 130, y_add + 150)) button.draw(self.bg) self.widgets.append(button) button = TxtButton((50, 12), "Cancel", (100, 20, 20), callback=self.quit) button.set_pos((10 + pos[0], y_add + 170)) button.draw(self.bg) self.widgets.append(button) button = TxtButton((50, 12), "New map", (20, 20, 100), callback=self.new) button.set_pos((10 + pos[0] + 70, y_add + 170)) button.draw(self.bg) self.widgets.append(button) self.add_kbevent(KEYDOWN, K_ESCAPE, callback=self.quit)
def __init__(self, filename=""): BaseState.__init__(self) self.game = False self.from_reg = None if not filename: self.map = Map(self) else: path = os.path.join(MAP_PATH, filename) try: map_data = load_object(path) except: self.map = Map(self) print "Error loading map. Using default." self.map = Map(self, map_data) self.map.name = filename self.bg.blit(self.map, self.map.pos) self.widgets.extend(self.map.region.values()) self.ui = pygame.Surface((800, 600)) self.ui.fill((255, 0, 255)) self.ui.set_colorkey((255, 0, 255)) self.ui.blit(GFX["editor.png"], (0, 0)) #cycle faction button pos = (89, 555) size = FLAG["red_s"].get_size() button = ClickArea([pos, size], callback=self.change_color) self.widgets.append(button) #set town button x, y = (8, 560) size = (50, 10) button = TxtButton(size, "set_town", (255, 0, 0), callback=self.set_town) button.set_pos((x, y)) button.draw(self.ui) self.widgets.append(button) #set hq button x, y = (8, 575) size = (50, 10) button = TxtButton(size, "set_hq", (0, 0, 255), callback=self.set_hq) button.set_pos((x, y)) button.draw(self.ui) self.widgets.append(button) self.mode = None #select mode #delete button x, y = (675, 15) size = (100, 10) y_add = 20 button = TxtButton(size, "delete", (50, 50, 50), callback=self.set_mode, arg=0) button.set_pos((x, y)) button.draw(self.ui) self.widgets.append(button) #grey button y += y_add button = TxtButton(size, "grey", (150, 150, 150), callback=self.set_mode, arg=1) button.set_pos((x, y)) button.draw(self.ui) self.widgets.append(button) #red button y += y_add button = TxtButton(size, "red", (255, 0, 0), callback=self.set_mode, arg=2) button.set_pos((x, y)) button.draw(self.ui) self.widgets.append(button) #blue button y += y_add button = TxtButton(size, "blue", (0, 0, 255), callback=self.set_mode, arg=3) button.set_pos((x, y)) button.draw(self.ui) self.widgets.append(button) #save button x, y = 4, 3 button = NamedFlipButton("save", callback=self.save_map) button.changed = 1 self.add_button(button, (x, y), "save") self.widgets.append(button) #load button x += 65 button = NamedFlipButton("load", callback=self.to_load) button.changed = 1 self.add_button(button, (x, y), "load") self.widgets.append(button) #exit button x += 65 button = NamedFlipButton("exit", callback=self.close_game) button.changed = 1 self.add_button(button, (x, y), "exit") self.widgets.append(button) self.add_kbevent(KEYDOWN, K_UP, callback=self.move_map, arg=0) self.add_kbevent(KEYDOWN, K_DOWN, callback=self.move_map, arg=1) self.add_kbevent(KEYDOWN, K_LEFT, callback=self.move_map, arg=2) self.add_kbevent(KEYDOWN, K_RIGHT, callback=self.move_map, arg=3) #add troops button button = NamedFlipButton("troops", callback=self.to_build_menu, img4=True) button.changed = 1 self.add_button(button, (170, 565), "build") self.widgets.append(button) self.show_ui = 1 def toggle_ui(): self.show_ui = not self.show_ui self.add_kbevent(KEYUP, K_TAB, callback=toggle_ui)
def __init__(self, world, render_blit_system, game_state): systems = [render_blit_system] BaseState.__init__(self, world, systems) self.game = game_state