def __init__(self, options, scene): """Initialise the EzMenu! options should be a sequence of lists in the format of [option_name, option_function]""" self.scene = scene self.options = options self.x = 0 self.y = 0 self.hx = 0 self.hy = 0 self.centerx = 0 self.centery = 0 self.font = pygame.font.Font(None, 18) self.option = 0 self.width = 1 self.color = [0, 0, 0] self.hcolor = [255, 0, 0] self.height = len(self.options) * self.font.get_height() self.font.set_italic(True) self.help_text = DrawableFontObject("", self.font) self.font.set_italic(False) self.font_list = [] self.scene.addObject(self.help_text) for o in self.options: ren = self.font.render(o[0], 1, self.color) self.font_list.append(DrawableFontObject(o[0], self.font)) if self.width < ren.get_width(): self.width = ren.get_width() self.scene.addObjects(self.font_list)
def __init__(self, callback): GameEngineElement.__init__(self, has_draw=True, has_event=False) self.menu = None self.callback = callback self.background = DrawableObject( [pygame.image.load(MENU_PATH + "battleMenubackground.gif")], '') self.font = pygame.font.SysFont("cmr10", 18, False, False) self.disp = DrawableFontObject("", self.font) self.sec_disp = DrawableFontObject("", self.font) self.add_to_scene([self.background]) self.add_to_scene([self.disp]) self.add_to_scene([self.sec_disp])
def __init__(self, recall_string=None, name_entry_cb=None): GameEngineElement.__init__(self) self.name = "" self.dungeon_id = "al1.txt" self.position = (-1, -1) self.playerFacing = NORTH self.hero = Hero() # 4 types of stats and difficulties self.problem_stats = {} self.difficulty = {} for stat in ['mult', 'div', 'geo', 'shop']: # Each type of stat has 3 "levels" easy, medium, hard # Shop uses level for too much, too little, exact self.problem_stats[stat] = [(0, 0), (0, 0), (0, 0)] #Difficulty: 1=Easy 2=Meduim(default) 3=Hard self.difficulty[stat] = 2 self.puzzlesSolved = 0 self.inventory = [] bg = pygame.image.load(MENU_PATH + "mafh_splash.gif").convert() self.background = DrawableObject([bg], '') self.background.scale(self.game_engine.width, self.game_engine.height) self.add_to_scene([self.background]) #create background rect draw_width = self.game_engine.width / 4 draw_height = self.game_engine.height / 4 surf = pygame.Surface((draw_width + 60, draw_height + 60)) surf.fill((150, 150, 255)) self.blueRect = DrawableObject([surf], "") self.add_to_scene([self.blueRect]) font = pygame.font.Font(None, 16) self.text_list = [] self.text_list.append(DrawableFontObject("1", font)) self.text_list.append(DrawableFontObject("2", font)) self.text_list.append(DrawableFontObject("name", font)) self.add_to_scene(self.text_list) if recall_string: self.load_from_json_string(recall_string) if self.name == "": self.name_cb = name_entry_cb self.add_to_engine()
def __init__(self, options, cols, scene, x=237, y=375): """Initialize the EzMenu! options should be a sequence of lists in the format of [option_name, option_function]""" self.options = options self.scene = scene self.x = x self.y = y self.cols = cols self.font = pygame.font.SysFont("cmr10", 18, False, False) self.option = 0 self.width = 1 self.color = [0, 0, 0] self.hcolor = [255, 0, 0] self.height = len(self.options) * self.font.get_height() self.font_list = [] self.rect_list = [] for o in self.options: self.font_list.append(DrawableFontObject(o[0], self.font)) ren = self.font.render(o[0], 1, [0, 0, 0]) if ren.get_width() > self.width: self.width = ren.get_width() i = 0 # Row Spacing h = 0 # Selection Spacing j = 0 # Col Spacing for o in self.options: newX = self.x + 45 * j newY = self.y + i * 45 surf = pygame.Surface((o[2], 44)) surf.fill((0, 74, 94)) tempDO = DrawableObject([surf], "") tempDO.setPosition(newX, newY) self.rect_list.append(tempDO) surf = pygame.Surface((o[2] - 4, 40)) surf.fill((4, 119, 152)) tempDO = DrawableObject([surf], "") tempDO.setPosition(newX + 2, newY + 2) self.rect_list.append(tempDO) j += o[3] h += 1 if j >= self.cols: i += 1 j = 0 self.scene.addObjects(self.rect_list) self.scene.addObjects(self.font_list)
def __init__(self, x, y, width, height, lines): GameEngineElement.__init__(self, has_draw=True, has_event=False) self.max_lines = lines self.x = x self.y = y surf = pygame.Surface((int(width), int(height))) surf.fill([0, 0, 0]) self.box = DrawableObject([surf], "") self.box.setPosition(int(x), int(y)) self.font = pygame.font.Font(None, 28) self.__lines = [] for i in range(lines): self.__lines.append(DrawableFontObject('', self.font)) self.add_to_scene([self.box]) self.add_to_scene(self.__lines) self.add_to_engine()