def __init__(self, panel, font, small_font): self.panel = panel self.font = font self.small_font = small_font self.x_cord_box = InputBox(pygame.Rect(75, 200, 200, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, message='0', text_color=Color.white, font=self.font, text_limit=10, allowed_characters=range(48, 58)) self.y_cord_box = InputBox(pygame.Rect(75, 250, 200, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, message='0', text_color=Color.white, font=self.font, text_limit=10, allowed_characters=range(48, 58)) self.generate_button = TextBox(pygame.Rect(125, 300, 100, 50), (20, 150, 30), Color.gray, highlight_color=Color.white, active_color=Color.blue, message=u'\u304D', text_color=Color.white, font=self.font)
class Warp(object): def __init__(self, panel, font, small_font): self.panel = panel self.font = font self.small_font = small_font self.x_cord_box = InputBox(pygame.Rect(75, 200, 200, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, message='0', text_color=Color.white, font=self.font, text_limit=10, allowed_characters=range(48, 58)) self.y_cord_box = InputBox(pygame.Rect(75, 250, 200, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, message='0', text_color=Color.white, font=self.font, text_limit=10, allowed_characters=range(48, 58)) self.generate_button = TextBox(pygame.Rect(125, 300, 100, 50), (20, 150, 30), Color.gray, highlight_color=Color.white, active_color=Color.blue, message=u'\u304D', text_color=Color.white, font=self.font) def draw(self, screen): Text.draw_text(screen, self.font, 'Warp to System', Color.white, (105, 14)) Text.draw_text(screen, self.font, 'X:', Color.white, (40, 200)) Text.draw_text(screen, self.font, 'Y:', Color.white, (40, 250)) self.x_cord_box.draw(screen) self.y_cord_box.draw(screen) self.generate_button.draw(screen) def update(self, key, mouse, offset=(0, 0)): self.x_cord_box.update(key, mouse, offset) self.y_cord_box.update(key, mouse, offset) # check for generate if self.generate_button.update(key, mouse, offset): if len(self.x_cord_box.message) != 0: x = int(self.x_cord_box.message) else: x = 0 if len(self.y_cord_box.message) != 0: y = int(self.y_cord_box.message) else: y = 0 self.panel.warp_to_system(x, y)
def __init__(self, size_x=16, size_y=16): self.big_font_size = 24 self.small_font_size = 16 self.font = pygame.font.Font(pygame.font.match_font('kaiti'), self.big_font_size) self.small_font = pygame.font.Font(pygame.font.match_font('kaiti'), self.small_font_size) self.name = 'Tyrra' self.crew = [Pawn()] self.panel_mode = 'stats' self.ship_grid = ShipGrid(self, size_x, size_y) self.ship_preview = self.ship_grid.preview_window self.stat_screen = ShipStats(self, self.font, self.small_font) self.crew_profile = CrewProfile(self, self.crew[0], self.font, self.small_font) self.main_screen = ShipMainScreen(self.stat_screen, self.ship_grid, self.crew_profile) self.box = Box(self.get_ship_rect(), border_color=Color.blue, highlight_color=Color.green, active_color=Color.red, name='Ship Hit Box') # easy dictionary to store stats probably self.ship_stats = {'crew_capacity': 1, 'attack': 0, 'armor': 0, 'speed': 0, 'power': 0, 'shield': 0, 'component_capacity': 4} self.current_shield = 0 # objects are drawn on side bar self.name_box = InputBox(pygame.Rect(70, 10, 250, 50), box_color=None, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.gray, message=self.name, text_color=Color.white, font=self.font, text_limit=16) # nav self.stats_button = TextBox(pygame.Rect(25, 70, 80, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.d_blue, message='Stats', text_color=Color.white, text_outline=True, font=self.font) self.edit_button = TextBox(pygame.Rect(120, 70, 80, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.d_blue, message='Edit', text_color=Color.white, text_outline=True, font=self.font) self.crew_button = TextBox(pygame.Rect(210, 70, 80, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.d_blue, message='Crew', text_color=Color.white, text_outline=True, font=self.font) # floors self.floor_dictionary = {'blank': 0, 'floor': 1, 'armor': 2, 'engine': 3, 'gun': 4, 'power': 5, 'shield': 7} self.floor_stats = {'blank': (0, 0, 0, 0), 'floor': (0, -1, -1, -1), 'armor': (0, 10, -2, 0), 'engine': (0, 0, 10, -5), 'gun': (10, 0, -1, -5), 'power': (0, 0, -1, 10), 'shield': (0, 0, 0, -10)} self.floors = [] self.floors.append(Box(pygame.Rect(25, 140, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='blank')) self.floors.append(Box(pygame.Rect(55, 140, 25, 25), Color.gray, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='floor')) self.floors.append(Box(pygame.Rect(85, 140, 25, 25), Color.d_gray, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='armor')) self.ship_grid.selected_cell_type = self.floor_dictionary['blank'] # Parts self.floors.append(TextBox(pygame.Rect(25, 180, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='engine', message='E1', text_color=Color.blue, text_outline=True, font=self.small_font)) self.floors.append(TextBox(pygame.Rect(55, 180, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='gun', message='G1', text_color=Color.red, text_outline=True, font=self.small_font)) self.floors.append(TextBox(pygame.Rect(85, 180, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='power', message='P1', text_color=Color.green, text_outline=True, font=self.small_font)) # components (inventory / installed are actual objects; lists are just the text boxes) self.selected_component = None self.component_inventory = [] self.component_list = [] self.installed_components = [] self.installed_list = [] self.make_installed_component_list() # debug load button self.load_box = TextBox(pygame.Rect(230, 610, 75, 40), Color.blue, border_color=Color.gray, highlight_color=Color.white, active_color=Color.white, message='LOAD', text_color=Color.white, text_outline=True, font=self.font) # debug save button self.save_box = TextBox(pygame.Rect(230, 650, 75, 40), Color.red, border_color=Color.gray, highlight_color=Color.white, active_color=Color.white, message='SAVE', text_color=Color.white, text_outline=True, font=self.font) # crew screen self.crew_list = [] self.make_crew_list()
class Ship(object): def __init__(self, size_x=16, size_y=16): self.big_font_size = 24 self.small_font_size = 16 self.font = pygame.font.Font(pygame.font.match_font('kaiti'), self.big_font_size) self.small_font = pygame.font.Font(pygame.font.match_font('kaiti'), self.small_font_size) self.name = 'Tyrra' self.crew = [Pawn()] self.panel_mode = 'stats' self.ship_grid = ShipGrid(self, size_x, size_y) self.ship_preview = self.ship_grid.preview_window self.stat_screen = ShipStats(self, self.font, self.small_font) self.crew_profile = CrewProfile(self, self.crew[0], self.font, self.small_font) self.main_screen = ShipMainScreen(self.stat_screen, self.ship_grid, self.crew_profile) self.box = Box(self.get_ship_rect(), border_color=Color.blue, highlight_color=Color.green, active_color=Color.red, name='Ship Hit Box') # easy dictionary to store stats probably self.ship_stats = {'crew_capacity': 1, 'attack': 0, 'armor': 0, 'speed': 0, 'power': 0, 'shield': 0, 'component_capacity': 4} self.current_shield = 0 # objects are drawn on side bar self.name_box = InputBox(pygame.Rect(70, 10, 250, 50), box_color=None, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.gray, message=self.name, text_color=Color.white, font=self.font, text_limit=16) # nav self.stats_button = TextBox(pygame.Rect(25, 70, 80, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.d_blue, message='Stats', text_color=Color.white, text_outline=True, font=self.font) self.edit_button = TextBox(pygame.Rect(120, 70, 80, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.d_blue, message='Edit', text_color=Color.white, text_outline=True, font=self.font) self.crew_button = TextBox(pygame.Rect(210, 70, 80, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.d_blue, message='Crew', text_color=Color.white, text_outline=True, font=self.font) # floors self.floor_dictionary = {'blank': 0, 'floor': 1, 'armor': 2, 'engine': 3, 'gun': 4, 'power': 5, 'shield': 7} self.floor_stats = {'blank': (0, 0, 0, 0), 'floor': (0, -1, -1, -1), 'armor': (0, 10, -2, 0), 'engine': (0, 0, 10, -5), 'gun': (10, 0, -1, -5), 'power': (0, 0, -1, 10), 'shield': (0, 0, 0, -10)} self.floors = [] self.floors.append(Box(pygame.Rect(25, 140, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='blank')) self.floors.append(Box(pygame.Rect(55, 140, 25, 25), Color.gray, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='floor')) self.floors.append(Box(pygame.Rect(85, 140, 25, 25), Color.d_gray, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='armor')) self.ship_grid.selected_cell_type = self.floor_dictionary['blank'] # Parts self.floors.append(TextBox(pygame.Rect(25, 180, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='engine', message='E1', text_color=Color.blue, text_outline=True, font=self.small_font)) self.floors.append(TextBox(pygame.Rect(55, 180, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='gun', message='G1', text_color=Color.red, text_outline=True, font=self.small_font)) self.floors.append(TextBox(pygame.Rect(85, 180, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='power', message='P1', text_color=Color.green, text_outline=True, font=self.small_font)) # components (inventory / installed are actual objects; lists are just the text boxes) self.selected_component = None self.component_inventory = [] self.component_list = [] self.installed_components = [] self.installed_list = [] self.make_installed_component_list() # debug load button self.load_box = TextBox(pygame.Rect(230, 610, 75, 40), Color.blue, border_color=Color.gray, highlight_color=Color.white, active_color=Color.white, message='LOAD', text_color=Color.white, text_outline=True, font=self.font) # debug save button self.save_box = TextBox(pygame.Rect(230, 650, 75, 40), Color.red, border_color=Color.gray, highlight_color=Color.white, active_color=Color.white, message='SAVE', text_color=Color.white, text_outline=True, font=self.font) # crew screen self.crew_list = [] self.make_crew_list() def add_crew(self, crew): self.crew.append(crew) self.make_crew_list() self.crew_profile.pawn = self.crew[0] def make_crew_list(self): del self.crew_list[:] y_offset = 0 for pawn in self.crew: self.crew_list.append(TextBox(pygame.Rect(50, 150+y_offset, 250, 40), box_color=Color.gray, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=2, message=pawn.name, text_color=Color.white, text_outline=True, font=self.font)) y_offset += 55 def add_component(self, component): self.component_inventory.append(component) self.make_component_list() def make_component_list(self): del self.component_list[:] y_offset = 0 for component in self.component_inventory: self.component_list.append(TextBox(pygame.Rect(25, 150+y_offset, 250, 40), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.red, active_color=Color.gray, border=2, name=self.component_inventory.index(component), message=component.name, text_color=Color.white, text_outline=True, font=self.font)) y_offset += 55 def install_component(self, index): if self.component_inventory[index].component_type is not 'empty': self.installed_components.append(index) self.make_installed_component_list() def remove_component(self, index): if len(self.installed_components) > index: del self.installed_components[index] self.make_installed_component_list() def make_installed_component_list(self): del self.installed_list[:] for i in range(1, self.ship_stats['component_capacity'] + 1): if len(self.installed_components) > i - 1: index = self.installed_components[i - 1] self.installed_list.append(TextBox(pygame.Rect(25, 250 + ((i - 1) * 50), 300, 40), Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, border=2, name=i, message=self.component_inventory[index].name, text_color=Color.gray, text_outline=True, font=self.font)) else: self.installed_list.append(TextBox(pygame.Rect(25, 250+((i-1)*50), 300, 40), Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, border=2, name=i, message='EMPTY {0}'.format(i), text_color=Color.gray, text_outline=True, font=self.font)) def update(self, key, mouse, offset=(0, 0)): self.name_box.update(key, mouse, offset) if self.stats_button.update(key, mouse, offset): self.panel_mode = 'stats' self.main_screen.mode = 'stats' if self.edit_button.update(key, mouse, offset): self.panel_mode = 'edit' self.main_screen.mode = 'edit' if self.crew_button.update(key, mouse, offset): self.panel_mode = 'crew' self.main_screen.mode = 'crew' if self.panel_mode is 'component': self.update_component_panel(key, mouse, offset) elif self.panel_mode is 'edit': self.update_edit_panel(key, mouse, offset) elif self.panel_mode is 'crew': self.update_crew_panel(key, mouse, offset) # self.ship_grid.update(key=key, mouse=mouse) # get stats self.update_stats() def update_edit_panel(self, key, mouse, offset=(0, 0)): for tile in self.floors: tile.update(key, mouse, offset) if tile.active: self.ship_grid.selected_cell_type = self.floor_dictionary[tile.name] self.ship_grid.selected_cell_stats = self.floor_stats[tile.name] for component in self.installed_list: if component.update(key, mouse, offset): self.selected_component = component.name-1 self.panel_mode = 'component' if self.load_box.update(key, mouse, offset): self.load('{0}data/save.shp'.format(settings.main_path)) if self.save_box.update(key, mouse, offset): self.save('{0}data/save.shp'.format(settings.main_path)) def update_component_panel(self, key, mouse, offset=(0, 0)): for component in self.component_list: if len(self.component_inventory) > 0: index = int(component.name) else: index = 0 if index not in self.installed_components: if component.update(key, mouse, offset): print "index is {0}".format(index) self.remove_component(index) self.install_component(index) self.panel_mode = 'edit' def update_crew_panel(self, key, mouse, offset=(0, 0)): for crew in self.crew_list: if crew.update(key, mouse, offset): for pawn in self.crew: if pawn.name == crew.message: if self.crew_profile is not None: self.crew_profile.pawn = pawn break def update_stats(self): attack, armor, speed, power = self.ship_grid.get_stats() self.ship_stats['attack'] = attack self.ship_stats['armor'] = armor self.ship_stats['speed'] = speed self.ship_stats['power'] = power self.ship_stats['shield'] = 0 for index in self.installed_components: component = self.component_inventory[index] if component.stats: for stat, value in component.stats.iteritems(): if stat in self.ship_stats: self.ship_stats[stat] += value # reset shield HP self.current_shield = self.ship_stats['shield'] def draw(self, screen): screen.fill(Color.black) self.name_box.draw(screen) self.stats_button.draw(screen) self.edit_button.draw(screen) self.crew_button.draw(screen) if self.panel_mode is 'edit': self.draw_edit_panel(screen) elif self.panel_mode is 'component': self.draw_component_panel(screen) elif self.panel_mode is 'crew': self.draw_crew_panel(screen) def draw_crew_panel(self, screen): for box in self.crew_list: box.draw(screen) def draw_edit_panel(self, screen): Text.draw_text(screen, self.small_font, 'Floors:', Color.white, position=(25, 110)) for tile in self.floors: tile.draw(screen) Text.draw_text(screen, self.small_font, 'Components:', Color.white, position=(25, 220)) for box in self.installed_list: box.draw(screen) self.load_box.draw(screen) self.save_box.draw(screen) Text.draw_text(screen, self.small_font, 'Preview:', Color.white, position=(25, 460)) Text.draw_text(screen, self.small_font, 'Attack:', Color.red, position=(230, 485)) Text.draw_text(screen, self.small_font, self.ship_stats['attack'], Color.red, position=(300, 485)) Text.draw_text(screen, self.small_font, 'Armor:', Color.gray, position=(230, 510)) Text.draw_text(screen, self.small_font, self.ship_stats['armor'], Color.gray, position=(300, 510)) Text.draw_text(screen, self.small_font, 'Speed:', Color.blue, position=(230, 535)) Text.draw_text(screen, self.small_font, self.ship_stats['speed'], Color.blue, position=(300, 535)) Text.draw_text(screen, self.small_font, 'Power:', Color.yellow, position=(230, 560)) Text.draw_text(screen, self.small_font, self.ship_stats['power'], Color.yellow, position=(300, 560)) Text.draw_text(screen, self.small_font, 'Shield:', Color.green, position=(230, 585)) Text.draw_text(screen, self.small_font, self.ship_stats['shield'], Color.green, position=(300, 585)) self.ship_preview.draw_border(screen) self.ship_preview.draw(screen) def draw_component_panel(self, screen): Text.draw_text(screen, self.small_font, 'Components:', Color.white, position=(25, 110)) for component in self.component_list: component.draw(screen) def draw_ship(self, screen, position, color=None, zoom=2): if color is None: color = Color.white self.box.rect = self.get_ship_rect(position=position, zoom=zoom) # self.ship_grid.update_bounds() x = 0 for row in self.ship_grid.grid[self.ship_grid.ship_bounds['left']:self.ship_grid.ship_bounds['right']+1]: y = 0 for node in row[self.ship_grid.ship_bounds['top']:self.ship_grid.ship_bounds['bottom']+1]: if node.type is not 0: pygame.draw.rect(screen, color, pygame.Rect(position[0] + x*zoom, position[1] + y*zoom, zoom, zoom)) y += 1 x += 1 # self.box.draw(screen) def get_ship_rect(self, position=None, zoom=1): self.ship_grid.update_bounds() if position is None: position = (0, 0) return pygame.Rect(position[0], position[1], self.get_ship_size(zoom)[0], self.get_ship_size(zoom)[1]) def get_ship_size(self, zoom=1): self.ship_grid.update_bounds() w = (self.ship_grid.ship_bounds['right'] - self.ship_grid.ship_bounds['left'] + 1) * zoom h = (self.ship_grid.ship_bounds['bottom'] - self.ship_grid.ship_bounds['top'] + 1) * zoom return w, h def load(self, file_name): try: with open(file_name) as data_file: data = json.load(data_file) self.name_box.message = data['NAME'] index = 0 for row in self.ship_grid.grid: for node in row: node.type = data['GRID'][index][0] node.set_stats(data['GRID'][index][1]) index += 1 # components del self.component_inventory[:] self.make_component_list() self.add_component(Component('empty', name='REMOVE')) if "C_INV" in data: for inventory in data["C_INV"]: self.add_component(Component(component_type=inventory["TYPE"], name=inventory["NAME"], stats=inventory["STATS"])) del self.installed_components[:] if "C_ACT" in data: self.installed_components = data["C_ACT"] self.make_installed_component_list() # crew del self.crew[:] if "CREW" in data: for crew in data["CREW"]: self.add_crew(Pawn(name=crew["NAME"], age=crew["AGE"], race=crew["RACE"], bio=crew["BIO"], profile=crew["PICTURE"], ship_skills=crew["SKILLS"], battle_skills=crew["STATS"])) self.update_stats() except Exception as e: print "Failed to load ship file {0} : {1}".format(file_name, e) def save(self, file_name): dump = {'NAME': self.name_box.message} grid = [] for row in self.ship_grid.grid: for node in row: grid.append((node.type, node.get_stats())) dump['GRID'] = grid # components component_list = [] for component in self.component_inventory: if self.component_inventory.index(component) != 0: component_list.append(component.component_dict()) dump["C_INV"] = component_list dump["C_ACT"] = self.installed_components # crew crew_list = [] for crew in self.crew: crew_list.append(crew.get_data()) dump["CREW"] = crew_list with open(file_name, 'w') as outfile: json.dump(dump, outfile) print 'saved to file'
def __init__(self, big_font, font, small_font, screen_height=800, screen_width=600): self.big_font = big_font self.font = font self.small_font = small_font self.box = Box(pygame.Rect(int(screen_width * 0.1), int(screen_height * 0.1), int(screen_width * 0.8), int(screen_height * 0.8)), box_color=Color.black, border_color=Color.white, border=4, highlight_box=False, name='Character Creation Box') box_x = self.box.rect.x box_y = self.box.rect.y # build portrait roster self.portrait_roster = [] self.portrait_index = 0 for face in os.listdir(settings.face_path): if face.endswith('.png'): path = os.path.join(settings.face_path, face) self.portrait_roster.append({"PATH": path, "IMAGE": pygame.image.load(path)}) for face in os.listdir(settings.mod_path): if face.endswith('.png'): path = os.path.join(settings.mod_path, face) self.portrait_roster.append({"PATH": path, "IMAGE": pygame.image.load(path)}) self.portrait = None self.portrait_box = Box(pygame.Rect(int(box_x + self.box.rect.width / 10), int(box_y + self.box.rect.height / 7), 250, 250), box_color=Color.black, border_color=Color.white, highlight_box=False, name='Portrait Box') self.update_roster_portrait_box() self.left_portrait = TextBox(pygame.Rect(self.portrait_box.rect.x - 35, self.portrait_box.rect.y + self.portrait_box.rect.height/3, 25, 40), box_color=Color.d_gray, border_color=Color.white, highlight_color=Color.gray, active_color=Color.white, name='p_left', message='<', text_color=Color.white, text_outline=True, font=self.font) self.right_portrait = TextBox(pygame.Rect(self.portrait_box.rect.x + self.portrait_box.rect.width + 10, self.portrait_box.rect.y + self.portrait_box.rect.height/3, 25, 40), box_color=Color.d_gray, border_color=Color.white, highlight_color=Color.gray, active_color=Color.white, name='p_right', message='>', text_color=Color.white, text_outline=True, font=self.font) # character name self.name = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/7, 400, 35), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='Flash', text_color=Color.white, font=self.font, text_limit=32) # character age self.age = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/2.7, 70, 35), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='25', text_color=Color.white, font=self.font, text_limit=5, allowed_characters=range(48, 58)) # character race self.race = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/4, 400, 35), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='Human', text_color=Color.white, font=self.font, text_limit=32) # character bio self.bio = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/2, 400, 50), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='A little bit about myself', text_color=Color.white, font=self.font, text_limit=300) # profession stuff self.profession_list = ['Pilot', 'Guns', 'Engineer', 'Medic', 'Scientist'] self.profession = TextBox(pygame.Rect(self.portrait_box.rect.x + self.portrait_box.rect.width/2, self.portrait_box.rect.y + self.portrait_box.rect.width + 20, 100, 20), highlight_color=Color.white, active_color=Color.gray, border=0, name='Profession', message=self.profession_list[0], text_color=Color.gray, font=self.small_font, highlight_box=False, highlight_text=True) self.skills = {} self.update_profession_stats() # done self.done = TextBox(pygame.Rect(box_x + self.box.rect.width - 150, box_y + self.box.rect.height - 100, 100, 50), box_color=Color.red, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, name='done', message='START', text_color=Color.white, text_outline=True, font=self.font)
class CreateCharacter(object): def __init__(self, big_font, font, small_font, screen_height=800, screen_width=600): self.big_font = big_font self.font = font self.small_font = small_font self.box = Box(pygame.Rect(int(screen_width * 0.1), int(screen_height * 0.1), int(screen_width * 0.8), int(screen_height * 0.8)), box_color=Color.black, border_color=Color.white, border=4, highlight_box=False, name='Character Creation Box') box_x = self.box.rect.x box_y = self.box.rect.y # build portrait roster self.portrait_roster = [] self.portrait_index = 0 for face in os.listdir(settings.face_path): if face.endswith('.png'): path = os.path.join(settings.face_path, face) self.portrait_roster.append({"PATH": path, "IMAGE": pygame.image.load(path)}) for face in os.listdir(settings.mod_path): if face.endswith('.png'): path = os.path.join(settings.mod_path, face) self.portrait_roster.append({"PATH": path, "IMAGE": pygame.image.load(path)}) self.portrait = None self.portrait_box = Box(pygame.Rect(int(box_x + self.box.rect.width / 10), int(box_y + self.box.rect.height / 7), 250, 250), box_color=Color.black, border_color=Color.white, highlight_box=False, name='Portrait Box') self.update_roster_portrait_box() self.left_portrait = TextBox(pygame.Rect(self.portrait_box.rect.x - 35, self.portrait_box.rect.y + self.portrait_box.rect.height/3, 25, 40), box_color=Color.d_gray, border_color=Color.white, highlight_color=Color.gray, active_color=Color.white, name='p_left', message='<', text_color=Color.white, text_outline=True, font=self.font) self.right_portrait = TextBox(pygame.Rect(self.portrait_box.rect.x + self.portrait_box.rect.width + 10, self.portrait_box.rect.y + self.portrait_box.rect.height/3, 25, 40), box_color=Color.d_gray, border_color=Color.white, highlight_color=Color.gray, active_color=Color.white, name='p_right', message='>', text_color=Color.white, text_outline=True, font=self.font) # character name self.name = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/7, 400, 35), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='Flash', text_color=Color.white, font=self.font, text_limit=32) # character age self.age = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/2.7, 70, 35), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='25', text_color=Color.white, font=self.font, text_limit=5, allowed_characters=range(48, 58)) # character race self.race = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/4, 400, 35), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='Human', text_color=Color.white, font=self.font, text_limit=32) # character bio self.bio = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/2, 400, 50), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='A little bit about myself', text_color=Color.white, font=self.font, text_limit=300) # profession stuff self.profession_list = ['Pilot', 'Guns', 'Engineer', 'Medic', 'Scientist'] self.profession = TextBox(pygame.Rect(self.portrait_box.rect.x + self.portrait_box.rect.width/2, self.portrait_box.rect.y + self.portrait_box.rect.width + 20, 100, 20), highlight_color=Color.white, active_color=Color.gray, border=0, name='Profession', message=self.profession_list[0], text_color=Color.gray, font=self.small_font, highlight_box=False, highlight_text=True) self.skills = {} self.update_profession_stats() # done self.done = TextBox(pygame.Rect(box_x + self.box.rect.width - 150, box_y + self.box.rect.height - 100, 100, 50), box_color=Color.red, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, name='done', message='START', text_color=Color.white, text_outline=True, font=self.font) def return_character(self): pawn = Pawn(name=self.name.message, age=self.age.message, race=self.race.message, bio=self.bio.message, profile=self.portrait_roster[self.portrait_index]["PATH"], battle_skills=self.skills) pawn.ship_skills[self.profession.message] = 1 return pawn def update_roster_portrait_box(self): self.portrait = self.portrait_roster[self.portrait_index]["IMAGE"] self.portrait_box.image = self.portrait def update_profession_stats(self): if self.profession.message == 'Pilot': self.skills = {'Melee': 2, 'Ranged': 1, 'Defense': 1, 'Intelligence': 1, 'Speed': 1} elif self.profession.message == 'Guns': self.skills = {'Melee': 1, 'Ranged': 2, 'Defense': 1, 'Intelligence': 1, 'Speed': 1} elif self.profession.message == 'Engineer': self.skills = {'Melee': 1, 'Ranged': 1, 'Defense': 1, 'Intelligence': 1, 'Speed': 2} elif self.profession.message == 'Medic': self.skills = {'Melee': 1, 'Ranged': 1, 'Defense': 2, 'Intelligence': 1, 'Speed': 1} elif self.profession.message == 'Scientist': self.skills = {'Melee': 1, 'Ranged': 1, 'Defense': 1, 'Intelligence': 2, 'Speed': 1} def update(self, key, mouse, offset=(0, 0)): if self.portrait_index > 0 and self.left_portrait.update(key=key, mouse=mouse, offset=offset): self.portrait_index -= 1 self.update_roster_portrait_box() if self.portrait_index < len(self.portrait_roster)-1 \ and self.right_portrait.update(key=key, mouse=mouse, offset=offset): self.portrait_index += 1 self.update_roster_portrait_box() self.name.update(key=key, mouse=mouse, offset=offset) self.age.update(key=key, mouse=mouse, offset=offset) self.race.update(key=key, mouse=mouse, offset=offset) self.bio.update(key=key, mouse=mouse, offset=offset) # if self.profession.update(key=key, mouse=mouse, offset=offset): if self.profession.message == self.profession_list[-1]: self.profession.message = self.profession_list[0] else: self.profession.message = self.profession_list[self.profession_list.index(self.profession.message)+1] self.update_profession_stats() # if self.done.update(key=key, mouse=mouse, offset=offset): return self.return_character() return def draw(self, screen): self.box.draw(screen) # non-interactive title = 'Create Your Character' title_width = self.big_font.size(title)[0] Text.draw_text(screen, self.big_font, text=title, color=Color.blue, position=(self.box.rect.x+(self.box.rect.width - title_width)/2, self.box.rect.y + 5)) Text.draw_text(screen, self.small_font, text='Name:', color=Color.green, position=(self.name.rect.x, self.name.rect.y - 20)) Text.draw_text(screen, self.small_font, text='Race:', color=Color.green, position=(self.race.rect.x, self.race.rect.y - 20)) Text.draw_text(screen, self.small_font, text='Age:', color=Color.green, position=(self.age.rect.x, self.age.rect.y - 20)) Text.draw_text(screen, self.small_font, text='Biography:', color=Color.green, position=(self.bio.rect.x, self.bio.rect.y - 20)) # profession box Text.draw_text(screen, self.small_font, text='Profession:', color=Color.l_gray, position=(self.portrait_box.rect.x, self.profession.rect.y)) # stats i = 25 for key, value in self.skills.iteritems(): Text.draw_text(screen, self.small_font, text=key, color=Color.l_gray, position=(self.portrait_box.rect.x, self.profession.rect.y + i)) Text.draw_text(screen, self.small_font, text=value, color=Color.l_gray, position=(self.portrait_box.rect.x + self.portrait_box.rect.width/2, self.profession.rect.y + i)) i += 25 # buttons and things self.portrait_box.draw(screen) self.left_portrait.draw(screen) self.right_portrait.draw(screen) # boxes self.name.draw(screen) self.race.draw(screen) self.age.draw(screen) self.bio.draw(screen) # self.profession.draw(screen) # self.done.draw(screen)