コード例 #1
0
ファイル: menu.py プロジェクト: ryuken/gravity-snails
    def addWidget(self, widget):
        """
        Adds a widget to the menu
        @param widget: The widget that should be added to the menu
        """
        widget_width = 128
        widget_height = 32
        widget_space = 2

        #(re-)calcluate rectangle size
        for i in range(0, len(self.widgets)):
            #print 'option_width: ' + str(option_width)
            #print "width of rectange [" + str(i) + "] = " + str(self.options[i].rect.width)
            if(widget_width < self.widgets[i].rect.width):
                widget_width = self.widgets[i].rect.width
            if(widget_height < self.widgets[i].rect.height):
                widget_height = self.widgets[i].rect.height

        widget.rect.width = widget_width
        widget.rect.height = widget_height
        widget.rect.centerx = (self.rect.width / 2)

        Frame.addWidget(self, widget)

        menu_height = widget_height * len(self.widgets)

        for i in range(0, len(self.widgets)):
            screen_center = self.rect.height / 2
            menu_top = (screen_center - (menu_height / 2))
            option_y = ((widget_height + widget_space) * i)
            self.widgets[i].rect.width = widget_width
            self.widgets[i].rect.height = widget_height
            self.widgets[i].rect.top = menu_top + option_y
コード例 #2
0
ファイル: help.py プロジェクト: ryuken/gravity-snails
class HelpMenu(Scene):
    """
    @ivar previousScene: The scene which should come after this help
    """
    def __init__(self, previousScene):
        """
        @param previousScene: The scene which should come after this help
        @summary: Initializes a help frame
        """
        Scene.__init__(self)
        self.previousScene = previousScene
        self.frame = Frame()
        text  = "Welcome to gravity snails\n"
        text += "=========================\n"
        text += "\n"
        text += "You can shoot the snails and the terrain beneath them\n"
        text += "Snails die if they touch the salt\nor when they are out of hitpoints\n"
        text += "\nCONTROLS\n=========================\n\n"
        text += "LEFT MOUSE BUTTON:\nplace snails in the screen\n\n"
        text += "ARROW KEYS:\nmove and target\n\n"
        text += "SPACE BAR:\nfire the active weapon\n\n"
        text += "RIGHT MOUSE BUTTON:\nswitch weapon\n\n"
        text += "\n"
        labelText = Label(text)
        labelText.centerLines = False
        labelText.rect.center = (self.frame.rect.width / 2, self.frame.rect.height / 2)
        self.frame.addWidget(labelText)

        buttonBack = Button("Back", self.runPreviousScene)
        buttonBack.rect.size = (128, 32)
        buttonBack.rect.centerx = self.frame.rect.width / 2
        buttonBack.rect.bottom = self.frame.rect.height - 32
        self.frame.addWidget(buttonBack)

    def update(self, input):
        """
        @param input: The user input
        @summary: updates the status of the help frame based on the user input
        """
        self.frame.update(input)

    def draw(self, surface):
        """
        @param surface: The surface which the help should be drawed on
        @summary: draws the help frame on a specified surface
        """
        self.frame.draw(surface)

    def runPreviousScene(self):
        """
        @summary: closes the help frame and tells sceneManager to go to previous scene
        """
        SceneManager().setScene(self.previousScene)
コード例 #3
0
ファイル: winscreen.py プロジェクト: ryuken/gravity-snails
class WinScreen(Scene):
    """
    @ivar nextScene: The scene which should come after this screen
    """
    def __init__(self, nextScene, teamColor):
        """
        @param nextScene: The scene which should come after this win screen
        @param teamColor: The color of the winning team
        @summary: Initializes win screen for the winning team
        """
        Scene.__init__(self)
        self.nextScene = nextScene
        self.frame = Frame()
        text = "!!! Congratulations !!!\n"
        text += "\n"
        text += "The " + teamColor + " team has won"
        labelText = Label(text)
        labelText.rect.center = (self.frame.rect.width / 2, self.frame.rect.height / 2)

        buttonBack = Button("Back", self.runNextScene)
        buttonBack.rect.size = (128, 32)
        buttonBack.rect.centerx = self.frame.rect.width / 2
        buttonBack.rect.bottom = self.frame.rect.height - 32

        self.frame.addWidget(labelText)
        self.frame.addWidget(buttonBack)

        self.victory_sound = load_sound("victory.ogg")
        self.victory_sound.play()

    def draw(self, surface):
        """
        @param surface: The surface which the win screen should be drawed on
        @summary: draws the win screen on a specified surface
        """
        self.frame.draw(surface)

    def update(self, input):
        """
        @param input: The user input
        @summary: updates the status of the win screen based on the user input
        """
        self.frame.update(input)

    def runNextScene(self):
        """
        @summary: closes the help frame and tells sceneManager to go to next scene
        """
        self.victory_sound.stop()
        SceneManager().setScene(self.nextScene)