Beispiel #1
0
def redraw_board(gameDisplay):
    draw_empty_board(gameDisplay)
    for sqr in Board.activePieces:
        piece = Board.activePieces[sqr]
        colour = Board.get_square_colour(sqr)
        draw_empty_square(gameDisplay, sqr, colour)
        draw_piece(gameDisplay, piece, sqr)

    selSqr = Board.selected_sqr
    highlight_all_squares(gameDisplay)

    if Board.selected_sqr != None:
        draw_selection(gameDisplay, Board.selected_sqr)
    Board.selected_sqr = selSqr

    for sqr in Board.promotion_menu_sqrs:
        draw_promotion_menu(gameDisplay, sqr)

    boardLength = Board.sqr_length * 8

    if Board.GAME_FINISHED:
        if Board.turn != Colour.WHITE:
            ptext.draw("White wins!", (Board.sqr_length / 5,
                                       (boardLength / 2) - (boardLength / 8)),
                       fontsize=boardLength / 8,
                       color=(255, 0, 0))
        else:
            ptext.draw("Black wins!", (Board.sqr_length / 5,
                                       (boardLength / 2) - (boardLength / 8)),
                       fontsize=boardLength / 8,
                       color=(255, 0, 0))
 def get_frame(self):
     bar_width = self._surface.get_width() / len(self._data)
     self._surface.fill(pygame.Color('lightblue'))
     for hilight in self._hilights:
         r = Rect(hilight * bar_width, 0, bar_width,
                  self._surface.get_height())
         pygame.draw.rect(self._surface, pygame.Color('red'), r, 0)
     for index, item in enumerate(self._data):
         r = Rect((index * bar_width) + 1,
                  self._surface.get_height() - item.value, bar_width - 2,
                  item.value)
         pygame.draw.rect(self._surface, pygame.Color(item.color), r, 0)
         pygame.draw.rect(self._surface, pygame.Color('black'), r, 1)
     if self.sorted:
         text_color = '#00cc00ff'  # Link Green
     else:
         text_color = 'orange'
     ptext.draw(self.name, (10, 10),
                surf=self._surface,
                color=text_color,
                owidth=1,
                ocolor='black')
     ptext.draw("C: %d, S: %d " % (self.compares, self.swaps), (10, 24),
                surf=self._surface,
                color=text_color,
                owidth=1,
                ocolor='black')
     return self._surface
Beispiel #3
0
 def countdown_draw(self, context, surface):
     ptext.draw(
         context.text,
         center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2),
         color=AMBER,
         fontsize=40,
     )
Beispiel #4
0
def _receive_left_click(gameState):
    """Processes the left click and selected square that the opponent sent in multiplayer."""
    if gameState.typeOfMove == "MoveMade":
        Board.selected_sqr = gameState.SELECTED_SQR
        selectedSqrScreenPos = Board.get_sqr_xy(gameState.SELECTED_SQR)
        Board.select_square(selectedSqrScreenPos)
        leftClickPos = gameState.CLICKED_POS
        Board.select_square(leftClickPos)
    elif gameState.typeOfMove == "PawnPromoted":
        Board.activePieces[gameState.SELECTED_SQR] = gameState.sentPiece
        colour = Board.get_square_colour(gameState.SELECTED_SQR)
        Draw.draw_empty_square(gameState.GAME_DISPLAY, gameState.SELECTED_SQR,
                               colour)
        Draw.draw_piece(gameState.GAME_DISPLAY, gameState.sentPiece,
                        gameState.SELECTED_SQR)
        if Board.turn == Colour.WHITE:
            Board.turn = Colour.BLACK
        else:
            Board.turn = Colour.WHITE

    # Checks if a checkmate has occurred.  If it has then the proper message is displayed to the user
    if Board.check_for_checkmate():
        if Board.turn != Colour.WHITE:
            ptext.draw("White wins!",
                       (20, (gameState.HEIGHT / 2) - (gameState.HEIGHT / 8)),
                       fontsize=gameState.HEIGHT / 8,
                       color=(255, 0, 0))
        else:
            ptext.draw("Black wins!",
                       (20, (gameState.HEIGHT / 2) - (gameState.HEIGHT / 8)),
                       fontsize=gameState.HEIGHT / 8,
                       color=(255, 0, 0))
        Board.GAME_FINISHED = True
    gameState.RECEIVED_MOVE = False
Beispiel #5
0
 def render(self):
     if (not self.wifi_manager.enabled):
         if self.is_night and not self.night_mode:
             self.set_night_mode(True)
         elif not self.is_night and self.night_mode:
             self.set_night_mode(False)
         # Clear screen
         self.screen.fill((255, 255, 255))
         # Render Image
         rect = self.current_image.get_rect()
         self.screen.blit(self.current_image, rect)
         # Render Time + Info
         txt = datetime.strftime(datetime.now(), "%H:%M")
         ptext.draw(txt,
                    centery=(self.height / 2) + 65,
                    left=self.text_offset,
                    owidth=0.2,
                    ocolor=(0, 0, 0),
                    color=(255, 255, 255),
                    angle=90,
                    fontsize=72)
         # Render warning if we're offline
         r = self.wifi_symbol.get_rect()
         if (not self.online):
             self.screen.blit(self.wifi_symbol,
                              (self.width - r.width,
                               (self.height / 2) - (r.height / 2)))
     pygame.display.flip()
def main_menu(screen):
    background = pygame.image.load("background.png").convert()
    screen.blit(background, [0, 0])
    ptext.draw(menu_text, (250, 180), color=constants.WHITE, align="center")
    pygame.display.update()

    # Check the player's save file
    file = open('save file.txt', 'r')
    level = int(file.readline())
    file.close()

    start = False
    while start is False:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_w:
                    level = 0
                    file = open('save file.txt', 'w')
                    file.write(str(level))
                    file.close()
                    return level
                if event.key == pygame.K_SPACE:
                    return level
                if event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    quit()
            elif event.type == pygame.constants.USEREVENT:
                pygame.mixer.music.play()
        pygame.display.update()
Beispiel #7
0
def DungeonFailed(pokemon):
    pg.mixer.init()

    pg.mixer.music.load(
        path.dirname(__file__) + '/Assets/Music/017 Oh No!.ogg')

    pg.mixer.music.play(-1)

    UI_font = path.dirname(__file__) + '/Assets/Font/PKMN-Mystery-Dungeon.ttf'
    h = True
    while h:
        screen.fill(BLACK)
        pt.draw("You Died!\n press 'R' to restart \n press 'Q' to quit",
                (int(WIDTH / 2), int(HEIGHT / 2)),
                fontname=UI_font,
                antialias=False,
                align="center",
                shadow=(1.0, 1.0),
                scolor="blue",
                anchor=(0.5, 0.5),
                fontsize=40)

        pg.display.flip()
        for event in pg.event.get():
            if event.type == pg.KEYDOWN:
                if event.key == pg.K_q:
                    pg.mixer_music.fadeout(1000)
                    pg.time.delay(500)
                    h = False
                    pg.quit()
                if event.key == pg.K_r:
                    StartGame(newstart=pokemon)
Beispiel #8
0
    def draw_menu(self):
        items = ["Moves", "Exit"]
        menu = message_box(50, len(items) * 25)

        self.screen.blit(menu, (10, 30))
        for i in range(len(items)):
            self.selected = self.selected_index % len(items)
            if i == self.selected:
                pt.draw(items[i], (20, (i * 25) + 40),
                        fontname=self.title_font,
                        antialias=False,
                        fontsize=24,
                        color=LIGHTBLUE)

            else:
                pt.draw(items[i], (20, (i * 25) + 40),
                        fontname=self.title_font,
                        antialias=False,
                        fontsize=24,
                        color=WHITE)

        for event in pg.event.get():
            if event.key == pg.K_DOWN:
                self.selected_index += 1

            if event.key == pg.K_UP:
                self.selected_index -= 1

            if event.key == pg.K_RETURN:
                if items[self.selected] == "Exit":
                    self.menuflag = False
                if items[self.selected] == "Moves":
                    self.movemenuflag = True
Beispiel #9
0
def DungeonClear():
    pg.mixer.init()

    pg.mixer.music.load(
        path.dirname(__file__) + '/Assets/Music/013 Job Clear!.ogg')

    pg.mixer.music.play(-1)

    UI_font = path.dirname(__file__) + '/Assets/Font/PKMN-Mystery-Dungeon.ttf'
    h = True
    while h:
        screen.fill(BLACK)
        pt.draw(
            "Congratulations of Clearing the Dungeon.\n Thankyou For playing the demo!",
            (int(WIDTH / 2), int(HEIGHT / 2)),
            fontname=UI_font,
            antialias=False,
            align="center",
            shadow=(1.0, 1.0),
            scolor="blue",
            anchor=(0.5, 0.5),
            fontsize=40)

        pg.display.flip()
        for event in pg.event.get():
            if event.type == pg.KEYDOWN:
                pg.mixer_music.fadeout(1000)
                pg.time.delay(2500)
                h = False
 def _draw_frame(self):
     self.drawing_ready.acquire()
     bar_width = self._surface.get_width() / len(self._data)
     self._surface.fill(pygame.Color('lightblue'))
     for hilight in self._hilights:
         r = Rect(hilight * bar_width, 0, bar_width,
                  self._surface.get_height())
         pygame.draw.rect(self._surface, pygame.Color('red'), r, 0)
         # pygame.draw.rect(self._surface, pygame.Color('black'), r, 1)
     for index, item in enumerate(self._data):
         r = Rect((index * bar_width) + 1,
                  self._surface.get_height() - item.value, bar_width - 2,
                  item.value)
         pygame.draw.rect(self._surface, pygame.Color(item.color), r, 0)
         pygame.draw.rect(self._surface, pygame.Color('black'), r, 1)
     if self.is_sorted:
         text_color = 'green'
     else:
         text_color = 'orange'
     ptext.draw(self.name, (10, 10),
                surf=self._surface,
                color=text_color,
                owidth=1,
                ocolor='black')
     self.drawing_ready.release()
     draw_event.wait()
Beispiel #11
0
def cutscene(screen, current_level):
    screen.fill(constants.BLACK)
    text = ""
    if current_level == 0:
        file = open('cutscene_0.txt', 'r')
        for line in file:
            text += line
        file.close()
    elif current_level == 1:
        file = open('cutscene_1.txt', 'r')
        for line in file:
            text += line
        file.close()
    elif current_level == 2:
        text = "End of demo. Press escape to quit."
    ptext.draw(text, (10, 10), color=constants.WHITE, width=750, fontsize=21)
    pygame.display.update()

    start = False
    while start is False:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    if current_level == 2:
                        pygame.quit()
                        quit()
                    else:
                        return
                if event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    quit()
Beispiel #12
0
 def _draw(self):
     pview.fill((0, 0, 0))
     txt = self.score
     ptext.draw(txt,
                T(150, 320),
                fontsize=T(70),
                color='black',
                background='red')
     pg.display.flip()
Beispiel #13
0
 def _draw(self):
     pview.fill((0, 0, 0))
     txt = 'Game over\n%d encounters seen' % self.enc_seen
     ptext.draw(txt,
                T(150, 320),
                fontsize=T(70),
                color='black',
                background='red')
     pg.display.flip()
Beispiel #14
0
    def _recompute(self):
        """ recompute image and rect after screen res, shapes, or text changed. 
        First fill bg color, then draw shapes in order, and finish with text.
        """
        self._res = pview.size  # resolution this spr is for
        self.rect = T(self.rect0)
        tw, th = self.rect.size
        surf = pg.Surface((tw, th))

        # draw border and fill with background color
        b = self.bthick
        inner_rect = pg.Rect(b, b, tw - 2 * b, th - 2 * b)  # inner part
        if self.bcol:
            surf.fill(self.bcol)  # draw border
        surf.fill(self.color, inner_rect)

        # draw shapes
        for shape in self.shapes:
            if shape.kind == 'rect':
                x, y, w, h = shape.dims
                xx = b + T(
                    x) * inner_rect.w // self.rect.w  # fit into inner rect
                yy = b + T(y) * inner_rect.h // self.rect.h
                ww = T(w) * inner_rect.w // self.rect.w
                hh = T(h) * inner_rect.h // self.rect.h
                shape_rect = pg.Rect(xx, yy, ww, hh)
                surf.fill(shape.color, shape_rect)
            else:
                txt = 'NeatSprite: unsupported Shape.kind: %s' % shape.kind
                raise NotImplementedError(txt)

        # draw text
        if self._txt:
            txt_kwargs = {
                'width': inner_rect.w,
                'fontsize': T(self.fontsize),
                'antialias': self.txt_aa,
                'owidth': self.txt_owidth,
                'ocolor': self.txt_ocolor,
                'surf': surf
            }
            if self.txt_positioning == 'center':
                txt_kwargs['center'] = tw // 2, th // 2
            elif self.txt_positioning == 'topleft':
                txt_kwargs['pos'] = 0, 0
            ptext.draw(self._txt, **txt_kwargs)
        surf.set_colorkey(TRANSPARENT, pg.RLEACCEL)
        surf.convert()
        self.image = surf
        self.dirty = 1  # ready to be blit on screen
        self.recompute = 0  # done computing my image
Beispiel #15
0
    def _draw(self):
        # TODO: DirtySprite for player and fixed surf for bg
        pview.fill((0, 155, 155))  # unnecessary?
        draw_level(self.level, pview.screen, self.sprites)
        # pview.screen.blit(self.bg, (0, 0))
        # TODO: right-side HUD tracking steps and current level number
        x = BASE_RES[1] + 10
        y = 10
        ptext.draw('Level %d' % self.level.level_num, T(x, y), fontsize=T(40))
        w, h = BASE_RES
        txt = 'R: rest level\nF11: toggle fullscreen\nEsc: menu'
        ptext.draw(txt, T(h + 20, h - 80), fontsize=T(20))

        pg.display.flip()
Beispiel #16
0
 def update(self, game):
     t = game.time.get_ticks() / 1000
     self.t0 = t if not self.t0 else self.t0
     self.t = t - self.t0
     # Update display
     w, h = game.display.get_surface().get_size()
     ptext.draw(self.text,
                centerx=w * self.rel_w,
                centery=h * self.rel_h,
                width=w,
                align="center",
                lineheight=1.5,
                color=self.clr,
                fontsize=self.fontsize,
                sysfontname="Helvetica")
Beispiel #17
0
def _process_left_click_ingame(mouseClickPos):
    """Takes the left mouse click position and selects a square on the chess board with it, then it checks if a checkmate has occurred"""
    moveMade = Board.select_square(mouseClickPos)
    if Board.check_for_checkmate():
        if Board.turn != Colour.WHITE:
            ptext.draw("White wins!",
                       (20, (gameState.HEIGHT / 2) - (gameState.HEIGHT / 8)),
                       fontsize=gameState.HEIGHT / 8,
                       color=(255, 0, 0))
        else:
            ptext.draw("Black wins!",
                       (20, (gameState.HEIGHT / 2) - (gameState.HEIGHT / 8)),
                       fontsize=gameState.HEIGHT / 8,
                       color=(255, 0, 0))
        Board.GAME_FINISHED = True
    return moveMade
Beispiel #18
0
 def render(self):
     ptext.draw(self.state,
                centery=(self.height / 2) + 65,
                left=32,
                owidth=0.2,
                ocolor=(0, 0, 0),
                color=(255, 255, 255),
                angle=90,
                fontsize=72)
     ptext.draw(self.current_string,
                centery=(self.height / 2) + 65,
                left=64,
                owidth=0.2,
                ocolor=(0, 0, 0),
                color=(255, 255, 255),
                angle=90,
                fontsize=72)
    def execute(self):
        print("Starting\n")
        t0 = pygame.time.get_ticks()
        clock = pygame.time.Clock()
        clock_tick_rate = 20
        while not self.quit_screen:
            #show an opening image for 4 seconds
            if (pygame.time.get_ticks() - t0) < 2000:  #4000:
                self.screen.blit(self.opening_image, [0, 0])
                self.screen.blit(self.title_opening,
                                 (self.width / 2 - 55, self.height / 2 - 35))
            else:
                action = self.event_listener(True)
                if action == launch_info_window:
                    self.screen = pygame.display.set_mode(
                        (self.width, math.floor(self.height / 3)))
                    pygame.display.set_caption("Info")
                    while not self.quit_info_window:
                        #display the description
                        self.screen.fill(self.screen_background_color)
                        ptext.draw(self.long_description, (20, 20),
                                   fontsize=30,
                                   color="gray",
                                   align="left",
                                   bold=False)
                        pygame.display.update()
                        clock.tick(clock_tick_rate)
                        #listen events related to the info window
                        self.event_listener(False)
                else:  #if action == nothing
                    self.screen.fill(self.screen_background_color)
                    self.screen.blit(self.Jarvis_logo, [0, 0])
                    self.screen.blit(self.Jarvis_title_main_window,
                                     [self.width / 2 - 105, self.height / 10])
                    self.screen.blit(
                        self.short_info_description,
                        [self.width / 2 - 105, self.height / 10 + 50])
                    self.screen.blit(
                        self.info_logo,
                        [self.info_logo_coords[0], self.info_logo_coords[1]])
                    self.user_input_box.draw(self.screen)
                    self.answer_input_box.draw(self.screen)

            pygame.display.update()
            clock.tick(clock_tick_rate)
Beispiel #20
0
 def title_draw(self, context, surface):
     surface.blit(context.name, context.name_pos)
     ptext.draw(
         "CLICK MOUSE BUTTON\nTO BEGIN",
         center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2),
         color=AMBER,
         fontsize=40,
     )
     ptext.draw(
         "You are the green worm trying to catch the appearing\n" +
         "bubbles by clicking towards them with your mouse.\n" +
         "The faster you click, the faster your worm moves.\n" +
         "Be quick, you have only 30 seconds.\n\n" + "Press ESC to quit.",
         midbottom=(SCREEN_WIDTH // 2, SCREEN_HEIGHT - 5),
         color=AMBER,
         fontsize=18,
         align="left",
     )
	def drawGrid(self):
		self.bg = pygame.transform.scale(self.bg_original,(self.x1-self.x0,self.y1-self.y0))
		self.surface.blit(self.bg,(0,0))
		self.menu.fill(self.menuColor)
		tsurf, tpos = ptext.draw(self.menuStr,midleft=(self.x_step,self.y_step),fontname="./fonts/UbuntuMono-Regular.ttf",color=self.menuFontColor, shadow=(1,1),scolor=(128,128,128),fontsize=15, width=(self.menu.get_width() - self.x_step*2))
		self.menu.blit(tsurf,tpos)
		SCR.fill((0,0,0))
		SCR.blit(self.surface,(self.x0, self.y0))
		SCR.blit(self.menu,(self.x0, self.y0 - 2*self.y_step))
		pygame.display.flip()
Beispiel #22
0
 def title_start(self, old_context):
     self.state = TITLE_SCREEN
     context = Context()
     context.done = False
     context.name, context.name_pos = ptext.draw("ÄH!",
                                                 midtop=(SCREEN_WIDTH // 2,
                                                         20),
                                                 color=AMBER,
                                                 fontsize=150,
                                                 surf=None)
     return context
Beispiel #23
0
    def destroy(self, points):
        self._destroy = True
        self._destroy_ticker = self.DESTROY_TICK_TIME

        self.image = ptext.draw(points, (0, 0),
                                surf=None,
                                fontname='assets/GochiHand-Regular.ttf',
                                fontsize=50,
                                color="white",
                                owidth=1.5,
                                ocolor="black")[0]
Beispiel #24
0
def draw_main_menu(gameDisplay, width, height):
    # Draws the main menu background
    background = pygame.Rect(0, 0, width, height)
    backgroundColour = pygame.Color(252, 219, 126)
    pygame.draw.rect(gameDisplay, backgroundColour, background)

    fontsize = min(width, height) / 8
    titleX = width / 80
    titleY = height / 16

    # Draws the title
    ptext.draw("Chess", (titleX, titleY),
               color=(255, 0, 0),
               fontsize=fontsize,
               underline=True)

    itemFontSize = fontsize * 2 / 3

    # Draws the items of the main menu
    ptext.draw("2 player", (titleX, titleY * 4),
               color=(255, 0, 0),
               fontsize=itemFontSize)
    ptext.draw("Multiplayer", (titleX, titleY * 5),
               color=(255, 0, 0),
               fontsize=itemFontSize)
Beispiel #25
0
def set_up_host_screen(state, host, port):
    # Draws the background of the set up multiplayer screen
    background = pygame.Rect(0, 0, state.WIDTH, state.HEIGHT)
    backgroundColour = pygame.Color(252, 219, 126)
    pygame.draw.rect(state.GAME_DISPLAY, backgroundColour, background)

    fontsize = min(state.WIDTH, state.HEIGHT) / 8
    titleX = state.WIDTH / 80
    titleY = state.HEIGHT / 16

    # Draws the title
    ptext.draw("Host game", (titleX, titleY),
               color=(255, 0, 0),
               fontsize=fontsize,
               underline=True)

    itemFontSize = fontsize * 2 / 3

    # Draws the items of the multiplayer menu
    ptext.draw("IP Address: " + host, (titleX, titleY * 4),
               color=(255, 0, 0),
               fontsize=itemFontSize)
    ptext.draw("Port: " + str(port), (titleX, titleY * 5),
               color=(255, 0, 0),
               fontsize=itemFontSize)
def draw_window(bear_rect, a_position, b_position, a_let, b_let, bear,
                string_bear, string_a, string_b, background):
    # function to update display window, defining background, bear location (mobile), A/B response option location, and text
    win.blit(
        background,
        (0, 0))  # attach/blit background image as surface onto entire window
    win.blit(bear,
             (bear_rect.x,
              bear_rect.y))  # attach/blit image as surface onto rectangle
    win.blit(a_let, (a_position.x, a_position.y))
    win.blit(b_let, (b_position.x, b_position.y))
    text_location = [bear_rect.x - 400, bear_rect.y - 100
                     ]  # define location of text relative to bear
    # ptext.draw function comes from ptext module, command structure given in ptext.py
    ptext.draw(string_bear, (text_location[0], text_location[1]),
               align="center",
               width=400,
               color=brown,
               background=white
               )  # create variable string_bear, defining text "spoken" by bear
    ptext.draw(string_a, (a_position.x - 120, a_position.y - 120),
               fontsize=40,
               align="center",
               width=350,
               color=brown,
               background=white)  # response A text
    ptext.draw(string_b, (b_position.x - 120, b_position.y - 120),
               fontsize=40,
               align="center",
               width=350,
               color=brown,
               background=white)  # response B text
    pygame.display.flip()  # flip to display loaded information
Beispiel #27
0
def draw_window(bear_rect, a_position, b_position, a_let, b_let, bear,
                string_bear, string_a, string_b, background):
    win.blit(background, (0, 0))
    win.blit(bear, (bear_rect.x, bear_rect.y))
    win.blit(a_let, (a_position.x, a_position.y))
    win.blit(b_let, (b_position.x, b_position.y))
    text_location = [bear_rect.x - 400, bear_rect.y - 100]
    ptext.draw(string_bear, (text_location[0], text_location[1]),
               align="center",
               width=400,
               color=brown,
               background=white)
    ptext.draw(string_a, (a_position.x - 120, a_position.y - 120),
               fontsize=40,
               align="center",
               width=350,
               color=brown,
               background=white)
    ptext.draw(string_b, (b_position.x - 120, b_position.y - 120),
               fontsize=40,
               align="center",
               width=350,
               color=brown,
               background=white)
    pygame.display.flip()
Beispiel #28
0
def set_up_multiplayer_screen(gameDisplay, width, height):
    # Draws the background of the set up multiplayer screen
    background = pygame.Rect(0, 0, width, height)
    backgroundColour = pygame.Color(252, 219, 126)
    pygame.draw.rect(gameDisplay, backgroundColour, background)

    fontsize = min(width, height) / 8
    titleX = width / 80
    titleY = height / 16

    # Draws the title
    ptext.draw("Set up game", (titleX, titleY),
               color=(255, 0, 0),
               fontsize=fontsize,
               underline=True)

    itemFontSize = fontsize * 2 / 3

    # Draws the items of the multiplayer menu
    ptext.draw("Host game", (titleX, titleY * 4),
               color=(255, 0, 0),
               fontsize=itemFontSize)
    ptext.draw("Join game", (titleX, titleY * 5),
               color=(255, 0, 0),
               fontsize=itemFontSize)
Beispiel #29
0
 def render(self):
     x_offset = 32
     y_offset = 32
     self.source_surface.blit(self.base_surface, (x_offset, y_offset))
     ptext.draw(self.title,
                top=(64 + y_offset),
                centerx=(352 + (x_offset / 2)),
                fontsize=72.0,
                color="black")
     loop_x = (352 + (x_offset / 2))
     loop_y = (256 + y_offset)
     for item in self.options:
         ptext.draw(str(item),
                    centerx=loop_x,
                    centery=loop_y,
                    fontsize=48,
                    color="black")
         loop_y = (loop_y + 64)
     arrow_y = (64 * int(self.current_option)) + (256 + y_offset) - (
         int(self.cursor.get_height()) / 2)
     arrow_x = int(loop_x - 152)
     self.source_surface.blit(self.cursor, (arrow_x, arrow_y))
Beispiel #30
0
 def draw(*args,
          size=3,
          color="white",
          gcolor="white",
          scolor="black",
          **kwargs) -> Tuple[pg.Surface, Position]:
     return ptext.draw(*args,
                       fontname="tetris",
                       fontsize=8 * size,
                       color=pg.Color(color),
                       gcolor=pg.Color(gcolor),
                       scolor=pg.Color(scolor),
                       surf=ctx.surface,
                       **kwargs)
Beispiel #31
0
"""Quick usage examples from the README file"""

import pygame
import ptext

screen = pygame.display.set_mode((854, 480))
screen.fill((0, 30, 60))

ptext.draw("Text color", (50, 30), color="orange")
ptext.draw("Font name and size", (20, 100), fontname="fonts/Boogaloo.ttf", fontsize=60)
ptext.draw("Positioned text", topright=(840, 20))
ptext.draw("Allow me to demonstrate wrapped text.", (90, 210), width=180, lineheight=1.5)
ptext.draw("Outlined text", (400, 70), owidth=1.5, ocolor=(255,255,0), color=(0,0,0))
ptext.draw("Drop shadow", (640, 110), shadow=(2,2), scolor="#202020")
ptext.draw("Color gradient", (540, 170), color="red", gcolor="purple")
ptext.draw("Transparency", (700, 240), alpha=0.1)
ptext.draw("Vertical text", midleft=(40, 440), angle=90)
ptext.draw("All together now:\nCombining the above options",
    midbottom=(427,460), width=360, fontname="fonts/Boogaloo.ttf", fontsize=48,
    color="#AAFF00", gcolor="#66AA00", owidth=1.5, ocolor="black", alpha=0.8)

pygame.display.flip()
while not any(event.type in (pygame.KEYDOWN, pygame.QUIT) for event in pygame.event.get()):
	pass

Beispiel #32
0
screen = pygame.display.set_mode((sx, sy))
pygame.display.set_caption("Clooky Clunker")

score, totalscore, clunkers = 0, 0, 0
nextgoal = 0
tgoal = -100
clunks = []
tbuy, buytext = -100, ""
t = 0

buttonrects = [pygame.Rect((50, 120 + 85 * j, 180, 70)) for j in range(4)]
buttonnames = ["auto-clunker", "clunkutron", "turbo enclunkulator", "clunx capacitor"]
buttoncosts = [10, 400, 12000, 250000]

# Pre-draw the title, using a gradient.
titleargs = ptext.draw("Clooky Clunker", midtop=(sx/2, 10), fontname="CherryCreamSoda", fontsize=64,
	owidth=1.2, color="0x884400", gcolor="0x442200", surf=None, cache=False)

playing = True
clock = pygame.time.Clock()
while playing:
	dt = 0.001 * clock.tick()
	t += dt

	clickpos = None
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			playing = False
		elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
			playing = False
		elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
			clickpos = event.pos
Beispiel #33
0
def draw_labels(iso_mode):
    # draw all the text on the screen (axis labels, current location, etc.)
    ptext.draw("Press <space> to change modes", midbottom=(400, 590))
    if iso_mode:
        ptext.draw("X", (610, 120), fontsize=40)
        ptext.draw("Y", (180, 120), fontsize=40)
        # ptext.draw("(0,0)", (390, 15))
        ptext.draw("X OFFSET: "+str(ISO_OFFSETX), bottomright=(790, 550), fontsize=30)
        ptext.draw("Y OFFSET: "+str(ISO_OFFSETY), bottomright=(790, 590), fontsize=30)
        ptext.draw("Grid Pos:", bottomleft=(10, 500), fontsize=30, fontname=None)
        ptext.draw("({:.0f}, {:.0f})".format(pos.x, pos.y),
                   bottomleft=(10, 530), fontsize=40,  fontname=None)
        ptext.draw("Screen Pos:", bottomleft=(10, 560), fontsize=30, fontname=None)
        ptext.draw("({:.0f}, {:.0f})".format(scr_pos.x, scr_pos.y),
                   bottomleft=(10, 590), fontsize=40, fontname=None)
    else:
        ptext.draw("X", midtop=(300, 10), fontsize=40)
        ptext.draw("Y", midleft=(20, 300), fontsize=40)
        ptext.draw("X OFFSET: "+str(ORTHO_OFFSETX), bottomright=(790, 550), fontsize=30)
        ptext.draw("Y OFFSET: "+str(ORTHO_OFFSETY), bottomright=(790, 590), fontsize=30)
        ptext.draw("Grid Pos:", topleft=(560, 50), fontsize=30, fontname=None)
        ptext.draw("({:.0f}, {:.0f})".format(pos.x, pos.y),
                   topleft=(560, 80), fontsize=40, fontname=None)
        ptext.draw("Screen Pos:", topleft=(560, 120), fontsize=30, fontname=None)
        ptext.draw("({:.0f}, {:.0f})".format(scr_pos.x, scr_pos.y),
                   topleft=(560, 150), fontsize=40, fontname=None)