コード例 #1
0
ファイル: keybinds.py プロジェクト: Pawel095/RaidenPy
 def setup_theme(self):
     self.theme = Theme()
     self.themeDisabled = Theme()
     self.theme.set_font(20, arcade.color.WHITE)
     self.themeDisabled.set_font(20, arcade.color.WHITE)
     self.set_button_textures()
     self.set_button_textures_disabled()
コード例 #2
0
ファイル: test_gui_theme.py プロジェクト: spaderdabomb/arcade
def test_theme_box_texture():
    theme = Theme()
    assert theme.text_box_texture == ""

    theme.add_text_box_texture(
        ":resources:gui_themes/Fantasy/TextBox/Brown.png")
    assert isinstance(theme.text_box_texture, arcade.Texture)
コード例 #3
0
ファイル: test_gui_theme.py プロジェクト: spaderdabomb/arcade
def test_theme_dialogut_box_texture():
    theme = Theme()
    assert theme.dialogue_box_texture == ""

    theme.add_dialogue_box_texture(
        ":resources:gui_themes/Fantasy/DialogueBox/DialogueBox.png")
    assert isinstance(theme.dialogue_box_texture, arcade.Texture)
コード例 #4
0
def test_theme_set_new_font_ban():
    theme = Theme()
    theme_font = theme.font
    new_font = Font()

    with pytest.raises(Exception):
        theme.font = new_font

    assert theme.font is theme_font
コード例 #5
0
ファイル: views.py プロジェクト: House-Rulez/black-jack
 def setup_theme(self):
     self.theme = Theme()
     self.theme_2 = Theme()
     self.theme_3 = Theme()
     self.theme_4 = Theme()
     self.theme.set_font(24, arcade.color.BLACK)
     self.set_button_textures()
コード例 #6
0
def test_theme_delete_font_ban():
    theme = Theme()
    theme_font = theme.font

    with pytest.raises(Exception):
        del theme.font

    assert theme.font is theme_font
コード例 #7
0
def test_setup_button_font_with_theme():
    theme = Theme()
    button = TextButton(center_x=50,
                        center_y=20,
                        width=30,
                        height=10,
                        text='Click me',
                        theme=theme)
    assert button.font is theme.font
コード例 #8
0
def test_draw_when_theme_set_and_text_is_empty(mocker):
    mocker.patch.object(TextButton, 'draw_texture_theme')
    mocker.patch.object(TextButton, 'draw_color_theme')
    mocker.patch('arcade.draw_text')

    button = TextButton(center_x=50,
                        center_y=20,
                        width=30,
                        height=10,
                        text='',
                        theme=Theme())
    button.draw()
    button.draw_color_theme.assert_not_called()
    button.draw_texture_theme.assert_called_once()
    arcade.draw_text.assert_not_called()
コード例 #9
0
def test_theme_font():
    theme = Theme()
    assert isinstance(theme.font, Font)

    assert theme.font.color == Font.DEFAULT_COLOR
    assert theme.font.size == Font.DEFAULT_SIZE
    assert theme.font.name == Font.DEFAULT_NAME

    theme.font.size = 10
    theme.font.color = arcade.color.WHITE
    theme.font.name = "verdana"
    assert theme.font.color == arcade.color.WHITE
    assert theme.font.size == 10
    assert theme.font.name == "verdana"

    theme.font.size = 12
    theme.font.name = Font.DEFAULT_NAME
    assert theme.font.name == Font.DEFAULT_NAME
コード例 #10
0
ファイル: test_gui_theme.py プロジェクト: spaderdabomb/arcade
def test_theme_font():
    theme = Theme()
    assert theme.font_color == Theme.DEFAULT_FONT_COLOR
    assert theme.font_size == Theme.DEFAULT_FONT_SIZE
    assert theme.font_name == Theme.DEFAULT_FONT_NAME

    theme.set_font(10, arcade.color.WHITE, "verdana")
    assert theme.font_color == arcade.color.WHITE
    assert theme.font_size == 10
    assert theme.font_name == "verdana"

    theme.set_font(12, arcade.color.WENGE)
    assert theme.font_name == Theme.DEFAULT_FONT_NAME
コード例 #11
0
ファイル: views.py プロジェクト: House-Rulez/black-jack
class GameOver(GameView):
    """Class to display the when game is over"""
    def setup_theme(self):
        self.theme = Theme()
        self.theme_2 = Theme()
        self.theme.set_font(24, arcade.color.BLACK)
        self.set_button_textures()

    def on_show(self):
        self.setup_theme()
        arcade.set_background_color(arcade.color.AMETHYST)
        self.play_button = PlayButton(self.WIDTH / 2 - 100,
                                      self.HEIGHT / 2 - 200,
                                      150,
                                      100,
                                      theme=self.theme,
                                      text='restart')
        self.exit_button = ExitButton(self.WIDTH / 2 + 100,
                                      self.HEIGHT / 2 - 200,
                                      150,
                                      100,
                                      theme=self.theme_2,
                                      text='exit')
        self.button_list.append(self.play_button)
        self.button_list.append(self.exit_button)

    def set_button_textures(self):
        #Play button
        normal = "img/buttons/green.png"
        hover = "img/buttons/pink.png"
        clicked = "img/buttons/red.png"
        locked = "img/buttons/blue.png"
        self.theme.add_button_textures(normal, hover, clicked, locked)

        #Exit button
        normal2 = "img/buttons/red.png"
        hover2 = "img/buttons/blue.png"
        clicked2 = "img/buttons/pink.png"
        locked2 = "img/buttons/green.png"
        self.theme_2.add_button_textures(normal2, hover2, clicked2, locked2)

    def on_draw(self):
        super().on_draw()

        if self.play_button.pressed:
            self.view.restart_game()

        if self.exit_button.pressed:
            arcade.close_window()
コード例 #12
0
def test_draw_when_theme_set(mocker):
    mocker.patch.object(TextButton, 'draw_texture_theme')
    mocker.patch.object(TextButton, 'draw_color_theme')
    mocker.patch('arcade.draw_text')

    button = TextButton(center_x=50,
                        center_y=20,
                        width=30,
                        height=10,
                        text='Click me',
                        theme=Theme())
    button.draw()
    button.draw_color_theme.assert_not_called()
    button.draw_texture_theme.assert_called_once()
    arcade.draw_text.assert_called_once_with('Click me',
                                             50,
                                             20,
                                             button.font.color,
                                             font_size=button.font.size,
                                             font_name=button.font.name,
                                             width=button.width,
                                             align="center",
                                             anchor_x="center",
                                             anchor_y="center")
コード例 #13
0
ファイル: test_gui_theme.py プロジェクト: spaderdabomb/arcade
def test_theme_button_texture():
    theme = Theme()
    assert theme.button_textures == {
        "normal": "",
        "hover": "",
        "clicked": "",
        "locked": ""
    }

    theme.add_button_textures(
        ":resources:gui_themes/Fantasy/Buttons/Normal.png",
        ":resources:gui_themes/Fantasy/Buttons/Hover.png",
        ":resources:gui_themes/Fantasy/Buttons/Clicked.png",
        ":resources:gui_themes/Fantasy/Buttons/Locked.png")

    for button_texture in theme.button_textures.values():
        assert isinstance(button_texture, arcade.Texture)

    theme.add_button_textures(
        ":resources:gui_themes/Fantasy/Buttons/Normal.png")
    assert isinstance(theme.button_textures["normal"], arcade.Texture)
    assert theme.button_textures["normal"] is theme.button_textures["hover"]
    assert theme.button_textures["normal"] is theme.button_textures["clicked"]
    assert theme.button_textures["normal"] is theme.button_textures["locked"]
コード例 #14
0
ファイル: views.py プロジェクト: House-Rulez/black-jack
class StartView(arcade.View):
    """Class to display the starting View for the game"""
    def __init__(self, game, WIDTH, HEIGHT):
        super().__init__()
        self.game = game
        self.WIDTH = WIDTH
        self.HEIGHT = HEIGHT
        self.start_game = False

    def setup_theme(self):
        self.theme = Theme()
        self.theme_2 = Theme()
        self.theme.set_font(24, arcade.color.BLACK)
        self.set_button_textures()

    def on_show(self):
        self.setup_theme()
        arcade.set_background_color(arcade.color.AMETHYST)
        self.play_button = PlayButton(550,
                                      100,
                                      80,
                                      80,
                                      theme=self.theme,
                                      text='play')
        self.exit_button = ExitButton(650,
                                      100,
                                      80,
                                      80,
                                      theme=self.theme_2,
                                      text='exit')
        self.button_list.append(self.play_button)
        self.button_list.append(self.exit_button)

    def set_button_textures(self):
        #Play button
        normal = "img/buttons/green.png"
        hover = "img/buttons/pink.png"
        clicked = "img/buttons/red.png"
        locked = "img/buttons/blue.png"

        #Exit button
        self.theme.add_button_textures(normal, hover, clicked, locked)
        normal2 = "img/buttons/red.png"
        hover2 = "img/buttons/blue.png"
        clicked2 = "img/buttons/pink.png"
        locked2 = "img/buttons/green.png"
        self.theme_2.add_button_textures(normal2, hover2, clicked2, locked2)

    def on_draw(self):
        arcade.start_render()
        start_x = self.WIDTH / 2
        start_y = self.HEIGHT / 2
        arcade.draw_text(
            "Welcome to Black Jack! \n You start off with 100 chips.\n Try to make it to 250 chips by beating the dealer\'s cards.\n Would you like to play?",
            start_x,
            start_y,
            arcade.color.BLACK,
            font_size=30,
            anchor_x="center",
            anchor_y="center",
            align='center')
        super().on_draw()
        self.play_button.draw()
        self.exit_button.draw()
        if self.play_button.pressed:
            game_view = GameViewBid(self.WIDTH, self.HEIGHT)
            self.game.window.show_view(game_view)
        if self.exit_button.pressed:
            arcade.close_window()
コード例 #15
0
ファイル: test_gui_theme.py プロジェクト: spaderdabomb/arcade
def test_theme_window_texture():
    theme = Theme()
    assert theme.window_texture == ""

    theme.add_window_texture(":resources:gui_themes/Fantasy/Window/Window.png")
    assert isinstance(theme.window_texture, arcade.Texture)
コード例 #16
0
ファイル: test_gui_theme.py プロジェクト: spaderdabomb/arcade
def test_theme_menu_texture():
    theme = Theme()
    assert theme.menu_texture == ""

    theme.add_menu_texture(":resources:gui_themes/Fantasy/Menu/Menu.png")
    assert isinstance(theme.menu_texture, arcade.Texture)
コード例 #17
0
ファイル: views.py プロジェクト: House-Rulez/black-jack
class BetView(GameView):
    """Class to display the game view for the "Make a Bid" screen"""
    def __init__(self, view, WIDTH, HEIGHT):
        super().__init__(view, WIDTH, HEIGHT)
        self.c_x = WIDTH / 6
        self.c_y = HEIGHT / 2
        self.bet = 1
        self.user_bank = self.game.user.get_bank()
        # place the deck image to the left of the screen
        self.deck_back = arcade.Sprite('img/bees.png',
                                       scale=0.2,
                                       center_x=self.c_x,
                                       center_y=self.c_y)

        # place 2 dealer's closed cards to the top of the screen
        self.dealer_card_back1 = arcade.Sprite('img/bees.png',
                                               scale=0.2,
                                               center_x=self.c_x + WIDTH / 3,
                                               center_y=self.c_y + HEIGHT / 4 +
                                               30)
        self.dealer_card_back2 = arcade.Sprite(
            'img/bees.png',
            scale=0.2,
            center_x=self.c_x + WIDTH / 3 + 70,
            center_y=self.c_y + HEIGHT / 4 + 30)

        # # place 2 player's closed cards to the bottom of the screen
        self.player_card_back1 = arcade.Sprite('img/bees.png',
                                               scale=0.2,
                                               center_x=self.c_x + WIDTH / 3,
                                               center_y=self.c_y - HEIGHT / 4 -
                                               30)
        self.player_card_back2 = arcade.Sprite(
            'img/bees.png',
            scale=0.2,
            center_x=self.c_x + WIDTH / 3 + 70,
            center_y=self.c_y - HEIGHT / 4 - 30)

    def setup_theme(self):
        self.theme = Theme()
        self.theme_2 = Theme()
        self.theme_3 = Theme()
        self.theme_4 = Theme()
        self.theme.set_font(24, arcade.color.BLACK)
        self.set_button_textures()

    def on_show(self):
        self.setup_theme()
        arcade.set_background_color(arcade.color.AMAZON)

        increase1_button = ValueButton(1,
                                       950,
                                       450,
                                       70,
                                       70,
                                       '1',
                                       theme=self.theme)
        decrease1_button = ValueButton(-1,
                                       1050,
                                       450,
                                       70,
                                       70,
                                       '-1',
                                       theme=self.theme)
        self.button_list.append(increase1_button)
        self.button_list.append(decrease1_button)
        increase5_button = ValueButton(5,
                                       950,
                                       375,
                                       70,
                                       70,
                                       '5',
                                       theme=self.theme_2)
        decrease5_button = ValueButton(-5,
                                       1050,
                                       375,
                                       70,
                                       70,
                                       '-5',
                                       theme=self.theme_2)
        self.button_list.append(increase5_button)
        self.button_list.append(decrease5_button)
        increase10_button = ValueButton(10,
                                        950,
                                        300,
                                        70,
                                        70,
                                        '10',
                                        theme=self.theme_3)
        decrease10_button = ValueButton(-10,
                                        1050,
                                        300,
                                        70,
                                        70,
                                        '-10',
                                        theme=self.theme_3)
        self.button_list.append(increase10_button)
        self.button_list.append(decrease10_button)
        increase25_button = ValueButton(25,
                                        950,
                                        225,
                                        70,
                                        70,
                                        '25',
                                        theme=self.theme_4)
        decrease25_button = ValueButton(-25,
                                        1050,
                                        225,
                                        70,
                                        70,
                                        '-25',
                                        theme=self.theme_4)
        self.button_list.append(increase25_button)
        self.button_list.append(decrease25_button)

        quit_button = ExitButton(100, 650, 90, 40, text="Quit")
        self.button_list.append(quit_button)

        submit_button = SubmitButton(1000, 150, 110, 40, text="Place Bet")
        self.button_list.append(submit_button)

    def set_button_textures(self):
        #Bet 1 or -1
        normal = "img/red-chip.png"
        hover = "img/red-chip.png"
        clicked = "img/red-chip.png"
        locked = "img/red-chip.png"
        self.theme.add_button_textures(normal, hover, clicked, locked)

        #Bet 5 or -5
        normal2 = "img/lightblue-chip.png"
        hover2 = "img/lightblue-chip.png"
        clicked2 = "img/lightblue-chip.png"
        locked2 = "img/lightblue-chip.png"
        self.theme_2.add_button_textures(normal2, hover2, clicked2, locked2)

        #Bet 10 or -10
        normal2 = "img/lightgreen-ship.png"
        hover2 = "img/lightgreen-ship.png"
        clicked2 = "img/lightgreen-ship.png"
        locked2 = "img/lightgreen-ship.png"
        self.theme_3.add_button_textures(normal2, hover2, clicked2, locked2)

        #Bet 25 or -25
        normal2 = "img/black-chip.png"
        hover2 = "img/black-chip.png"
        clicked2 = "img/black-chip.png"
        locked2 = "img/black-chip.png"
        self.theme_4.add_button_textures(normal2, hover2, clicked2, locked2)

    def on_draw(self):
        super().on_draw()
        arcade.draw_text(f"Your bank is {self.bank - self.bet}", 100, 100,
                         arcade.color.BLACK, 24)

        self.deck_back.draw()
        self.dealer_card_back1.draw()
        self.dealer_card_back2.draw()
        self.player_card_back1.draw()
        self.player_card_back2.draw()

        arcade.draw_text(f"Place your bid:\n Your bet is {self.bet}",
                         self.WIDTH / 2,
                         self.HEIGHT / 2,
                         arcade.color.BLACK,
                         24,
                         anchor_x="center")

        for button in self.button_list:

            # if player made input
            if isinstance(button, ValueButton) and button.on_release():
                if self.bet + button.get_value() < 1:
                    self.bet = 1
                    continue

                if self.bet == 1 and button.get_value() > 1:
                    self.bet -= 1

                if self.bet + button.get_value() >= self.user_bank:
                    self.bet = self.user_bank
                    continue

                self.bet += button.get_value()

            if isinstance(button, SubmitButton) and button.pressed:
                self.game.place_user_bet(self.bet)
                self.view.set_view(
                    RoundView(self.view, self.WIDTH, self.HEIGHT))

            if isinstance(button, ExitButton) and button.pressed:
                arcade.close_window()
コード例 #18
0
ファイル: game.py プロジェクト: rcmerker/game-jam-2020
 def setup_theme(self):
     self.theme = Theme()
     self.theme.set_font(24, arcade.color.WHITE)
     self.set_button_textures()
コード例 #19
0
class SetName(arcade.View):
    def on_show(self):
        arcade.set_background_color(arcade.color.BLACK)

    def __init__(self):
        super().__init__()
        self.theme = None
        self.background = None
        self.screen_header = "Raiden Py"
        self.screen_header_font_size = 60
        self.screen_header_x = 300
        self.screen_header_y = 450
        self.setup()
        if(database.dbfuns.conn == None):
            database.dbfuns.connectDB()

    def set_button_textures(self):
        normal = "assets/normal.png"
        hover = "assets/hover.png"
        clicked = "assets/clicked.png"
        locked = "assets/locked.png"
        self.theme.add_button_textures(normal, hover, clicked, locked)

    def setup_theme(self):
        self.theme = Theme()
        self.theme.set_font(24, arcade.color.WHITE)
        self.set_button_textures()

    def set_buttons(self):
        submit = Submit(self, 300, 310, 190, 50, theme=self.theme)
        self.button_list.append(submit)
        utils.menusFunctions.app_buttons.append(submit)

    def setup(self):
        self.setup_theme()
        self.set_buttons()
        self.background = arcade.load_texture('assets/background.jpg')
        self.input = arcade.TextBox(
            1, 1, width=600, height=600, theme=self.theme)
        self.input.text_display.highlighted = True
        self.text = ''

    def on_key_press(self, key, modifiers):
        global nickname
        super().on_key_press(key, modifiers)
        if key >= 32 and key <= 126 or key == arcade.key.BACKSPACE:
            self.input.update(0, key)
        nickname = self.input.text_storage.text
        self.text = self.input.text_storage.text

    def on_key_release(self, k, m):
        super().on_key_release(k, m)

    def on_update(self, delta):
        super().on_update(delta)

    def on_draw(self):
        arcade.start_render()
        super().on_draw()

        arcade.draw_texture_rectangle(utils.globals.SCREEN_WIDTH // 2, utils.globals.SCREEN_HEIGHT // 2,
                                      utils.globals.SCREEN_WIDTH, utils.globals.SCREEN_HEIGHT, self.background)

        arcade.draw_text(self.screen_header, self.screen_header_x, self.screen_header_y, arcade.color.WHITE,
                         self.screen_header_font_size, align="center", anchor_x="center", anchor_y="center")
        # input name
        if self.text:
            arcade.draw_text(self.text, 300, 380, arcade.color.WHITE,
                             self.screen_header_font_size, align="center", anchor_x="center", anchor_y="center")

        [button.draw() for button in self.button_list]
コード例 #20
0
class LeaderboardView(arcade.View):
    def on_show(self):
        arcade.set_background_color(arcade.color.BLACK)
    def __init__(self):
        super().__init__()    
        self.theme = None
        self.background = None
        self.playerText = utils.languagePack.playerText[utils.menusFunctions.currentLanguage]
        self.scoreText = utils.languagePack.scoreText[utils.menusFunctions.currentLanguage]
        
        self.setup()
        

    def set_button_textures(self):
        normal = "assets/normal.png"
        hover = "assets/hover.png"
        clicked = "assets/clicked.png"
        locked = "assets/locked.png"
        self.theme.add_button_textures(normal, hover, clicked, locked)

    def setup_theme(self):
        self.theme = Theme()
        self.theme.set_font(20, arcade.color.WHITE)
        self.set_button_textures()

    def set_buttons(self):
        
        optionsButton = ReturnButton(self, 300, 210, 240, 50, theme=self.theme)

        self.button_list.append(optionsButton)

        utils.menusFunctions.app_buttons.append(optionsButton)



    def setup(self):
        self.setup_theme()
        self.set_buttons()
        self.background = arcade.load_texture('assets/background.jpg')

    def on_draw(self):
        arcade.start_render()
        super().on_draw()
        arcade.draw_texture_rectangle(utils.globals.SCREEN_WIDTH // 2, utils.globals.SCREEN_HEIGHT // 2,
                                      utils.globals.SCREEN_WIDTH, utils.globals.SCREEN_HEIGHT, self.background)
        arcade.draw_text('#', 50, 500, arcade.color.ALICE_BLUE, 30, align="center", anchor_x="center", anchor_y="center")
        arcade.draw_text(self.playerText, 200, 500, arcade.color.ALICE_BLUE, 30, align="center", anchor_x="center", anchor_y="center")
        arcade.draw_text(self.scoreText, 450, 500, arcade.color.ALICE_BLUE, 30, align="center", anchor_x="center", anchor_y="center")
        arcade.draw_text("1", 50, 430, arcade.color.ALICE_BLUE, 30, align="center", anchor_x="center", anchor_y="center")
        arcade.draw_text("2", 50, 360, arcade.color.ALICE_BLUE, 30, align="center", anchor_x="center", anchor_y="center")
        arcade.draw_text("3", 50, 290, arcade.color.ALICE_BLUE, 30, align="center", anchor_x="center", anchor_y="center")
        arcade.draw_text(database.dbfuns.data[0]['playername'], 200, 430, arcade.color.ALICE_BLUE, 30, align="center", anchor_x="center", anchor_y="center")
        arcade.draw_text(str(database.dbfuns.data[0]['score']), 450, 430, arcade.color.ALICE_BLUE, 30, align="center", anchor_x="center", anchor_y="center")
        arcade.draw_text(database.dbfuns.data[1]['playername'], 200, 360, arcade.color.ALICE_BLUE, 30, align="center", anchor_x="center", anchor_y="center")
        arcade.draw_text(str(database.dbfuns.data[1]['score']), 450, 360, arcade.color.ALICE_BLUE, 30, align="center", anchor_x="center", anchor_y="center")
        arcade.draw_text(database.dbfuns.data[2]['playername'], 200, 290, arcade.color.ALICE_BLUE, 30, align="center", anchor_x="center", anchor_y="center")
        arcade.draw_text(str(database.dbfuns.data[2]['score']), 450, 290, arcade.color.ALICE_BLUE, 30, align="center", anchor_x="center", anchor_y="center")
        [button.draw() for button in self.button_list]

    def on_update(self, delta_time):
        self.updateText()
        

    def updateText(self):
        self.playerText = utils.languagePack.playerText[utils.menusFunctions.currentLanguage]
        self.scoreText = utils.languagePack.scoreText[utils.menusFunctions.currentLanguage]
コード例 #21
0
ファイル: keybinds.py プロジェクト: Pawel095/RaidenPy
class KeybindsOptionsView(arcade.View):
    def on_show(self):
        arcade.set_background_color(arcade.color.BLACK)

    def __init__(self):
        super().__init__()
        self.theme = None
        self.background = None
        self.screen_header = utils.languagePack.keybindsText[
            utils.menusFunctions.currentLanguage]
        self.movementText = utils.languagePack.movementText[
            utils.menusFunctions.currentLanguage]
        self.shootText = utils.languagePack.shootText[
            utils.menusFunctions.currentLanguage]
        self.screen_header_font_size = 60
        self.screen_header_x = 300
        self.screen_header_y = 450
        self.setup()

    def set_button_textures(self):
        normal = "assets/normal.png"
        hover = "assets/hover.png"
        clicked = "assets/clicked.png"
        locked = "assets/locked.png"
        self.theme.add_button_textures(normal, hover, clicked, locked)

    def set_button_textures_disabled(self):
        normal = "assets/normalDisabled.png"
        hover = "assets/hoverDisabled.png"
        clicked = "assets/clickedDisabled.png"
        locked = "assets/lockedDisabled.png"
        self.themeDisabled.add_button_textures(normal, hover, clicked, locked)

    def setup_theme(self):
        self.theme = Theme()
        self.themeDisabled = Theme()
        self.theme.set_font(20, arcade.color.WHITE)
        self.themeDisabled.set_font(20, arcade.color.WHITE)
        self.set_button_textures()
        self.set_button_textures_disabled()

    def set_buttons(self):
        mvButton = MovementButton(self, 450, 380, 240, 50, theme=self.theme)
        shootButton = ShootButton(self,
                                  450,
                                  310,
                                  240,
                                  50,
                                  theme=self.themeDisabled)
        optionsButton = ReturnButton(self, 300, 240, 240, 50, theme=self.theme)

        self.button_list.append(mvButton)
        self.button_list.append(shootButton)
        self.button_list.append(optionsButton)

        utils.menusFunctions.app_buttons.append(mvButton)
        utils.menusFunctions.app_buttons.append(shootButton)
        utils.menusFunctions.app_buttons.append(optionsButton)

    def setup(self):
        self.setup_theme()
        self.set_buttons()
        self.background = arcade.load_texture('assets/background.jpg')

    def on_draw(self):
        arcade.start_render()

        super().on_draw()
        arcade.draw_texture_rectangle(utils.globals.SCREEN_WIDTH // 2,
                                      utils.globals.SCREEN_HEIGHT // 2,
                                      utils.globals.SCREEN_WIDTH,
                                      utils.globals.SCREEN_HEIGHT,
                                      self.background)
        arcade.draw_text(self.screen_header,
                         self.screen_header_x,
                         self.screen_header_y,
                         arcade.color.ALICE_BLUE,
                         self.screen_header_font_size,
                         align="center",
                         anchor_x="center",
                         anchor_y="center")
        arcade.draw_text(utils.languagePack.movementText[
            utils.menusFunctions.currentLanguage],
                         150,
                         380,
                         arcade.color.ALICE_BLUE,
                         28,
                         align="center",
                         anchor_x="center",
                         anchor_y="center")
        arcade.draw_text(
            utils.languagePack.shootText[utils.menusFunctions.currentLanguage],
            150,
            310,
            arcade.color.ALICE_BLUE,
            28,
            align="center",
            anchor_x="center",
            anchor_y="center")
        [button.draw() for button in self.button_list]

    def on_update(self, delta_time):
        self.updateText()

    def updateText(self):
        self.screen_header = utils.languagePack.keybindsText[
            utils.menusFunctions.currentLanguage]
        self.movementText = utils.languagePack.movementText[
            utils.menusFunctions.currentLanguage]
        self.shootText = utils.languagePack.shootText[
            utils.menusFunctions.currentLanguage]
コード例 #22
0
ファイル: game.py プロジェクト: rcmerker/game-jam-2020
class Game(arcade.Window):
    def __init__(self):
        super().__init__(SCREEN_SIZE[0], SCREEN_SIZE[1], SCREEN_TITLE)
        self.planets = None
        self.lithium_location = get_new_lithium_location()
        self.last_lithium_change = time.time()
        self.lithium_count = 0
        self.lithium_score_location = (SCREEN_SIZE[0] / 3, SCREEN_SIZE[1] / 20)
        self.theme = None
        self.background = None
        self.background_music = arcade.Sound(BACKGROUND_MUSIC)
        self.lithium_sound = arcade.Sound(LITHIUM_SOUND)
        self.heal_sound = arcade.Sound(HEAL_SOUND)
        self.abscond_sound = arcade.Sound(ABSCOND_SOUND)
        self.game_over_sound = arcade.Sound(GAME_OVER_SOUND)
        self.restart_sound = arcade.Sound(RESTART_SOUND)

        self.master_volume = 0.5

        self.abscond_button = None
        self.restart_button = None
        self.volume_meter = None
        self.volume_mover = None

        self.player_in_tutorial = True
        self.game_over_time = None
        self.absconded = None
        self.player_has_clicked_lithium = False
        self.player_has_healed_planet = False
        self.banner_text = None
        self.banner_location = (SCREEN_SIZE[0] / 100, SCREEN_SIZE[1] / 2)
        self.last_banner_change = None
        self.story_iter = None

        self.volume_location = (7 * SCREEN_SIZE[0] / 8, SCREEN_SIZE[1] / 13)
        self.restart_location = (29 * SCREEN_SIZE[0] / 40, SCREEN_SIZE[1] / 13)

        self.banner_background_color = arcade.make_transparent_color(
            arcade.color.BLUE, 100)

    def setup(self):
        self.planets = arcade.SpriteList()
        self.absconded = False
        self.game_over_time = None
        self.lithium_count = 0
        self.player_has_clicked_lithium = False
        self.player_has_healed_planet = False
        self.banner_text = ""
        self.last_banner_change = None
        self.story_iter = itertools.cycle(line for line in STORY_LINES)
        self.background = arcade.load_texture(BACKGROUND_IMAGE)
        try:
            self.background_music.stop()
        except NameError:
            # Soloud not installed
            pass
        self.background_music.play(BACKGROUND_MUSIC_VOLUME *
                                   self.master_volume)
        planets = [Planet(planet_name) for planet_name in ALL_PLANETS]
        self.setup_theme()
        self.abscond_button = TextButton(SCREEN_SIZE[0] / 6,
                                         SCREEN_SIZE[1] / 15,
                                         200,
                                         50,
                                         "Abscond",
                                         theme=self.theme)
        self.restart_button = arcade.Sprite(RESTART_IMAGE)
        self.restart_button.center_x = self.restart_location[0]
        self.restart_button.center_y = self.restart_location[1]
        self.restart_button.scale /= 2
        self.abscond_button.on_press = self.abscond_press
        self.abscond_button.on_release = self.abscond_release
        self.button_list.append(self.abscond_button)

        self.volume_meter = arcade.Sprite(VOLUME_IMAGE)
        self.volume_meter.center_x = self.volume_location[0]
        self.volume_meter.center_y = self.volume_location[1]
        self.volume_meter.width *= 3
        self.volume_meter_leftmost = (self.volume_meter.center_x -
                                      (self.volume_meter.width / 2))
        self.volume_meter_rightmost = (self.volume_meter.center_x +
                                       (self.volume_meter.width / 2))
        self.volume_meter_bottommost = (self.volume_meter.center_y - 10)
        self.volume_meter_topmost = (self.volume_meter.center_y + 10)
        self.volume_mover = arcade.Sprite(VOLUME_MOVER_IMAGE)
        self.volume_mover.center_x = self.volume_meter.center_x
        self.volume_mover.center_y = self.volume_meter.center_y
        self.volume_mover.scale /= 3

        spawn_locations = get_spawn_locations()
        for planet, spawn_location in zip(planets, spawn_locations):
            self.planets.append(planet)
            others = [other for other in planets if other != planet]
            planet.setup(parent=self,
                         others=others,
                         center_x=spawn_location[0],
                         center_y=spawn_location[1],
                         start_speed_x=random.random(),
                         start_speed_y=random.random())

    def set_banner_text(self, new_text):
        if new_text == self.banner_text:
            return
        self.last_banner_change = time.time()
        self.banner_text = new_text
        x_coord = SCREEN_SIZE[0] / 100
        y_coord = ((random.random() * (6 * SCREEN_SIZE[1] / 8)) +
                   (SCREEN_SIZE[1] / 5))
        self.banner_location = (x_coord, y_coord)

    def abscond_press(self):
        self.abscond_button.pressed = True

    def abscond_release(self):
        if not self.abscond_button.pressed:
            return
        self.abscond_button.pressed = False
        self.absconded = True
        self.abscond_sound.play(self.master_volume * ABSCOND_VOLUME)
        self.game_over(f"Absconded with {self.lithium_count:.2f} lithium!")

    def set_button_textures(self):
        normal = ":resources:gui_themes/Fantasy/Buttons/Normal.png"
        hover = ":resources:gui_themes/Fantasy/Buttons/Hover.png"
        clicked = ":resources:gui_themes/Fantasy/Buttons/Clicked.png"
        locked = ":resources:gui_themes/Fantasy/Buttons/Locked.png"
        self.theme.add_button_textures(normal, hover, clicked, locked)

    def setup_theme(self):
        self.theme = Theme()
        self.theme.set_font(24, arcade.color.WHITE)
        self.set_button_textures()

    @log_exceptions
    def on_draw(self):
        """ Draw everything """
        arcade.start_render()
        arcade.draw_lrwh_rectangle_textured(0, 0, SCREEN_SIZE[0],
                                            SCREEN_SIZE[1], self.background)
        super().on_draw()
        for planet in self.planets:
            for other in planet.attacked_last_round:
                attack_point = random_location_in_planet(
                    (other.center_x, other.center_y), other.width / 4)
                attack_start_radius = min(planet.base_damage * 1e4,
                                          planet.width / 4)
                start_point_1, start_point_2 = get_attack_triangle_points(
                    (planet.center_x, planet.center_y), attack_point,
                    attack_start_radius)
                arcade.draw_triangle_filled(*start_point_1,
                                            *start_point_2,
                                            *attack_point,
                                            color=planet.color)
            planet.attacked_last_round = []
            planet.pushed_last_round = []

            planet.draw_triangulation_circle()
        self.planets.draw()
        lithium_count_text = f"Lithium count: {self.lithium_count:.2f}"
        arcade.draw_text(f"{lithium_count_text}",
                         *self.lithium_score_location,
                         color=arcade.color.WHITE,
                         font_size=24)

        self.abscond_button.draw()

        if self.game_over_time:
            self.restart_button.draw()

        self.volume_meter.draw()
        self.volume_mover.draw()

        arcade.draw_rectangle_filled(center_x=SCREEN_SIZE[0] / 2,
                                     center_y=20 + self.banner_location[1],
                                     width=SCREEN_SIZE[0],
                                     height=40,
                                     color=self.banner_background_color)

        arcade.draw_text(self.banner_text,
                         *self.banner_location,
                         color=arcade.color.GREEN,
                         font_size=22)

    def check_volume_press(self, x, y):
        if (self.volume_meter_leftmost < x < self.volume_meter_rightmost and
                self.volume_meter_bottommost < y < self.volume_meter_topmost):
            self.master_volume = (
                (x - self.volume_meter_leftmost) /
                (self.volume_meter_rightmost - self.volume_meter_leftmost))
            self.background_music.set_volume(BACKGROUND_MUSIC_VOLUME *
                                             self.master_volume)
            self.volume_mover.center_x = x

    @log_exceptions
    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        self.check_volume_press(x, y)

    @log_exceptions
    def on_mouse_press(self, x, y, button, modifiers):
        if self.game_over_time:
            if self.restart_button.collides_with_point((x, y)):
                self.restart_sound.play(self.master_volume * RESTART_VOLUME)
                self.setup()
            return
        if get_distance(x, y, *self.lithium_location) < 10:
            self.clicked_lithium()
        for planet in self.planets:
            if self.lithium_count >= 1 and planet.collides_with_point((x, y)):
                logger.info(f"Healing {planet.name}")
                self.lithium_count -= 1
                planet.get_healed(0.1)
                self.heal_sound.play(self.master_volume * HEAL_VOLUME)
                self.player_has_healed_planet = True

        self.abscond_button.check_mouse_press(x, y)

        self.check_volume_press(x, y)

    def clicked_lithium(self):
        self.lithium_sound.play(self.master_volume * LITHIUM_VOLUME)
        planet_avg_health = self.avg_planet_health()
        self.lithium_count += planet_avg_health * LITHIUM_MULTIPLIER
        self.lithium_location = get_new_lithium_location()
        self.last_lithium_change = time.time()
        self.player_has_clicked_lithium = True

    def avg_planet_health(self):
        return (sum([planet.health
                     for planet in self.planets]) / len(self.planets))

    def on_update(self, delta_time):
        if self.game_over_time:
            game_over_delta_time = (BASE_TIME_MULTIPLIER *
                                    (time.time() - self.game_over_time))
            if game_over_delta_time > 6 and not self.absconded:
                self.setup()
                return
        time_multiplier = BASE_TIME_MULTIPLIER * delta_time / 0.0168
        if self.player_in_tutorial:
            time_multiplier /= 6
        logger.debug("\nNew Round\n")
        if not self.player_in_tutorial and not self.game_over_time:
            self.lithium_count += delta_time / 100
        self.run_assertions()
        self.update_banner()
        self.planets.update()
        [planet.move(time_multiplier) for planet in self.planets]
        [planet.try_attack_others(time_multiplier) for planet in self.planets]
        [planet.try_push_others(time_multiplier) for planet in self.planets]
        should_not_triangulate = (self.player_in_tutorial
                                  and self.lithium_count > 2
                                  and not self.player_has_healed_planet)
        [
            planet.update_triangulating(time_multiplier,
                                        self.player_in_tutorial,
                                        should_not_triangulate)
            for planet in self.planets
        ]

        try:
            if self.background_music.get_stream_position() == 0.0:
                self.background_music.play(self.master_volume *
                                           BACKGROUND_MUSIC_VOLUME)
        except AttributeError:
            # Soloud not installed
            pass

        self.run_assertions()

    def update_banner(self):
        if self.game_over_time:
            return
        if not self.player_in_tutorial:
            self.update_banner_story()
            return
        now = time.time()
        if self.last_banner_change is None:
            self.set_banner_text("This is the story of Ze, Yogh, and Ezh.")
        delta_time = BASE_TIME_MULTIPLIER * (now - self.last_banner_change)
        if not self.player_has_clicked_lithium and delta_time > 3:
            self.set_banner_text(
                "See the flickering circles? Click on their intersection.")
        if (self.player_has_clicked_lithium
                and not self.player_has_healed_planet
                and not self.lithium_count > 2 and delta_time > 0.5):
            self.set_banner_text("Good. Keep doing it.")
        if self.lithium_count > 2 and not self.player_has_healed_planet:
            self.set_banner_text(
                "Good. Now heal one of the planets by clicking on them.")
        if self.player_has_healed_planet:
            self.set_banner_text(
                "You've healed them with lithium. Keep them alive.")
            delta_time = BASE_TIME_MULTIPLIER * (now - self.last_banner_change)
            if delta_time > 2:
                self.player_in_tutorial = False

    def update_banner_story(self):
        if self.game_over_time:
            return
        now = time.time()
        self.last_banner_change = self.last_banner_change or now - 5
        delta_time = BASE_TIME_MULTIPLIER * (now - self.last_banner_change)
        if delta_time < 3:
            return
        next_story_part = next(self.story_iter, self.banner_text)
        self.set_banner_text(next_story_part)

    def run_assertions(self):
        assert len(self.planets) in (1, 2, 3)
        if not self.game_over_time:
            assert len(self.planets) == 3
        assert self.lithium_count >= 0
        for planet in self.planets:
            if not self.game_over_time:
                assert len(planet.others) == 2
            assert planet.center_x > -SCREEN_SIZE[0]
            assert planet.center_x < SCREEN_SIZE[0] * 2
            assert planet.center_y > -SCREEN_SIZE[1]
            assert planet.center_y < SCREEN_SIZE[1] * 2
            assert planet.speed_x != 0
            assert planet.speed_y != 0

    def game_over(self, reason):
        if self.game_over_time:
            return
        if not self.absconded:
            self.game_over_sound.play(self.master_volume * GAME_OVER_VOLUME)
        self.banner_text = reason
        logger.info(f"Game over! {reason}")
        for planet in self.planets:
            logger.info(planet.get_stats_str())
        self.game_over_time = time.time()
コード例 #23
0
ファイル: options.py プロジェクト: Pawel095/RaidenPy
class Options(arcade.View):
    def on_show(self):
        arcade.set_background_color(arcade.color.BLACK)
    def __init__(self):
        super().__init__()    
        self.theme = None
        self.background = None
        self.screen_header = "Options"
        self.screen_header_font_size = 60
        self.screen_header_x = 300
        self.screen_header_y = 450
        self.setup()
        

    def set_button_textures(self):
        normal = "assets/normal.png"
        hover = "assets/hover.png"
        clicked = "assets/clicked.png"
        locked = "assets/locked.png"
        self.theme.add_button_textures(normal, hover, clicked, locked)

    def setup_theme(self):
        self.theme = Theme()
        self.theme.set_font(20, arcade.color.WHITE)
        self.set_button_textures()

    def set_buttons(self):
        diffButton = DifficultyButton(self, 300, 380, 240, 50, theme=self.theme)
        soundButton = SoundButton(self, 300, 310, 240, 50, theme=self.theme)
        keysButton = KeyBindsButton(self, 300, 240, 240, 50, theme=self.theme)
        langButton = LanguageButton(self, 300, 170, 240, 50, theme=self.theme)
        menuButton = ReturnButton(self, 300, 95, 240, 50, theme=self.theme)
        self.button_list.append(diffButton)
        self.button_list.append(soundButton)
        self.button_list.append(keysButton)
        self.button_list.append(langButton)
        self.button_list.append(menuButton)

        utils.menusFunctions.app_buttons.append(diffButton)
        utils.menusFunctions.app_buttons.append(soundButton)
        utils.menusFunctions.app_buttons.append(keysButton)
        utils.menusFunctions.app_buttons.append(langButton)
        utils.menusFunctions.app_buttons.append(menuButton)

    def setup(self):
        self.setup_theme()
        self.set_buttons()
        self.background = arcade.load_texture('assets/background.jpg')

    def on_draw(self):
        arcade.start_render()
        
        super().on_draw()
        arcade.draw_texture_rectangle(utils.globals.SCREEN_WIDTH // 2, utils.globals.SCREEN_HEIGHT // 2,
                                      utils.globals.SCREEN_WIDTH, utils.globals.SCREEN_HEIGHT, self.background)
        arcade.draw_text(self.screen_header, self.screen_header_x, self.screen_header_y, arcade.color.ALICE_BLUE, self.screen_header_font_size, align="center", anchor_x="center", anchor_y="center")
        [button.draw() for button in self.button_list]

    def on_update(self, delta_time):
        self.updateText()

    def updateText(self):
        self.screen_header = utils.languagePack.optionsText[utils.menusFunctions.currentLanguage]
コード例 #24
0
class MainMenu(arcade.View):
    def on_show(self):
        arcade.set_background_color(arcade.color.BLACK)

    def __init__(self):
        super().__init__()
        self.theme = None
        self.background = None
        self.screen_header = "Raiden Py"
        self.screen_header_font_size = 60
        self.screen_header_x = 300
        self.screen_header_y = 450
        self.setup()
        if (database.dbfuns.conn == None):
            database.dbfuns.connectDB()

    def set_button_textures(self):
        normal = "assets/normal.png"
        hover = "assets/hover.png"
        clicked = "assets/clicked.png"
        locked = "assets/locked.png"
        self.theme.add_button_textures(normal, hover, clicked, locked)

    def setup_theme(self):
        self.theme = Theme()
        self.theme.set_font(20, arcade.color.WHITE)
        self.set_button_textures()

    def set_buttons(self):
        playButton = PlayButton(self, 300, 380, 240, 50, theme=self.theme)
        optionsButton = OptionsButton(self,
                                      300,
                                      310,
                                      240,
                                      50,
                                      theme=self.theme)
        leaderboardButton = LeaderboardButton(self,
                                              300,
                                              240,
                                              240,
                                              50,
                                              theme=self.theme)
        exitButton = ExitButton(self, 300, 170, 240, 50, theme=self.theme)

        self.button_list.append(playButton)
        self.button_list.append(optionsButton)
        self.button_list.append(leaderboardButton)
        self.button_list.append(exitButton)

        utils.menusFunctions.app_buttons.append(playButton)
        utils.menusFunctions.app_buttons.append(optionsButton)
        utils.menusFunctions.app_buttons.append(leaderboardButton)
        utils.menusFunctions.app_buttons.append(exitButton)

    def setup(self):
        self.setup_theme()
        self.set_buttons()
        self.background = arcade.load_texture('assets/background.jpg')

    def on_draw(self):
        arcade.start_render()

        super().on_draw()
        arcade.draw_texture_rectangle(utils.globals.SCREEN_WIDTH // 2,
                                      utils.globals.SCREEN_HEIGHT // 2,
                                      utils.globals.SCREEN_WIDTH,
                                      utils.globals.SCREEN_HEIGHT,
                                      self.background)
        arcade.draw_text(self.screen_header,
                         self.screen_header_x,
                         self.screen_header_y,
                         arcade.color.WHITE,
                         self.screen_header_font_size,
                         align="center",
                         anchor_x="center",
                         anchor_y="center")
        [button.draw() for button in self.button_list]