Example #1
0
    def start(self, screen):
        width = screen.get_width()
        height = screen.get_height()

        if not self.already_loaded:
            self.confirm_text = Label(
                pygame.rect.Rect(width / 2 - 200, height / 2 - 50, 400, 30),
                "Are you sure you want to forfeit the match?", {
                    Options.BACKGROUND: (82, 173, 200),
                    Options.FOREGROUND: (20, 61, 89),
                    Options.BORDER_WIDTH: 0
                })
            self.yes_btn = Button(pygame.rect.Rect(width / 2 - 100,
                                                   height / 2 + 50, 50, 40),
                                  "Yes",
                                  options={
                                      Options.BACKGROUND: (20, 61, 89),
                                      Options.FOREGROUND: (244, 180, 26),
                                      Options.HOVERED_BACKGROUND: (10, 30, 45),
                                      Options.BORDER_WIDTH: 0,
                                  })
            self.no_btn = Button(pygame.rect.Rect(width / 2 + 50,
                                                  height / 2 + 50, 50, 40),
                                 "No",
                                 options={
                                     Options.BACKGROUND: (20, 61, 89),
                                     Options.FOREGROUND: (244, 180, 26),
                                     Options.HOVERED_BACKGROUND: (10, 30, 45),
                                     Options.BORDER_WIDTH: 0,
                                 })

        self.underlay_screen = screen.copy()
        self.already_loaded = True
Example #2
0
    def start(self, screen):
        width = screen.get_width()
        height = screen.get_height()

        if not self.already_loaded:
            self.header = Label(pygame.rect.Rect(width / 2 - 200, 10, 400, 30), "Delete an account", options={
                Options.BACKGROUND: (20, 61, 89),
                Options.FOREGROUND: (244, 180, 26),
                Options.BORDER_WIDTH: 0,
            })
            self.confirm_text = Label(pygame.rect.Rect(width / 2 - 200, height / 2 - 50, 400, 30), "", options={
                                          Options.BACKGROUND: (82, 173, 200),
                                          Options.FOREGROUND: (20, 61, 89),
                                          Options.BORDER_WIDTH: 0
                                      })
            self.yes_btn = Button(pygame.rect.Rect(width / 2 - 200, height / 2 + 50, 50, 40), "Yes", options={
                Options.BACKGROUND: (20, 61, 89),
                Options.FOREGROUND: (244, 180, 26),
                Options.HOVERED_BACKGROUND: (10, 30, 45),
                Options.BORDER_WIDTH: 0,
            })
            self.no_btn = Button(pygame.rect.Rect(width / 2 + 150, height / 2 + 50, 50, 40), "No", options={
                Options.BACKGROUND: (20, 61, 89),
                Options.FOREGROUND: (244, 180, 26),
                Options.HOVERED_BACKGROUND: (10, 30, 45),
                Options.BORDER_WIDTH: 0,
            })

            self.already_loaded = True

        self.confirm_text.text = f"Are you sure you want to delete account {Account.account_to_delete.name}?"
        self.confirm_text.recreate()
Example #3
0
    def __init__(self):
        self.__ACTION = MenuActions.NOSET
        self.Font = fonts.ubuntu_bold_graph(25)
        self.Input = input_text.text_input()
        self.Input.set_alpha_states(0.9, 1)
        self.Input.allowLetters()
        self.Input.allowNumbers()
        self.Input.set_show_text(dat.GetWord("aqui"))
        self.Input.set_background((0, 175, 255))
        self.Input.set_border_color((0, 107, 255))
        self.Input.set_border_size(2)
        self.Input.set_margin(6)

        self.Button = Button.Button(dat.GetWord("continuar"), (100, 100, 100),
                                    (0, 0))

        self.ReturnButton = Button.Button(dat.GetWord("cancelar"),
                                          (200, 200, 200), (0, 0))

        self.Moving = None
        self.Disf = pygame.display.get_surface().get_size(
        )[0] / 2 + self.Input.surface.get_size()[0]
        self.original = self.Disf
        self.SpeedMove = 0
        Name = self.Font.render(dat.GetWord("ingresar nombre"), 1, (0, 0, 0))
        self.GlobalSize = [
            self.Input.surface.get_size()[0],
            Name.get_size()[1] + 10 + self.Input.surface.get_size()[1] + 10 +
            self.Button.surface.get_size()[1]
        ]
        self.DirMove = None
        self.Finished = False
Example #4
0
def main():
    # ---------------------------------------- Pygame general settings ---------------------------------------- #
    pg.init()

    WIDTH = 800
    SIZE = (WIDTH, WIDTH)
    screen = pg.display.set_mode(SIZE)
    main_icon = pg.image.load(os.path.join('assets', 'main_icon.png'))
    icon = pg.image.load(os.path.join('assets', 'icon.png'))
    pg.display.set_icon(icon)
    pg.display.set_caption('Path Finding Algorithm Visualizer')
    font = pg.font.Font(os.path.join('assets', 'Ubuntu-Bold.ttf'), 22)
    title_font = pg.font.Font(os.path.join('assets', 'Ubuntu-Bold.ttf'), 50)

    # ---------------------------------------- Main-Menu settings ---------------------------------------- #
    buttons = []
    buttons.append(
        Button(50, 70, 260, 50, Colors.LIGHT_GREEN, font, 'Controls'))
    buttons.append(
        Button(50, WIDTH - 200, 260, 50, Colors.LIGHT_GREEN, font,
               'Breadth First Search'))
    buttons.append(
        Button(500, WIDTH - 200, 260, 50, Colors.LIGHT_GREEN, font,
               'Depth First Search'))
    buttons.append(
        Button(50, WIDTH - 100, 260, 50, Colors.LIGHT_GREEN, font,
               'A* Search'))
    buttons.append(
        Button(500, WIDTH - 100, 260, 50, Colors.LIGHT_GREEN, font,
               'Greedy Best First Search'))
    menu = MainMenu(screen, main_icon, title_font, font, buttons)

    menu.loop()
Example #5
0
    def __init__(self, game):
        self.game = game
        GameStateScreen.__init__(self, game)

        self.prev_screen = None

        self.stackpanel = StackPanel(game, (200, 300),
                                     400,
                                     action=self.stackpanel_action)
        btn_classic = Button(game,
                             text='Classic Snake',
                             action=self.btn_cl_action,
                             enabled=True)
        btn_timelimit = Button(game,
                               text='Time limit',
                               action=self.btn_tl_action,
                               enabled=False)
        btn_back = Button(game, text='Back', action=self.btn_bk_action)

        self.stackpanel.add_widgets(btn_classic, btn_timelimit, btn_back)

        self.textbox = TextDisplay(game, bg_color=DARK_GREEN)

        self.container = StandaloneContainer(game, (650, 300), 600, 300,
                                             self.textbox)
        self.stackpanel_action(0)
Example #6
0
    def __init__(self, game):
        GameStateScreen.__init__(self, game)
        self.stackpanel = StackPanel(game, (200, 300), 400)

        btn_single_player = Button(game,
                                   text='Single Player',
                                   action=self.btn_sp_action)
        btn_multiplayer = Button(game,
                                 text='Multiplayer',
                                 action=self.btn_mp_action,
                                 enabled=False)
        btn_settings = Button(game,
                              text='Settings',
                              action=self.btn_st_action,
                              enabled=False)
        btn_credits = Button(game, text='Credits', action=self.btn_cr_action)
        btn_quit = Button(game, text='Quit', action=self.btn_qt_action)

        self.stackpanel.add_widgets(btn_single_player, btn_multiplayer,
                                    btn_settings, btn_credits, btn_quit)

        txt = 'Welcome to Battle Snakes!'
        textbox = TextDisplay(game, text=txt, bg_color=DARK_GREEN)
        self.container = StandaloneContainer(game, (650, 300), 600, 300,
                                             textbox)
    def start(self, screen):
        width = screen.get_width()
        height = screen.get_height()

        if self.already_loaded:
            self.name_box.set_text("")

        else:
            self.header = Label(pygame.rect.Rect(width / 2 - 200, 10, 400, 30), "Add new account", options={
                Options.BACKGROUND: (20, 61, 89),
                Options.FOREGROUND: (244, 180, 26),
                Options.BORDER_WIDTH: 0,
            })
            self.name_box = Textbox(pygame.rect.Rect(width/2 - 200, height/2 - 50, 400, 30), "", options={
                Options.BORDER_WIDTH: 0,
            })
            self.create_btn = Button(pygame.rect.Rect(width / 2 - 100, height / 2 + 50, 200, 30), "Create", options={
                Options.BACKGROUND: (20, 61, 89),
                Options.FOREGROUND: (244, 180, 26),
                Options.HOVERED_BACKGROUND: (10, 30, 45),
                Options.BORDER_WIDTH: 0,
            })
            self.back_btn = Button(pygame.rect.Rect(10, 10, 60, 40), "Back", {
                Options.BORDER_WIDTH: 0,
                Options.BACKGROUND: (20, 61, 89),
                Options.FOREGROUND: (244, 180, 26),
                Options.HOVERED_BACKGROUND: (10, 30, 45),
                Options.FONT: pygame.font.SysFont("Comic Sans MS", 15)
            })

            self.already_loaded = True
Example #8
0
 def __init__(self, game):
     super().__init__(game)
     self.buttons = []
     x = (game.width - 150) / 2
     self.buttons.append(
         Button("1-Player", (x, 100, 150, 40), (220, 220, 0),
                self.changeToOnePlayerState))
     self.buttons.append(
         Button("2-Player", (x, 160, 150, 40), (220, 220, 0),
                self.changeToTwoPlayerState))
Example #9
0
    def __init__(self, parent):
        self.parent = parent

        self.last_time = pygame.time.get_ticks()

        self.button_font = pygame.font.SysFont('consolas', 20)
        self.font = pygame.font.SysFont('consolas', 25)

        self.tasks = ButtonContainer()
        self.selected_tasks = []
        self.task_start_y = 100

        self.buttons = ButtonContainer([
            Button(
                self.parent.window_size[0] - self.button_font.size('Back')
                [0],  # Make these buttons position themselves when resizing 
                10,
                text='Back',
                fg=(255, 0, 0),
                font=self.button_font,
                show_box=False,
                command=self.parent.main),
            Button(10,
                   40,
                   120,
                   20,
                   text='Add a task',
                   font=self.button_font,
                   show_box=False,
                   fg=(255, 255, 255),
                   command=self.input_task),
            Button(10,
                   self.parent.window_size[1] -
                   self.button_font.size('Complete')[1],
                   self.button_font.size('Complete')[0],
                   self.button_font.size('Complete')[1],
                   text='Complete',
                   font=self.button_font,
                   show_box=False,
                   fg=(255, 255, 255),
                   command=self.complete_tasks),
            Button(self.button_font.size('Complete')[0] + 30,
                   self.parent.window_size[1] -
                   self.button_font.size('Complete')[1],
                   self.button_font.size('Abandon')[0],
                   self.button_font.size('Abandon')[1],
                   text='Abandon',
                   font=self.button_font,
                   show_box=False,
                   fg=(255, 255, 255),
                   command=self.abandon_task)
        ])

        self.particles = ParticleContainer()
Example #10
0
    def __init__(self, game):
        self.game = game
        GameStateScreen.__init__(self, game)
        self.prev_screen = None
        self.stackpanel = StackPanel(game, (SCR_W / 2 - 200, 300), 400)

        btn_controls = Button(game, text='Controls', action=self.btn_cl_action)
        btn_sound = Button(game, text='Sound', action=self.btn_sn_action)
        btn_back = Button(game, text='Back', action=self.btn_bk_action)

        self.stackpanel.add_widgets(btn_controls, btn_sound, btn_back)
Example #11
0
    def __init__(self, game):
        self.game = game
        GameStateScreen.__init__(self, game)
        self.stackpanel = StackPanel(game, (SCR_W / 2 - 200, 300), 400)

        txt_question = label(game, text='Are you sure you want to quit?')
        btn_yes = Button(game, text='Yes', action=self.game.quit)
        btn_no = Button(game, text='No', action=self.btn_no_action)

        self.stackpanel.add_widgets(txt_question, btn_yes, btn_no)

        self.prev_screen = None
Example #12
0
    def start(self, screen):
        if not self.already_loaded:
            width = screen.get_width()
            height = screen.get_height()

            self.header = Label(pygame.Rect(width / 2 - 75,
                                            height * 1 / 5 + 10, 150, 50),
                                "Game Paused",
                                options={
                                    Options.BACKGROUND: (20, 61, 89),
                                    Options.FOREGROUND: (244, 180, 26),
                                    Options.BORDER_WIDTH: 0,
                                })

            self.back_btn = Button(
                pygame.Rect(width * 1 / 5 + 10, height * 1 / 5 + 10, 60, 40),
                "Back", {
                    Options.BORDER_WIDTH: 0,
                    Options.BACKGROUND: (20, 61, 89),
                    Options.FOREGROUND: (244, 180, 26),
                    Options.HOVERED_BACKGROUND: (10, 30, 45),
                    Options.FONT: pygame.font.SysFont("Comic Sans MS", 15)
                })

            self.forfeit_btn = Button(
                pygame.Rect(width / 2 - 75, height / 2, 150, 40), "Forfeit", {
                    Options.BORDER_WIDTH: 0,
                    Options.BACKGROUND: (20, 61, 89),
                    Options.FOREGROUND: (244, 180, 26),
                    Options.HOVERED_BACKGROUND: (10, 30, 45),
                    Options.FONT: pygame.font.SysFont("Comic Sans MS", 25)
                })

            settings_gear_image = Resources.get("gear")
            settings_gear_rect = pygame.rect.Rect(width * 4 / 5 - 100,
                                                  height * 4 / 5 - 100, 75, 75)
            self.settings_btn = Image(
                settings_gear_rect, settings_gear_image, {
                    Options.BACKGROUND: (20, 61, 89),
                    Options.HOVERED_BACKGROUND: (10, 30, 45)
                })

            self.already_loaded = True

        if self.last_scene_id != Scene.scene_stack[-2]:
            self.last_scene_id = Scene.scene_stack[-2]
            self.underlay_screen = screen.copy()
            dark_cover = pygame.Surface(
                self.underlay_screen.get_size()).convert_alpha(
                    self.underlay_screen)
            dark_cover.fill((0, 0, 0, 0.6 * 255))
            self.underlay_screen.blit(dark_cover, (0, 0))
Example #13
0
    def start(self, screen):
        width = screen.get_width()
        height = screen.get_height()

        if not self.already_loaded:
            StatsScene.create_metrics()

            self.header = Label(pygame.rect.Rect(width / 2 - 200, 10, 400, 30),
                                "Statistics",
                                options={
                                    Options.BACKGROUND: (20, 61, 89),
                                    Options.FOREGROUND: (244, 180, 26),
                                    Options.BORDER_WIDTH: 0,
                                })

            self.first_offset = pygame.rect.Rect(width / 2 - 125, 75, 250, 30)

            label_options = {
                Options.BACKGROUND: (82, 173, 200),
                Options.FOREGROUND: (20, 61, 89),
                Options.BORDER_WIDTH: 0
            }

            for metric in StatsScene.all_metrics.keys():
                text = f"{metric}: {StatsScene.all_metrics[metric](Account.current_account)}"
                stat_lbl = Label(pygame.rect.Rect(0, 0, 0, 0), text,
                                 label_options)
                self.statistics.append(stat_lbl)

            btn_options = {
                Options.BORDER_WIDTH: 0,
                Options.BACKGROUND: (20, 61, 89),
                Options.FOREGROUND: (244, 180, 26),
                Options.HOVERED_BACKGROUND: (10, 30, 45),
                Options.FONT: pygame.font.SysFont("Comic Sans MS", 15)
            }

            self.back_btn = Button(pygame.rect.Rect(10, 10, 60, 40), "Back",
                                   btn_options)

            self.up_btn = Button(
                pygame.rect.Rect(width * 5 / 6, height * 2 / 6, 60, 40), "Up",
                btn_options)
            self.down_btn = Button(
                pygame.rect.Rect(width * 5 / 6, height * 4 / 6 - 40, 60, 40),
                "Down", btn_options)

            self.already_loaded = True

        self.stat_index = 0
        self.reposition_stats()
Example #14
0
    def __init__(self):
        self.logo = self.logo = pygame.image.load(IMAGE_FOLDER + 'logo.png')
        self.logo_size = self.logo.get_rect().size
        self.show_game_loader = False
        self.game_loader = LoadGameWindow()

        button_margin = 50
        self.new_game_button = Button(
            96, CONFIG.WINDOW_HEIGHT - 96 - 3 * button_margin, 'NEW GAME')
        self.load_game_button = Button(
            96, CONFIG.WINDOW_HEIGHT - 96 - 2 * button_margin, 'LOAD GAME')
        self.settings_button = Button(
            96, CONFIG.WINDOW_HEIGHT - 96 - button_margin, 'SETTINGS')
        self.exit_button = Button(96, CONFIG.WINDOW_HEIGHT - 96, 'EXIT')
Example #15
0
    def __init__(self, game, mode):
        GameStateScreen.__init__(self, game)
        self.mode = mode
        self.stack_panel = StackPanel(game, (515, 400), 250)

        btn_again = Button(game,
                           text='Play again',
                           action=self.btn_again_action)
        btn_menu = Button(game,
                          text='Return to main menu',
                          action=self.btn_menu_action)
        btn_quit = Button(game, text='Quit', action=self.btn_quit_action)

        self.stack_panel.add_widgets(btn_again, btn_menu, btn_quit)
Example #16
0
    def event_loop(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.VIDEORESIZE:
                self.parent.window_size = (event.w, event.h)
                self.parent.window = pygame.display.set_mode(
                    self.parent.window_size, pygame.RESIZABLE)

                self.buttons = ButtonContainer([
                    Button(self.parent.window_size[0] -
                           self.button_font.size('Back')[0],
                           10,
                           text='Back',
                           fg=(255, 0, 0),
                           font=self.button_font,
                           show_box=False,
                           command=self.parent.main),
                    Button(10,
                           40,
                           120,
                           20,
                           text='Add a task',
                           font=self.button_font,
                           show_box=False,
                           fg=(255, 255, 255),
                           command=self.input_task),
                    Button(10,
                           self.parent.window_size[1] -
                           self.button_font.size('Complete')[1],
                           self.button_font.size('Complete')[0],
                           self.button_font.size('Complete')[1],
                           text='Complete',
                           font=self.button_font,
                           show_box=False,
                           fg=(255, 255, 255),
                           command=self.complete_tasks),
                    Button(self.button_font.size('Complete')[0] + 30,
                           self.parent.window_size[1] -
                           self.button_font.size('Complete')[1],
                           self.button_font.size('Abandon')[0],
                           self.button_font.size('Abandon')[1],
                           text='Abandon',
                           font=self.button_font,
                           show_box=False,
                           fg=(255, 255, 255),
                           command=lambda: print(
                               'continue this | abandon button'))
                ])
Example #17
0
def init_menu():
    global screen, width, height, image_menu
    button_width = 200
    button_height = 100
    horizontal = width / 2 - (button_width * 2 + 50) / 2 - 100
    vertical = height / 2 - button_height / 2 + 250
    menu_obj.append(
        Button((horizontal, vertical), (button_width, button_height),
               Colors.BLACK, Colors.RED, start_game, "PLAY"))
    menu_obj.append(
        Button((horizontal + 300, vertical), (button_width, button_height),
               Colors.BLACK, Colors.RED, go_to_load_menu, "LOAD"))
    image_menu = pygame.image.load(os.path.join("img/menu.jpg"))
    pygame.mixer.music.load('sounds/soundtrack.mp3')
    pygame.mixer.music.play(-1)
Example #18
0
	def __init__(self, display):
		GUI.__init__(self, display)

		self.onClose = None
		self.onSetLight = None
		self.lumWarm = 0
		self.lumCold = 0

		self.margin = 16

		self.cellsX = 3
		self.cellsY = 4

		self.gridW = (self.width - self.margin * (self.cellsX + 1)) / self.cellsX
		self.gridH = (self.height - self.margin * (self.cellsY + 1)) / self.cellsY

		nextX = self.margin
		nextY = self.margin

		buttonQuit = Button(self, nextX, nextX, self.gridW, self.gridH, name="quit", label="Quit")
		nextX += self.gridW + self.margin
		buttonReboot = Button(self, nextX, nextY, self.gridW, self.gridH, name="reboot", label="Reboot")
		#nextX += self.gridW + self.margin
		#button3 = Button(self, nextX, nextY, self.gridW, self.gridH)
		nextX += self.gridW + self.margin
		buttonClose = Button(self, nextX, nextY, self.gridW, self.gridH, name="close", label="CLOSE")
		sliderWidth = self.gridW * self.cellsX + (self.cellsX-1) * self.margin
		nextX = self.margin
		nextY  += self.gridH + self.margin
		sliderWarm = Slider(self, nextX, nextY, sliderWidth, self.gridH, name="warm", label="WARM")
		nextY  += self.gridH + self.margin
		sliderCold = Slider(self, nextX, nextY, sliderWidth, self.gridH, name="cold", label="COLD")

		sliderWarm.onChange = self.changeLight
		sliderCold.onChange = self.changeLight
		buttonQuit.onClick = self.clickButton
		buttonReboot.onClick = self.clickButton
		#button3.onClick = self.clickButton
		buttonClose.onClick = self.clickButton

		self.addWidget(buttonQuit)
		self.addWidget(buttonReboot)
		#self.addWidget(button3)
		self.addWidget(buttonClose)
		self.addWidget(sliderWarm)
		self.addWidget(sliderCold)

		self.drawBG()
Example #19
0
    def __init__(self):
        self.window_size = (1000, 700)
        self.window = pygame.display.set_mode(self.window_size, pygame.RESIZABLE)
        self.todo_menu = TodoMenu(self)

        self.font = pygame.font.SysFont('consolas', 40)
        
        self.characters = { # Add player buttons
            'dave': Character(50, 10, 950, 1, exp_color = (0, 0, 255), sprites = [
                pygame.transform.scale(load_sprite('characters\\dave\\1.png', (255, 255, 255)), (500, 500)),
                pygame.transform.scale(load_sprite('characters\\dave\\2.png', (255, 255, 255)), (500, 500)),
                pygame.transform.scale(load_sprite('characters\\dave\\3.png', (255, 255, 255)), (500, 500)),
                pygame.transform.scale(load_sprite('characters\\dave\\4.png', (255, 255, 255)), (500, 500))
            ])
        }
        
        self.current_character = self.characters['dave']

        self.buttons = ButtonContainer([
                Button(10, 10, text = 'Todo menu', command = self.todo_menu.main, font = pygame.font.SysFont('consolas', 20), fg = (255, 255, 255),
                       show_box = False),
        ])

        self.particles = ParticleContainer()

        self.last_time = pygame.time.get_ticks()
Example #20
0
 def Button(self,
            x=0,
            y=0,
            width=400,
            height=40,
            image=button_image,
            image_highlighted=button_highlighted,
            caption="Unlabeled",
            batch=None,
            group=None,
            label_group=None,
            font_name='ChunkFive Roman',
            on_click=None,
            enabled=True):
     button = Button(self,
                     x=x,
                     y=y,
                     width=width,
                     height=height,
                     image=resize_button_image(image, 400, width),
                     image_highlighted=resize_button_image(
                         image_highlighted, 400, width),
                     caption=caption,
                     batch=(batch or self.batch),
                     group=(group or self.group),
                     label_group=(label_group or self.labels_group),
                     font_name=font_name,
                     enabled=enabled)
     if on_click:
         button.push_handlers(on_click=on_click)
     return button
Example #21
0
    def __init__(self, size):
        Template.__init__(self, size)
        self.size = size
        self.block = 64
        self.dt = 0.
        self.map1 = Map(self.size, (40, 40), self.block,
                        "./tiles/Empty_tile_64p.png")
        self.map2 = Map(self.size, (40, 40), self.block,
                        "./tiles/Empty_tile_64p.png")
        self.menu = Map(self.size, (2, 14), self.block,
                        "./tiles/Empty_tile_64p.png")
        self.menu_list = []
        self.palette = self.setup_menu()
        self.palette.xy = [250, 0]
        self.clip = pg.Rect(0, 0, self.size[0], self.size[1])
        self.c_pos = self.clip.topleft
        self.current_tile = None
        self.show_foreground = -1
        self.right_m_button = False
        self.right_m_pos = None
        self.m_pos = None
        self.fill = False
        self.m_select_rect = pg.Rect(1, 1, 1, 1)
        self.button1 = Button((120, 20), (129, 1), "Menu")
        self.drop_menu = Menu((120, 160), (129, 21))
        self.drop_menu.add_buttons(4, ["Save", "Load", "Palette", "Info"])
        self.drop_menu.set_bg_color(CONCRETE)
        self.load_menu = self.setup_loadmenu()
        self.floating_text = FloatingText("no text", self.size)
        self.setup()

        self.selected_map = self.map1
Example #22
0
    def __init__(self):
        self.subscreen = GameSubScreen.START_MENU
        self.map = Map(MAP_FOLDER + CONFIG.CURRENT_LEVEL + '.tcm')  # Stores the current map
        self.player = Player(len(self.map.layers[4].tiles[0]), 32)
        self.bot = Bot(len(self.map.layers[4].tiles[0]) + 32, 32)
        self.in_game_menu_bg = None

        # In game menu elements
        button_margin = 50
        self.in_game_resume_button = Button(96, CONFIG.WINDOW_HEIGHT - 96 - 3 * button_margin, label='RESUME')
        self.in_game_save_button = Button(96, CONFIG.WINDOW_HEIGHT - 96 - 2 * button_margin, label='SAVE GAME')
        self.in_game_exit_button = Button(96, CONFIG.WINDOW_HEIGHT - 96 - button_margin, label='EXIT')

        if CONFIG.SAVE_GAME != '':
            load_save_game(self)
            CONFIG.SAVE_GAME = ''
Example #23
0
 def __init__(self, game):
     super().__init__(game)
     self.buttons = []
     x = (game.width)//2-250
     
     for i in range(1,4):
         self.buttons.append(Button(str(i),(x+25+((i-1)%5)*100,160+((i-1)//5)*100,50,50), (220,220,0),action=self.selectAIDifficulty, args=(i,)))
Example #24
0
    def start(self, screen):
        if not self.already_loaded:
            self.back_btn = Button(
                pygame.rect.Rect(10, 10, 60, 40), "Back", {
                    Options.BORDER_WIDTH: 0,
                    Options.BACKGROUND: (20, 61, 89),
                    Options.FOREGROUND: (244, 180, 26),
                    Options.HOVERED_BACKGROUND: (10, 30, 45),
                    Options.FONT: pygame.font.SysFont("Comic Sans MS", 15)
                })

            about_text = "This game was made by Ritobroto Mukherjee and\n" \
                         "Shivam Gupta (who has done absolutely nothing yet)\n" \
                         "as practice for collaboration."
            y_offset = 0
            for line in about_text.splitlines():
                self.about_labels.append(
                    Label(
                        pygame.rect.Rect(10, 200 + y_offset * 30,
                                         screen.get_width() - 10, 30), line, {
                                             Options.BACKGROUND:
                                             (82, 173, 200),
                                             Options.FOREGROUND: (20, 61, 89),
                                             Options.BORDER_WIDTH: 0
                                         }))
                y_offset += 1

            self.already_loaded = True
Example #25
0
    def __init__(self):
        self.character_sprites = SpriteGroup()
        self.grid_sprites = SpriteGroup()
        self.button_sprites = SpriteGroup()
        self.infowidget_sprites = SpriteGroup()

        self.characters, n_characters = [], 8
        hex_positions = [(i, j) for i in range(pr.grid_width) for j in range(pr.grid_height)]
        character_positions = random.sample(hex_positions, n_characters)
        for cp in character_positions:
            h, w = cp
            cts = pr.CharacterType.type_names()
            ct_i = random.randrange(0, len(cts))
            self.characters.append(character_module.Character(sprite_group=self.character_sprites,
                                                              grid_position=(h, w),
                                                              character_type=pr.CharacterType[cts[ct_i]]))

        self.grid_topleft_position = (pr.game_window_width // 4, pr.game_window_height // 4)
        self.bg_grid_surface = pg.Surface((pr.game_window_width // 2, pr.game_window_height // 2))
        self.bg_grid_surface_rect = self.bg_grid_surface.get_rect(topleft=self.grid_topleft_position)
        self.bg_grid_surface.fill(pr.WHITE_RGB)

        self.grid = grid_module.Grid(sprite_group=self.grid_sprites,
                                     bg_surface_data=(self.bg_grid_surface, self.bg_grid_surface_rect),
                                     width_in_hexes=pr.grid_width,
                                     height_in_hexes=pr.grid_height,
                                     hex_edge_length=pr.hex_edge_length,
                                     objects=self.characters)

        self.menu_button = Button(game_state=self,
                                  pos=(13 * pr.game_window_width // 16, 1 * pr.game_window_height // 8),
                                  text='Back to menu',
                                  action=finish_game_action)
        self.end_turn_button = Button(game_state=self,
                                      pos=(13 * pr.game_window_width // 16, 7 * pr.game_window_height // 8),
                                      text='End the turn',
                                      action=end_turn_action)
        self.hex_infowidget = InfoWidget(game_state=self,
                                         pos=(0, 1 * pr.game_window_height // 4),
                                         size=(pr.game_window_width // 6, pr.game_window_height // 4),
                                         action=update_hex_infowidget)
        self.initiative_order_infowidget = InfoWidget(game_state=self,
                                                      pos=(
                                                      13 * pr.game_window_width // 16, 1 * pr.game_window_height // 4),
                                                      size=(3 * pr.game_window_width // 16, pr.game_window_height // 2),
                                                      action=update_initiative_order_infowidget)
def setup_light(idx, light):
    Button(light.name, [(0, 0, 255), (255, 255, 0), (255, 0, 0),
                        (0, 255, 0)][x], (10 + left, 10), (100, 100),
           lambda b, e, t: light.toggle())

    Slider((0, 100, 0), [(0, 0, 255), (255, 255, 0), (255, 0, 0),
                         (0, 255, 0)][x], (10 + left, 120), (100, 350),
           lambda s, v: light.brightness(v))
Example #27
0
    def __init__(self,
                 parent='osd',
                 text=None,
                 search=None,
                 handler=None,
                 left=None,
                 top=None,
                 width=600,
                 height=200,
                 bg_color=None,
                 fg_color=None,
                 icon=None,
                 border=None,
                 bd_color=None,
                 bd_width=None,
                 vertical_expansion=1):

        if not text:
            text = _('Program Search')

        PopupBox.__init__(self,
                          text,
                          handler,
                          left,
                          top,
                          width,
                          height,
                          icon,
                          vertical_expansion,
                          parent=parent)

        (self.server_available, msg) = record_client.connectionTest()
        if not self.server_available:
            errormsg = Label(_('Recording server is unavailable.') + \
                             ( ': %s\n\n' % msg ) + \
                             _('Feel free to implement this function inside the main guide.'),
                             self, Align.CENTER)
            return

        self.internal_h_align = Align.CENTER

        self.lbg = LetterBoxGroup(text=search)
        self.add_child(self.lbg)

        items_height = Button('foo').height
        self.num_shown_items = 8
        self.results = ListBox(width=(self.width - 2 * self.h_margin),
                               height=self.num_shown_items * items_height,
                               show_v_scrollbar=0)
        self.results.y_scroll_interval = self.results.items_height = items_height
        max_results = 10

        self.results.set_h_align(Align.CENTER)
        self.add_child(self.results)

        if search:
            self.searchProg(search)
        self.center_on_screen = TRUE
Example #28
0
    def __init__(self, last_screen_enum=None):
        self.last_screen_enum = last_screen_enum

        label_margin = 75
        self.labels = [(
            RM.readable_font.render('CONTROLS', 1, (255, 255, 255)),
            (75, 50),
        ),
                       (
                           RM.readable_font.render('UP', 1, (240, 240, 240)),
                           (75, 50 + 2 * label_margin),
                       ),
                       (
                           RM.readable_font.render('DOWN', 1, (240, 240, 240)),
                           (75, 50 + 3 * label_margin),
                       ),
                       (
                           RM.readable_font.render('RIGHT', 1,
                                                   (240, 240, 240)),
                           (75, 50 + 4 * label_margin),
                       ),
                       (
                           RM.readable_font.render('LEFT', 1, (240, 240, 240)),
                           (75, 50 + 5 * label_margin),
                       )]
        self.buttons = [(Button(2 * 75,
                                40 + 2 * label_margin,
                                label=pygame.key.name(CONFIG.KEY_UP),
                                font_family=RM.readable_font), 'Up'),
                        (Button(2 * 75,
                                40 + 3 * label_margin,
                                label=pygame.key.name(CONFIG.KEY_DOWN),
                                font_family=RM.readable_font), 'Down'),
                        (Button(2 * 75,
                                40 + 4 * label_margin,
                                label=pygame.key.name(CONFIG.KEY_RIGHT),
                                font_family=RM.readable_font), 'Right'),
                        (Button(2 * 75,
                                40 + 5 * label_margin,
                                label=pygame.key.name(CONFIG.KEY_LEFT),
                                font_family=RM.readable_font), 'Left')]
        self.back_button = Button(50,
                                  CONFIG.WINDOW_HEIGHT -
                                  4 * CONFIG.CHARACTER_SIZE,
                                  label='BACK')
Example #29
0
    def __init__(self, game):
        self.game = game
        GameStateScreen.__init__(self, game)
        self.prev_screen = None

        self.btn_back = Button(game, text='Back', action=self.btn_bk_action)
        self.container = StandaloneContainer(game, (0, 0),
                                             150,
                                             50,
                                             self.btn_back,
                                             focus=True)
Example #30
0
    def __init__(self,
                 text,
                 Thash,
                 handler=None,
                 handler_message=None,
                 default_choice=0,
                 x=None,
                 y=None,
                 width=0,
                 height=0,
                 icon=None,
                 vertical_expansion=1,
                 text_prop=None,
                 parent='osd'):

        PopupBox.__init__(self, text, handler, x, y, width, height, icon,
                          vertical_expansion, text_prop, parent)
        self.globalHash = Thash
        self.handler_message = handler_message

        # XXX: It may be nice if we could choose between
        #      OK/CANCEL and YES/NO
        s = xmlrpclib.ServerProxy(config.RPCHOST)
        if (s.d.is_active(self.globalHash) == 1) ^ (s.d.is_hash_checking(
                self.globalHash) == 1):
            self.b0 = Button(_('Stop'), width=(self.width - 60) / 2)
        else:
            self.b0 = Button(_('Start'), width=(self.width - 60) / 2)
        self.b0.set_h_align(Align.NONE)
        self.add_child(self.b0)

        self.b1 = Button(_('Erase'), width=(self.width - 60) / 2)
        self.b1.set_h_align(Align.NONE)
        self.add_child(self.b1)

        self.b2 = Button(_('Cancel'), width=(self.width - 60) / 2)
        self.b2.set_h_align(Align.NONE)
        self.add_child(self.b2)

        select = 'self.b%s.toggle_selected()' % default_choice
        eval(select)