Esempio n. 1
0
 def init_text_ui(self):
     # ui button surface
     ui_text_list = []
     if self.width == 0:
         ui_text_list.append(
             SysFont(self.font,
                     self.font_size).render(self.text, True, self.color))
     else:
         # text[start_pointer:end_pointer-1]: characters displayed in a line
         start_pointer = 0  # character start of the line
         end_pointer = 0  # character end of the line
         while end_pointer < len(self.text):
             text_width = SysFont(self.font, self.font_size).render(
                 self.text[start_pointer:end_pointer], True,
                 self.color).get_width()
             if text_width >= self.width:
                 ui_text_list.append(
                     SysFont(self.font, self.font_size).render(
                         self.text[start_pointer:(end_pointer - 1)], True,
                         self.color))
                 start_pointer = end_pointer - 1
             else:
                 end_pointer += 1
         # Add the last text element
         ui_text_list.append(
             SysFont(self.font, self.font_size).render(
                 self.text[start_pointer:end_pointer], True, self.color))
     return ui_text_list
Esempio n. 2
0
    def __init__(self, resources, options):
        self.__resources = resources
        
        args = pygame.DOUBLEBUF 
        if options.fullscreen:
            args |= pygame.FULLSCREEN
        self.__window = pygame.display.set_mode(WINDOW_SIZE, args)
        pygame.display.set_caption("Whutshmup?!")

        side_width = (WINDOW_SIZE[0] - GAME_WIDTH) / 2
        self.__game_rect = Rect((side_width, 0), (GAME_WIDTH, WINDOW_SIZE[1]))
        self.__left_rect = Rect((0, 0), (side_width, WINDOW_SIZE[1])),
        self.__right_rect = Rect((GAME_WIDTH + side_width, 0), 
                                 (side_width, WINDOW_SIZE[1])
                                )
        self.surface = self.__window.subsurface(self.__game_rect)
        self.left = self.__window.subsurface(self.__left_rect)
        self.right = self.__window.subsurface(self.__right_rect)

        self.__scrolling_speed = 0
        self.__current_scroll = 0
        self.__total_distance = 0

        # Fonts
        self.__large = SysFont("Monospace", 40, True)
        self.__small = SysFont("Monospace", 20, True)
        self.__smaller = SysFont("Monospace", 12, True)

        # TODO: Different backgrounds for different levels
        bgimg = join(GFX_PATH, "BG-bluepattern.png")
        self.__bg_img = self.__resources.get_graphics(bgimg)
        self.paint_bg()
Esempio n. 3
0
    def __init__(self):
        self.gameSurf = display.get_surface().copy()
        self.drawWindow = display.get_surface()

        backgroundColor = (31, 97, 141, 150)
        title = SysFont('lucidaconsole', 35)
        subtitle = SysFont('lucidaconsole', 25)

        #distance between title and subtitle text
        textMargin = 10
        #distance between edge of text and full opacity background
        textBackgroundMargin = 10

        self.titleSurf = title.render("Cheat mode", True, Color('black'))
        self.subtitleSurf = subtitle.render("Click to exit", True,
                                            Color('black'))

        self.textBackgroundSurf = surface.Surface(
            (self.subtitleSurf.get_width() + 2 * textBackgroundMargin + 75,
             self.titleSurf.get_height() + self.subtitleSurf.get_height() +
             textMargin + 2 * textBackgroundMargin + 25), constants.SRCALPHA)

        self.textBackgroundSurf.fill(backgroundColor)

        self.titlePos = (self.drawWindow.get_width() / 2 -
                         self.titleSurf.get_width() / 2,
                         self.drawWindow.get_height() / 2 -
                         self.titleSurf.get_height() - textMargin / 2)
        self.subtitlePos = (self.drawWindow.get_width() / 2 -
                            self.subtitleSurf.get_width() / 2,
                            self.drawWindow.get_height() / 2 + textMargin / 2)
        self.textBackgroundPos = (self.drawWindow.get_width() / 2 -
                                  self.textBackgroundSurf.get_width() / 2,
                                  self.drawWindow.get_height() / 2 -
                                  self.textBackgroundSurf.get_height() / 2)
Esempio n. 4
0
 def __init__(self, surface):
     self.surface = surface
     self.status = 0  # 0: auto; 1: manul
     self.iter = 0
     self.ftw = 120
     self.font = SysFont('Comic Sans MS', 32)
     self.draw_help()
Esempio n. 5
0
    def set_font_size(self, point_size):
        # Set the point size of the window font used to draw strings
        # - self is the Window
        # - point_size is the int point size of the font

        self.__font_size__ = point_size
        self.__font__ = SysFont(self.__font_name__, self.__font_size__, True)
Esempio n. 6
0
 def text(self, value):
     self._text = value
     font = SysFont('consola', self.font_size)
     self._font = font.render(self._text, True, (255, 0, 0))
     self.content['font'] = [self._font, (
         self.rect.centerx - self._font.get_width() / 2,
         self.rect.centery - self._font.get_height() / 2)]
    def __init__(self):
        self.started = False
        
        self.fill_colour_min = Color(200, 167, 238)
        self.fill_colour_max = Color(138, 167, 200)
        
        self.circ_colour_min = Color(100, 20, 55)
        self.circ_colour_max = Color(0, 66, 127)
        
        self.circ_pos_min = Vector2(50, 50)
        self.circ_pos_max = Vector2(350, 350)
        
        self.lerp_n = 0
        self.lerp_speed = 0.05

        self.bg_colour = (240, 160, 212)
        self.area_info = (0, 0, 450, 450)
        self.cell_amt = 18
        self.back_colour = Color(231, 242, 198)
        self.cell_colour = Color(200, 200, 227)

        self.cell_size = (self.area_info[2] // self.cell_amt,
                          self.area_info[3] // self.cell_amt)
        self.play_rect = Rect(self.area_info)
        self.play_surf = Surface(self.area_info[2:])
        self.play_surf.fill(self.back_colour)

        self.circ_radius = 25
        
        self.fruit = Collectible(self.cell_size, self.cell_amt)
        
        self.draw_checkerboard()

        self.font = SysFont("Arial", 30)
        self.text = self.font.render("Text on screen.", False, self.bg_colour)
Esempio n. 8
0
 def text(self, text):
     self._text = text
     font = SysFont('consola', 60)
     self._font = font.render(self._text, True, (255, 0, 0))
     # well, figure out what the font's width is depended on
     self.content['font'] = [self._font,
                             (self.rect.centerx - self._font.get_width() / 2, self.rect.centery - self._font.get_height() / 2)]
Esempio n. 9
0
 def __init__(self, ai_settings, game_status, screen):
     self.ai_settings = ai_settings
     self.game_stats = game_status
     self.screen = screen
     self.screen_rect = self.screen.get_rect()
     self.text_font = SysFont(None, 18)
     self.text_color = (120, 30, 30)
Esempio n. 10
0
def display_abacus_add_subtract_problem(
    screen,
    color,
    separator_bead_color,
    upper_left,
    height,
    operands,
    line_spacing=1.2,
    font=None,
):
    if font is None:
        font = SysFont('Lucida Console', height)
    x_ul, y_ul = upper_left
    max_digits = max(len(digitize(operand)) for operand in operands)
    column_width = height_to_width(height)
    max_sign_width = 0.

    for row_n, operand in enumerate(operands):
        x_row = x_ul
        y_row = y_ul + row_n * height * line_spacing

        digits = digitize(abs(operand))
        n_digits = len(digits)

        sign = '+' if operand >= 0 else '-'
        sign_surface = font.render(sign, True, color)
        sign_width = sign_surface.get_width()

        max_sign_width = max(sign_width, max_sign_width)

        screen.blit(sign_surface, (x_row, y_row))

        draw_columns(
            screen,
            color,
            (x_row + sign_width +
             (max_digits - n_digits) * column_width, y_row),
            height,
            digits,
            separator_bead_color=separator_bead_color,
        )

    row_n = len(operands)
    x_rect_left = x_ul
    x_rect_right = (x_ul + max_sign_width + max_digits * column_width)
    y_rect_top = (y_ul + height * (row_n * line_spacing - .25 *
                                   (line_spacing - 1.)))
    y_rect_bottom = (y_rect_top + .25 * (line_spacing - 1.) * height)

    polygon(screen, color, [
        (x_rect_left, y_rect_top),
        (x_rect_right, y_rect_top),
        (x_rect_right, y_rect_bottom),
        (x_rect_left, y_rect_bottom),
    ])

    # coordinates of where to draw the rightmost digit
    # of the response
    return ((x_ul + sign_width + max_digits * column_width),
            y_ul + row_n * height * line_spacing)
Esempio n. 11
0
 def prep_time(self):
     format_time = "%02d:%02d" % (self.stats.minutes, self.stats.seconds)
     self.image_time = SysFont(None, 30).render(format_time, True,
                                                (150, 150, 150))
     self.time_rect = self.image_time.get_rect()
     self.time_rect.topright = self.score_rect.bottomright
     self.time_rect.top += 10
Esempio n. 12
0
    def refresh_loc(self, field_size):
        """
        updates coordinates on teh table surface
        :param field_size: float; size of a virtual field
         that is determined by the size of the window that inhabits the GUI
        """
        # gets surface with fitting size

        if self.title == "Remaining Ships":
            self.location = [field_size * 25, field_size * 5
                             ]  # updates location on the game window
            column_width = 3
        else:
            self.location = [field_size * 10, field_size * 5.5]
            column_width = 3.75
        self.surf = Surface((self.fake_size[0] * 4 * field_size,
                             self.fake_size[1] * 3 * field_size))
        self.writing.font = SysFont(None, int(field_size * 3 /
                                              2))  # resizes title's font
        # calculates title's center
        self.writing.top_left_corner = [
            field_size * self.columns.__len__() * column_width / 2,
            field_size * 3 / 4
        ]
        for column in self.columns:  # goes through every column
            column.refresh_loc(field_size)  # updates its locations
Esempio n. 13
0
    def __init__(self):
        self.started = False

        self.bg_colour = (240, 160, 212)
        self.area_info = (0, 0, 450, 450)
        self.cell_amt = 18
        self.back_colour = Color(231, 242, 198)
        self.cell_colour = Color(200, 200, 227)

        self.cell_size = (self.area_info[2] // self.cell_amt,
                          self.area_info[3] // self.cell_amt)
        self.play_rect = Rect(self.area_info)
        self.play_surf = Surface(self.area_info[2:])
        self.play_surf.fill(self.back_colour)

        self.circ_radius = 25

        self.fruit = Collectible(self.cell_size, self.cell_amt)
        self.score = 0
        self.snake = Snake(self.cell_size, self.cell_amt)
        self.snake_is_dead = False

        self.draw_checkerboard()

        self.font = SysFont("Arial", 30)
        self.text = self.font.render("Score: 0", False, self.back_colour)
Esempio n. 14
0
    def set_font_name(self, name):
        # Set the name of the window font used to draw strings
        # - self is the Window
        # - name is the str name of the font

        self.__font_name__ = name
        self.__font__ = SysFont(self.__font_name__, self.__font_size__, True)
Esempio n. 15
0
    def show_about(self):
        sentences = [
            "This Game was made by", "Maxim Egorov and Maxim Mogulev", "",
            "Controls:", "'p' key - exit from pause",
            "'o' key - To turn on the sound",
            "'wasd' keys - move on the board",
            "'esc' key - exit from the game", "'space' key - stop moving", "",
            "", "Press any key to exit this menu"
        ]

        font_list = [SysFont("Consolas", 40) for _ in range(len(sentences))]
        text_list = []
        happy_img = pygame.transform.scale(load_image("happy_pacman.png"),
                                           (300, 300))

        for i in range(len(font_list)):
            text_list.append(font_list[i].render(sentences[i], 0,
                                                 (255, 255, 255)))

        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.close()
                elif event.type == pygame.KEYDOWN:
                    return
            self._window.fill(0)

            self._draw_placed_text(text_list, (100, 100))
            self._window.draw_obj(happy_img, (320, 680))

            pygame.display.flip()
Esempio n. 16
0
    def __init__(self, seed, setContextFunc, population=None, train=True):
        BaseContext.__init__(self, setContextFunc)
        self.seed = seed
        self.pop = Population(seed, 100) if population is None else population
        if train:
            self.worlds = []
            for net in sorted(self.pop.current_generation, key=lambda x: x.fitness, reverse=True):
                nWorld = NeuronalWorld(self.pop.seed, net)
                nWorld.renderer = RenderNeuronalWorld(nWorld)
                self.worlds.append(nWorld)
                nWorld.generatePlatform()
        else:
            best_nn = max((n for n in self.pop.current_generation), key=lambda x: x.fitness)
            nWorld = NeuronalWorld(self.pop.seed, best_nn)
            nWorld.renderer = RenderNeuronalWorld(nWorld)
            self.worlds = [nWorld]
        self.drawmode = 0
        self._train = train

        # the gui overlays
        self._overlays = texhandler.adjustedSurface(texhandler.Textures.overlays, height=48)

        fontObj = SysFont("Monospace", 30, bold=True)
        # mode switch buttons
        self.addElements({
            "bNext": GuiButton(constants.screenWidth - 100, constants.screenHeight - 70, fontObj, "->",
                               width=70).connect(self.buttonModeSwitch, 1),
            "bPrevious": GuiButton(30, constants.screenHeight - 70, fontObj, "<-", width=70).connect(
                self.buttonModeSwitch, -1)
        })
Esempio n. 17
0
    def drawSummary(self, screen):
        """
        draws a summary
        """
        x = 30
        y = 50
        fontObj = SysFont("Monospace", 18, bold=True)

        time = 0
        rowHeight = fontObj.get_height() + 2

        for world in self.worlds:
            time = max(time, world.time)
            renderedFitness = fontObj.render("Fitness: {0:.2f}".format(world.nn.fitness), 1, (255, 255, 255))

            if (y + rowHeight > (constants.screenHeight - 95)):
                y = 50
                x += 260
                if x + renderedFitness.get_width() > constants.screenWidth:
                    break
                # draw vertical line
                pygame.draw.line(screen, (100, 100, 100), (x - 10, 45), (x - 10, constants.screenHeight - 100), 2)
            # draw horizontal line (if still on first column)
            elif x < 100:
                pygame.draw.line(screen, (100, 100, 100), (25, y + rowHeight - 3),
                                 (constants.screenWidth - 25, y + rowHeight - 3), 2)

            screen.blit(renderedFitness, (x, y))

            y += rowHeight

        # draw the time
        renderedTime = pygame.font.SysFont("Monospace", 34, bold=True).render("Time: {0:.2f}".format(time), 1,
                                                                              (255, 255, 255))
        screen.blit(renderedTime, ((constants.screenWidth - renderedTime.get_width()) // 2, 10))
Esempio n. 18
0
 def __init__(self, title, number_of_columns, number_of_rows, column_titles,
              field_size):
     """
     :param title: str; tables title, dsipalyed on top of the table
     :param number_of_columns: int; number of columns in the table
     :param number_of_rows: int; number of rows in the table
     :param column_titles: list[str, ...]; list containg all columns' titles
     :param field_size: float; size of a virtual field
      that is determined by the size of the window that inhabits the GUI
     """
     self.title = title
     font = SysFont(None, int(field_size * 3 / 2))  # sets font
     self.writing = Writing(
         title, font, DARKGREEN,
         (field_size, field_size / 5))  # initializes title as writing
     self.fake_size = [number_of_columns,
                       number_of_rows]  # sets size in rows and colums
     column_list = [
     ]  # creates a lsit later containg every column inhabiting the table
     for i in range(number_of_columns):
         column_list.append(
             Column(number_of_rows, column_titles[i], i,
                    title))  # creates a column
     self.columns = column_list
     self.refresh_loc(field_size)  # initializes coordiantes and locations
Esempio n. 19
0
    def __init__(self, gui_left_upper, gui_right_upper=None, caption="Basic Model",
                 patch_size=15, board_rows_cols=(51, 51), clear=None, bounce=None, fps=None):

        gui.PATCH_SIZE = patch_size if patch_size % 2 == 1 else patch_size + 1
        gui.PATCH_ROWS = board_rows_cols[0] if board_rows_cols[0] % 2 == 1 else board_rows_cols[0] + 1
        gui.PATCH_COLS = board_rows_cols[1] if board_rows_cols[1] % 2 == 1 else board_rows_cols[1] + 1

        self.EXIT = 'Exit'
        self.GRAPH = '-GRAPH-'
        self.SETUP = 'setup'
        self.STOP = 'Stop'

        self.clock = pg.time.Clock()

        self.caption = caption

        self.screen_shape_width_height = (SCREEN_PIXEL_WIDTH(), SCREEN_PIXEL_HEIGHT())

        # All these gui.<variable> elements are globals in this file.
        gui.WINDOW = self.make_window(caption, gui_left_upper, gui_right_upper=gui_right_upper,
                                      clear=clear, bounce=bounce, fps=fps)
        pg.init()
        gui.FONT = SysFont(None, int(1.5 * gui.BLOCK_SPACING()))

        # All graphics are drawn to gui.SCREEN, which is a global variable.
        gui.SCREEN = pg.display.set_mode(self.screen_shape_width_height)
    def set_font_name(self, name):
        """Set the name of the window font used to draw strings.

        :param name: the str name of the font
        """

        self.__font_name__ = name
        self.__font__ = SysFont(self.__font_name__, self.__font_size__, True)
Esempio n. 21
0
    def __init__(self, settings: Settings, screen: Surface):
        self._settings = settings
        self._screen = screen
        self._screen_rect = screen.get_rect()
        self._font = SysFont(None, settings.scoreboard_font_size)
        self._margin = settings.scoreboard_margin

        self.render_all(0, 0, 1, settings.health_limit, settings.ammo_limit)
    def set_font_size(self, point_size):
        """Set the point size of the window font used to draw strings.

        :param point_size: the int point size of the font
        """

        self.__font_size__ = point_size
        self.__font__ = SysFont(self.__font_name__, self.__font_size__, True)
    def __init__(self, networkContext, setContextFunc, popFileName):
        BaseContext.__init__(self, setContextFunc)
        self._networkContext = networkContext
        self._popFileName = popFileName
        self._pop = Population.load_from_file(
            constants.res_loc("networks") + popFileName)

        self._background = texturehandler.fillSurface(
            pygame.Surface(constants.screenSize),
            random.choice(texturehandler.blocks), (64, 64))

        best_fitness = max(n.fitness for n in self._pop.current_generation)
        fontObj = Font(None, 40)
        self.addElements({
            "lCaption":
            GuiLabel.createCentered(10, Font(None, 60), self._pop.name),
            "lSeed":
            GuiLabel(240, 90, fontObj, "Current seed:"),
            "tfSeed":
            GuiNumberTextfield(450,
                               87,
                               SysFont("Monospace", 24, bold=True),
                               width=140,
                               text=str(self._pop.seed)),
            "bSeed":
            GuiButton(600, 87, fontObj, "Set Seed", width=200,
                      height=32).connect(self.buttonSetSeed),
            "lSize":
            GuiLabel(
                240, 130, fontObj, "Population size: {}".format(
                    len(self._pop.current_generation))),
            "lFitness":
            GuiLabel(240, 170, fontObj,
                     "Highest fitness: {0:.2f}".format(best_fitness)),
            "lGeneration":
            GuiLabel(240, 210, fontObj,
                     "Generation: {}".format(self._pop.generation_count)),
            "bDelete":
            GuiButton(390,
                      470,
                      fontObj,
                      "Delete (hold CTRL)",
                      width=300,
                      height=40,
                      startColor=(255, 50, 50),
                      endColor=(255, 100, 100)).connect(self.buttonDelete),
            "bShowResult":
            GuiButton(240, 530, fontObj, "Show Result",
                      width=285).connect(self.buttonShowResult),
            "bResumeTraining":
            GuiButton(555, 530, fontObj, "Resume Training",
                      width=285).connect(self.buttonResumeTraining),
            "bBack":
            GuiButton(240, 600, fontObj, "Back").connect(self.buttonBack)
        })

        # enable key repeats
        pygame.key.set_repeat(500, 50)
 def font(self, font: Union[Font, SysFont, Tuple[int, str, str]]) -> None:
     if isinstance(font, (tuple, list)):
         if str(font[0]).endswith((".ttf", ".otf")):
             self.__font = Font(*font)
         else:
             self.__font = SysFont(*font)
     else:
         self.__font = font
     self.refresh()
Esempio n. 25
0
 def draw(self, screen):
     if self.worlds:
         [self.drawSimple, self.drawNetwork, self.drawSummary, self.drawOverview][self.drawmode](screen)
     BaseContext.draw(self, screen)
     # draw current generation
     renderedGen = SysFont("Monospace", 40, bold=True).render(str(self.pop.generation_count), 1, (50, 50, 50))
     # draw generation overlay (dinosaur egg)
     screen.blit(self._overlays, (485, 650), (336, 0, 48, 48))
     screen.blit(renderedGen, (540, 655))
Esempio n. 26
0
 def create_font_object(font) -> Font:
     obj = None
     if isinstance(font, (tuple, list)):
         if font[0] is not None and os.path.isfile(font[0]):
             obj = Font(*font[0:2])
             if "bold" in font:
                 obj.set_bold(True)
             if "italic" in font:
                 obj.set_italic(True)
         else:
             obj = SysFont(*font[0:2], bold=bool("bold" in font), italic=bool("italic" in font))
         if "underline" in font:
             obj.set_underline(True)
     elif isinstance(font, Font):
         obj = font
     else:
         obj = SysFont(pygame.font.get_default_font(), 15)
     return obj
Esempio n. 27
0
 def system_font(cls,
                 fontname,
                 size,
                 foreground,
                 background=None,
                 bold=False,
                 italic=False):
     font = SysFont(fontname, size, bold, italic)
     return cls(font, foreground, background)
Esempio n. 28
0
	def __init__(self):
		Sprite.__init__(self, Game.current.sprites)
		Game.current.sprites.change_layer(self, Game.LAYER_ABOVE_BG)
		self.font = SysFont(self.font, 22)
		self.image = Surface((
			Game.current.board.rect.width,
			self.font.get_linesize() + self.padding * 2
		))
		self.text = ""
		self.rect = self.image.get_rect()
Esempio n. 29
0
    def __init__(self, width, height, fs, white, colors):

        self.width = width
        self.height = height
        self.white_platforms = white
        self.resolution = (self.width, self.height)
        self.colors = colors

        pygame.init()
        pygame.mixer.init()
        pygame.font.init()
        if fs:
            self.display = pygame.display.set_mode(self.resolution, FULLSCREEN)
        else:
            self.display = pygame.display.set_mode(self.resolution)
        pygame.display.set_caption(TITLE)
        self.clock = pygame.time.Clock()
        pygame.time.set_timer(USEREVENT, 500)
        pygame.time.set_timer(USEREVENT + 1, 1000)
        self.font = SysFont("sans", 16)
        self.font2 = SysFont("sans", 48, True, False)
        self.manager = ResourcesManager("assets")
        self.bg1 = self.manager.load_image("parallax-space-background.png",
                                           False, self.resolution)
        self.bg2 = BackgroundLayer(
            self.manager.load_image("parallax-space-stars.png", True,
                                    self.resolution))
        self.bg3 = BackgroundLayer(
            self.manager.load_image("parallax-space-far-planets.png", True,
                                    self.resolution))
        self.imgSpeed = self.manager.load_image("arrowUp.png", True)
        self.imgSlow = self.manager.load_image("arrowDown.png", True)
        self.imgMap = self.manager.load_image("question.png", True)
        self.platTexture = self.manager.load_image("platBlock.png", True)
        self.go_sound = self.manager.load_sound("gameover.wav")
        self.go_sound.set_volume(0.15)
        self.faster_sound = self.manager.load_sound("tFTFaster.ogg")
        self.faster_sound.set_volume(0.15)
        pygame.mixer.music.load(os.path.join("assets", "alphacentauri.ogg"))
        pygame.mixer.music.set_volume(1.0)
        self.running = True
        self.run()
Esempio n. 30
0
    def __init__(self, world):
        self._world = world
        # update the entityfactory to a rendered version
        self._world.worldgen.ef = RenderEntityFactory()
        # attach the renderer for the player
        self._world.player.renderer = renderent.RenderPlayer(self._world.player)

        # the background texture
        self._background = pygame.transform.scale(texhandler.Textures.gameBG.surface, (2 * screenWidth, screenHeight))
        self._overlays = texhandler.adjustedSurface(texhandler.Textures.overlays, height=32)
        self._fontObj = SysFont("Monospace", 20, bold=True)