示例#1
0
    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)
示例#2
0
 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])
示例#3
0
 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])
示例#4
0
    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()
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
    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()
示例#8
0
class EzMenu():
    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 draw(self):
        """Draw the menu to the surface."""
        i = 0
        help_txt = ""
        for o in self.options:
            if i == self.option:
                clr = self.hcolor
                help_txt = o[2]
            else:
                clr = self.color
            text = o[0]
            self.font_list[i].changeText(text, clr)
            self.font_list[i].setPosition(self.x,
                                          self.y + i * self.font.get_height())
            i += 1

        # Help Text
        self.help_text.changeText(help_txt, self.color)
        self.help_text.setPosition(self.hx + 5, self.hy)

    def update(self, event):
        """Update the menu and get input for the menu."""
        return_val = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_DOWN:
                self.option += 1
                return_val = True
            elif event.key == pygame.K_UP:
                self.option -= 1
                return_val = True
            elif event.key == pygame.K_RETURN:
                self.options[self.option][1]()
                return_val = True

        if self.option > len(self.options) - 1:
            self.option = 0
        elif self.option < 0:
            self.option = len(self.options) - 1

        return return_val

    def set_pos(self, x, y):
        """Set the topleft of the menu at x,y"""
        self.x = x
        self.y = y

    def set_font(self, font):
        """Set the font used for the menu."""
        self.font = font

    def set_highlight_color(self, color):
        """Set the highlight color"""
        self.hcolor = color

    def set_normal_color(self, color):
        """Set the normal color"""
        self.color = color

    def center_at(self, x, y):
        """Center the center of the menu at x,y"""
        self.x = x - (self.width / 2)
        self.y = y - (self.height / 2)
        self.centerx = x
        self.centery = y

    def help_text_at(self, x, y):
        self.hx = x
        self.hy = y

    def clear_menu(self):
        for dfo in self.font_list:
            self.scene.removeObject(dfo)
        self.scene.removeObject(self.help_text)
示例#9
0
class EzMenu():

    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 draw(self):
        """Draw the menu to the surface."""
        i=0
        help_txt = ""
        for o in self.options:
            if i==self.option:
                clr = self.hcolor
                help_txt = o[2]
            else:
                clr = self.color
            text = o[0]
            self.font_list[i].changeText(text, clr)
            self.font_list[i].setPosition( self.x, self.y + i*self.font.get_height() )
            i+=1

        # Help Text
        self.help_text.changeText(help_txt, self.color)
        self.help_text.setPosition(self.hx+5, self.hy)

    def update(self, event):
        """Update the menu and get input for the menu."""
        return_val = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_DOWN:
                self.option += 1
                return_val = True
            elif event.key == pygame.K_UP:
                self.option -= 1
                return_val = True
            elif event.key == pygame.K_RETURN:
                self.options[self.option][1]()
                return_val = True

        if self.option > len(self.options)-1:
            self.option = 0
        elif self.option < 0:
            self.option = len(self.options)-1

        return return_val

    def set_pos(self, x, y):
        """Set the topleft of the menu at x,y"""
        self.x = x
        self.y = y

    def set_font(self, font):
        """Set the font used for the menu."""
        self.font = font

    def set_highlight_color(self, color):
        """Set the highlight color"""
        self.hcolor = color

    def set_normal_color(self, color):
        """Set the normal color"""
        self.color = color

    def center_at(self, x, y):
        """Center the center of the menu at x,y"""
        self.x = x-(self.width/2)
        self.y = y-(self.height/2)
        self.centerx = x
        self.centery = y

    def help_text_at(self, x, y):
        self.hx = x
        self.hy = y
        
    def clear_menu(self):
        for dfo in self.font_list:
            self.scene.removeObject(dfo)
        self.scene.removeObject(self.help_text)
示例#10
0
class BattleMenuHolder(GameEngineElement):
    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 set_disp(self, msg):
        self.disp.changeText(msg, (0, 0, 0))

    def set_sec_disp(self, msg):
        self.sec_disp.changeText(msg, (0, 0, 0))

    def remove_from_engine(self):
        super(BattleMenuHolder, self).remove_from_engine()
        self.clear_menu()

    def draw(self):
        self.background.setPosition(0, 286)
        self.disp.setPosition(250, 340)
        self.sec_disp.setPosition(237, 375)

    def menu_called(self, id):
        self.callback(id, self)

    def clear_menu(self):
        if self.menu:
            self.menu.clear()
            self.menu.remove_from_engine()
            self.menu = None

    def show_menu(self, id):
        if self.is_in_engine():
            self.clear_menu()
        else:
            self.add_to_engine()

        y_offset = 0
        if id == "selection":
            menu_type = NORMAL_MENU
            menu_options = [
                [_("Attack"), lambda: self.menu_called("attack_show"), 140, 1],
                [_('Special'), lambda: self.show_menu("special"), 140, 1],
                [_('Magic'), lambda: self.show_menu("magic"), 140, 1],
                [_('Scan'), lambda: self.menu_called("scan"), 140, 1],
            ]

        elif id == "attack":
            y_offset = 50
            menu_type = GRID_MENU
            menu_options = [
                ['1', lambda: self.menu_called('1'), 44, 1],
                ['2', lambda: self.menu_called('2'), 44, 1],
                ['3', lambda: self.menu_called('3'), 44, 1],
                ['4', lambda: self.menu_called('4'), 44, 1],
                ['5', lambda: self.menu_called('5'), 44, 1],
                ['6', lambda: self.menu_called('6'), 44, 1],
                ['7', lambda: self.menu_called('7'), 44, 1],
                ['8', lambda: self.menu_called('8'), 44, 1],
                ['9', lambda: self.menu_called('9'), 44, 1],
                [_("C"), lambda: self.menu_called('clear'), 44, 1],
                ['0', lambda: self.menu_called('0'), 44, 1],
                [_("E"), lambda: self.menu_called('enter'), 44, 1],
            ]

        elif id == "special":
            menu_type = NORMAL_MENU
            menu_options = [[
                _("Back"), lambda: self.show_menu("selection"), 140, 1
            ]]

        elif id == "magic":
            menu_type = NORMAL_MENU
            menu_options = [
                [_("Fire"), lambda: self.menu_called("fire"), 140, 1],
                [
                    _("Lightning"), lambda: self.menu_called("lightning"), 140,
                    1
                ], [_("Missile"), lambda: self.menu_called("missile"), 140, 1],
                [_("Heal"), lambda: self.menu_called("heal"), 140, 1],
                [_("Back"), lambda: self.show_menu("selection"), 140, 1]
            ]

        else:
            print "Invalid Menu", id
            return

        self.menu = BattleMenu(menu_options, 237, 375 + y_offset, menu_type)
示例#11
0
class BattleMenuHolder( GameEngineElement ):
    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 set_disp(self, msg):
        self.disp.changeText(msg, (0,0,0))

    def set_sec_disp(self, msg):
        self.sec_disp.changeText(msg, (0,0,0))

    def remove_from_engine(self):
        super( BattleMenuHolder, self ).remove_from_engine()
        self.clear_menu()

    def draw(self):
        self.background.setPosition(0,286)
        self.disp.setPosition(250,340)
        self.sec_disp.setPosition(237, 375)

    def menu_called(self, id):
        self.callback(id, self)

    def clear_menu(self):
        if self.menu:
            self.menu.clear()
            self.menu.remove_from_engine()
            self.menu = None

    def show_menu(self,id):
        if self.is_in_engine():
            self.clear_menu()
        else:
            self.add_to_engine()

        y_offset = 0
        if id == "selection":
            menu_type = NORMAL_MENU
            menu_options = [
                        [_("Attack"), lambda: self.menu_called("attack_show"), 140,1],
                        [_('Special'), lambda: self.show_menu("special"), 140,1],
                        [_('Magic'), lambda: self.show_menu("magic"), 140,1],
                        [_('Scan'), lambda: self.menu_called("scan"), 140,1],
            ]

        elif id == "attack":
            y_offset = 50
            menu_type = GRID_MENU
            menu_options = [
                        ['1', lambda: self.menu_called('1'),44,1],
                        ['2', lambda: self.menu_called('2'),44,1],
                        ['3', lambda: self.menu_called('3'),44,1],
                        ['4', lambda: self.menu_called('4'),44,1],
                        ['5', lambda: self.menu_called('5'),44,1],
                        ['6', lambda: self.menu_called('6'),44,1],
                        ['7', lambda: self.menu_called('7'),44,1],
                        ['8', lambda: self.menu_called('8'),44,1],
                        ['9', lambda: self.menu_called('9'),44,1],
                        [_("C"), lambda: self.menu_called('clear'),44,1],
                        ['0', lambda: self.menu_called('0'),44,1],
                        [_("E"), lambda: self.menu_called('enter'),44,1],
            ]

        elif id == "special":
            menu_type = NORMAL_MENU
            menu_options = [
                        [_("Back"), lambda: self.show_menu("selection"),140,1]
            ]

        elif id == "magic":
            menu_type = NORMAL_MENU
            menu_options = [
                        [_("Fire"),  lambda: self.menu_called("fire"), 140, 1],
                        [_("Lightning"),  lambda: self.menu_called("lightning"), 140, 1],
                        [_("Missile"), lambda: self.menu_called("missile"), 140, 1],
                        [_("Heal"),  lambda: self.menu_called("heal"), 140, 1],
                        [_("Back"), lambda: self.show_menu("selection"), 140, 1]
            ]

        else:
            print "Invalid Menu", id
            return

        self.menu = BattleMenu(menu_options, 237, 375+y_offset, menu_type)