Exemplo n.º 1
0
def pageMessageSingleView(message, page_nr):
    global buttons
    initButtons(pageMessageSingleView)
    
    print "MessageSingleView:", message

    buttons[pageMessageSingleView][1].np_value= {'page_nr': page_nr}    #allow go back to correct page

    msg_surface= pygame.Surface((300,198), pygame.SRCALPHA)
    msg_surface.convert_alpha()
    
    msg_surface.fill((255,255,255))
    msg_surface.fill((0,0,0), pygame.Rect(1,1,298, 196))

    txtFont = pygame.font.SysFont("opensans", 16)
    txtRect= pygame.Rect(10, 6, 280, 184)

    try:
        rendered_text = render_textrect(message['content'], txtFont, txtRect, (255, 255, 255), (0, 0, 0), 0)
    except TextRectException:
        print 'MessageSingleView: text to long'
        rendered_text = render_textrect("Error:\nCouldn't render text, doesn't fit", txtFont, txtRect, (255, 255, 255), (0, 0, 0), 0)

    msg_surface.blit(rendered_text, txtRect.topleft)
    screen.blit(msg_surface, (10,10))
    pygame.display.update()

    buttons[pageMessageSingleView].append(pisms_ui.Button((148, 218, 24, 22), bg='btn_trash', np=pageDeleteMessage,
        np_value={'message': message, 'page_nr': page_nr}))
def load_results(screen, fitResults, font, data_rect, g, vi, Cd, state):
    # There are 3 possible states: loading = 0, fit data = 1, and advanced = 2
    if state == 0:
        fitResults[0] = render_textrect("",
                                        font,
                                        data_rect, (255, 0, 0), (0, 0, 0),
                                        justification=1)
        screen.blit(fitResults[0], (15, 210))
        screen.blit(fitResults[0], (15, 240))
        screen.blit(fitResults[0], (15, 270))
    elif state in [1, 2]:
        fitResults[0] = render_textrect("g = " + str(g) + " m/s^2",
                                        font,
                                        data_rect, (255, 0, 0), (0, 0, 0),
                                        justification=1)
        fitResults[1] = render_textrect("vi = " + str(vi) + " m/s",
                                        font,
                                        data_rect, (255, 0, 0), (0, 0, 0),
                                        justification=1)
        fitResults[2] = render_textrect("",
                                        font,
                                        data_rect, (255, 0, 0), (0, 0, 0),
                                        justification=1)
        screen.blit(fitResults[0], (15, 210))
        screen.blit(fitResults[1], (15, 240))
        screen.blit(fitResults[2], (15, 270))
    if state == 2:
        fitResults[2] = render_textrect("Cd = " + str(Cd),
                                        font,
                                        data_rect, (255, 0, 0), (0, 0, 0),
                                        justification=1)
        screen.blit(fitResults[2], (15, 270))

    return fitResults
Exemplo n.º 3
0
    def showBookDetails(self, screen, options):
        self.bookNumber = self.index
        print "index", self.index
        book = self.bookshelf[self.bookNumber]
        
        self.font = pygame.font.SysFont('Arial', 15)
        
        rendered_title = tx.render_textrect("\'" + book.title + "\' by \'" + book.author +"\'", self.font, Rect(20, 200, 400, 400), (255, 255, 255), (48, 48, 48), 0)
        screen.blit(rendered_title, options.lowerHalfScreenrect.topleft)
        
        file = open(options.bookshelfPath +'/' + book.filepath + '/' + "text.txt", 'r')
        content = file.read()

        (timeToRead, numWords, self.summary) = Summarize.main(content, 10, needSummary=True)
        book.timeToRead = round(timeToRead,2)
        self.summary = self.summary[:650] + "..."
        print "*summary*", self.summary, " : ", "*timeToRead*", book.timeToRead
        
        screen.blit(self.font.render("Total time : " + str(book.timeToRead) + " min", True, (250,150,150)), (0, 220))
        
        rendered_sumtitle = tx.render_textrect("Summary (There were " + str(numWords) + " words in actual document)", self.font, Rect(20, 240, 400, 400), (48, 48, 48), (200, 200, 200), 0)
        screen.blit(rendered_sumtitle, (0, 240))
        
        rendered_summary = tx.render_textrect(self.summary, self.font, options.summary, (60, 60, 60), (230, 230, 230), 0)
        
        if rendered_summary:
            screen.blit(rendered_summary, options.summary.topleft)

        #screen.blit(self.font.render(summary, True, (255,0,0)), (40, 200))
        pygame.display.flip()
Exemplo n.º 4
0
    def changeVal(self, val=None):
        if not val is None:
            self.val = val
        self.panel = pygame.Surface(self.rect.size)
        self.panel.blit(self.backPanel, (0, 0))

        font = CHARACTER_SELECTION_FONT
        textHeight = font.get_linesize() + 2
        tempRect = Rect((0, 0), (self.rect.width, textHeight))

        text = textrect.render_textrect(self.name, font, tempRect,
                                        CHARACTER_SELECTION_FONT_COLOR,
                                        ALMOST_BLACK, 0, True)
        tempRect = Rect((0, 0), text.get_size())
        tempRect.top = ((CHARACTER_SELECT_PANEL_SIZE[1] / 2) -
                        (tempRect.height / 2))
        loc = (tempRect.left + CHARACTER_SELECT_PANEL_BORDER_WIDTH +
               CHARACTER_SELECT_PANEL_BORDER_SIZE, tempRect.top)
        self.panel.blit(text, loc)

        if self.ready:
            msg = "READY"
            color = CHARACTER_SELECTION_READY_COLOR
        else:
            msg = str(self.val) + "/" + str(self.maxVal)
            color = CHARACTER_SELECTION_FONT_COLOR
        text = textrect.render_textrect(msg, font, tempRect, color,
                                        ALMOST_BLACK, 2, True)
        loc = (tempRect.left - CHARACTER_SELECT_PANEL_BORDER_WIDTH -
               CHARACTER_SELECT_PANEL_BORDER_SIZE, tempRect.top)
        self.panel.blit(text, loc)
Exemplo n.º 5
0
 def draw(self, surf):
     if self.view == VIEW_MAINMENU:
         surf.fill(COL_MENUBG)
         for button in self.mainmenu_buttons:
             col = COL_BPLAY #Default
             text = button
             if button == "play":
                 col = COL_BPLAY
                 text = "Play!"
             elif button == "reset":
                 col = COL_BRESET
                 text = "Reset\nProgress"
             elif button == "quit":
                 col = COL_BQUIT
                 text = "Quit Game"
             
             pygame.draw.rect(surf,col,self.mainmenu_buttons[button])
             pygame.draw.rect(surf,(255,255,255),self.mainmenu_buttons[button].inflate(3,3),3)
             pygame.draw.rect(surf,(255,255,255),self.mainmenu_buttons[button].inflate(-8,-8),1)
             
             tsurf = render_textrect(text,self.menufont,self.mainmenu_buttons[button].inflate(-10,-10), COL_BTEXT, (0,0,0,0),1)
             surf.blit(tsurf,self.mainmenu_buttons[button])
         
         
         prog = self.menufont.render("Progress: %d out of %d levels"%(len(self.completedlevels),len(self.alllevels)),1,COL_TEXT)
         surf.blit(prog,(50,650))
         
         surf.blit(self.rendered_cache['titletopper'],(0,0))
         
         xoffset = 576/2 - sum([i.get_width() for i in self.rendered_cache['title']])/2
         for i,s in enumerate(self.rendered_cache['title']):
             surf.blit(s,(xoffset,150+(i*40)))
             xoffset += s.get_width()
         
     
     elif self.view == VIEW_END:
         surf.fill(COL_MENUBG)
         tsurf = render_textrect("You won!\nProgress has been reset.\nPress any key to continue back to the main menu.",self.menufont,surf.get_rect().inflate(-100,-100), COL_BTEXT, (0,0,0,0),1)
         surf.blit(tsurf,surf.get_rect())
         
     elif self.view == VIEW_GAME:
         gm = self.gm
         surf.fill(COL_BG)
         gm.draw()
         surf.blit(gm.surf,(0,0))
 
         for i,line in enumerate(gm.text):
             yoffset = i*self.mainfont.get_height()
             surf.blit(self.mainfont.render(line, 0, COL_TEXT),(10,590+yoffset))
 
         if gm.curworld.maxhistory != -1:
             hourleft = gm.curworld.maxhistory-gm.curworld.ticks%gm.curworld.maxhistory -1
             surf.blit(self.dayfont.render("Hours Left: %d"%hourleft,1,COL_TEXT),(10,10))
         if gm.curworld.maxlives > 0:
             livesleft = gm.curworld.maxlives - gm.curplr.generation-1
             surf.blit(self.rendered_cache['livesleft'],(10,25))
             x = 10+self.rendered_cache['livesleft'].get_width()
             y = 25+ self.dayfont.get_ascent()/2 + 6
             for i in xrange(livesleft):
                 pygame.draw.circle(surf,COL_PLAYER,(x+(i*13),y),6)
Exemplo n.º 6
0
    def changeVal(self, val=None):
        if not val is None:
            self.val = val
        self.panel = pygame.Surface(self.rect.size)
        self.panel.blit(self.backPanel, (0, 0))

        font = CHARACTER_SELECTION_FONT
        textHeight = font.get_linesize() + 2
        tempRect = Rect((0, 0), (self.rect.width, textHeight))

        text = textrect.render_textrect(
            self.name, font, tempRect, CHARACTER_SELECTION_FONT_COLOR, ALMOST_BLACK, 0, True
        )
        tempRect = Rect((0, 0), text.get_size())
        tempRect.top = (CHARACTER_SELECT_PANEL_SIZE[1] / 2) - (tempRect.height / 2)
        loc = (tempRect.left + CHARACTER_SELECT_PANEL_BORDER_WIDTH + CHARACTER_SELECT_PANEL_BORDER_SIZE, tempRect.top)
        self.panel.blit(text, loc)

        if self.ready:
            msg = "READY"
            color = CHARACTER_SELECTION_READY_COLOR
        else:
            msg = str(self.val) + "/" + str(self.maxVal)
            color = CHARACTER_SELECTION_FONT_COLOR
        text = textrect.render_textrect(msg, font, tempRect, color, ALMOST_BLACK, 2, True)
        loc = (tempRect.left - CHARACTER_SELECT_PANEL_BORDER_WIDTH - CHARACTER_SELECT_PANEL_BORDER_SIZE, tempRect.top)
        self.panel.blit(text, loc)
Exemplo n.º 7
0
 def updateStructureCount(self, fortressCount, spireCount, altarCount):
     self.fortressCount = fortressCount
     self.spireCount = spireCount
     self.altarCount = altarCount
     
     self.structureCountPanel = pygame.Surface(self.structureCountPanelRect.size)
     self.structureCountPanel.fill(UNIT_HUD_COLORS[self.team])
     
     self.structureCountPanel.blit(self.fortressIcon, self.fortressIconRect.topleft)
     self.structureCountPanel.blit(self.spireIcon, self.spireIconRect.topleft)
     self.structureCountPanel.blit(self.altarIcon, self.altarIconRect.topleft)
     
     textRect = Rect((0,0), (100, STRUCTURE_COUNT_FONT.get_height() + 4))
     
     textSurface = textrect.render_textrect(" x" + str(self.fortressCount), STRUCTURE_COUNT_FONT, textRect,
                                            ALMOST_BLACK, BLACK, 0, True)
     textRect.bottomleft = self.fortressIconRect.bottomright
     self.structureCountPanel.blit(textSurface, textRect.topleft)
     
     
     textSurface = textrect.render_textrect(" x" + str(self.spireCount), STRUCTURE_COUNT_FONT, textRect,
                                            ALMOST_BLACK, BLACK, 0, True)
     textRect.left = self.spireIconRect.right - 3
     self.structureCountPanel.blit(textSurface, textRect.topleft)
     
     textSurface = textrect.render_textrect(" x" + str(self.altarCount), STRUCTURE_COUNT_FONT, textRect,
                                            ALMOST_BLACK, BLACK, 0, True)
     textRect.left = self.altarIconRect.right - 3
     self.structureCountPanel.blit(textSurface, textRect.topleft)
Exemplo n.º 8
0
def title_screen(episode=None):
    global firstEpisode, loadingGame
    textSurface = None
    titleImage = None
    try:
        titleImage = pygame.image.load(TITLE_IMAGES[0]).convert()
        titleImage = pygame.transform.scale(titleImage, (pygame.display.Info().current_w, pygame.display.Info().current_h))
    except IOError:
        textSurface = textrect.render_textrect(get_title(), #+ (":" if get_subtitle() != "" else ""), 
                universal.font, universal.worldView, LIGHT_GREY, DARK_GREY, 1)
    except IndexError:
        textSurface = textrect.render_textrect(get_title(), #+ (":" if get_subtitle() != "" else ""), 
                universal.font, universal.worldView, LIGHT_GREY, DARK_GREY, 1)
    titleImages = []
    if os.path.exists(os.path.join(os.getcwd(), 'save')) and '.init.sav' in os.listdir(os.path.join(os.getcwd(), 'save')):
        #townmode.clear_rooms()
        townmode.previousMode = None
        townmode.load_game('.init.sav', preserveLoadName=False)
    else:
        townmode.save_game('.init.sav', preserveSaveName=False)
    assert(episode is not None or firstEpisode is not None)
    if episode is not None:
        firstEpisode = episode
    screen = universal.get_screen()
    worldView = universal.get_world_view()
    background = universal.get_background()
    screen.fill(universal.DARK_GREY)
    font = pygame.font.SysFont(universal.FONT_LIST, 50)
    wvMidLeft = worldView.midleft
    if loadingGame:
        for i in range(1, len(TITLE_IMAGES)):
            try:
                titleImages.append(pygame.image.load(TITLE_IMAGES[i]))
                titleImages[-1] = pygame.transform.scale(titleImages[-1], (pygame.display.Info().current_w, pygame.display.Info().current_h))
            except IOError:
                continue
        opening_crawl()
        loadingGame = False
    music.play_music(music.THEME)
    universal.set_commands(['(S)tart', '(L)oad', '(A)cknowledgments', '(Esc)Quit'])
    universal.set_command_interpreter(title_screen_interpreter)
    if not skip:
        pygame.time.delay(125)
        for i in range(0, len(titleImages)):
            screen.blit(titleImages[i], worldView.topleft)
            pygame.time.delay(25)
            pygame.display.flip()
    if titleImage is not None:
        screen.blit(titleImage, worldView.topleft)
    else:
        screen.blit(textSurface, worldView.centerleft)
    pygame.display.flip()
    while 1:
        universal.textToDisplay = ''
        universal.titleText = ''
        for event in pygame.event.get():
            if event.type == KEYUP:
                return [universal.get_command_view()]
Exemplo n.º 9
0
    def makeXPBox(self):
        self.xpMeter = meter.Meter(
            (0, 0),
            PLANNING_XP_BAR_SIZE[0],
            PLANNING_XP_BAR_SIZE[1],
            self.xp,
            PLANNING_XP_BAR_COLOR_FULL,
            PLANNING_XP_BAR_COLOR_EMPTY,
        )
        tempHeight = PLANNING_XP_BAR_SIZE[1]
        if tempHeight < PLANNING_XP_TEXT_SIZE[1]:
            tempHeight = PLANNING_XP_TEXT_SIZE[1]
        tempRect = pygame.Rect(
            (0, 0),
            (
                PLANNING_XP_BAR_SIZE[0] + (PLANNING_XP_BAR_PADDING * 3) + PLANNING_XP_TEXT_SIZE[0],
                tempHeight + (PLANNING_XP_BAR_PADDING * 4) + (PLANNING_XP_TEXT2_SIZE[1] * 2),
            ),
        )
        self.xpBox = box.Box(
            tempRect, PLANNING_BOX_PATTERN, PLANNING_BOX_PATTERN_SIZE, PLANNING_BOX_BORDER, PLANNING_BOX_BORDER_SIZE
        )

        tempRect = pygame.Rect(
            (PLANNING_XP_BAR_PADDING, PLANNING_XP_BAR_PADDING), (PLANNING_XP_TEXT_SIZE[0], PLANNING_XP_TEXT_SIZE[1])
        )
        tempFont = pygame.font.Font(PLANNING_BOX_FONT, PLANNING_BOX_FONT_SIZE)
        textSurface = textrect.render_textrect("EXP", tempFont, tempRect, BOX_FONT_COLOR, (0, 0, 0), 1, True)
        self.xpBox.mainPane.blit(textSurface, tempRect.topleft)
        self.xpTextRect = tempRect

        tempRect = pygame.Rect(
            (PLANNING_XP_BAR_PADDING, PLANNING_XP_BAR_PADDING + tempRect.height),
            (PLANNING_XP_TEXT2_SIZE[0], PLANNING_XP_TEXT2_SIZE[1]),
        )
        textSurface = textrect.render_textrect("Reserve:", tempFont, tempRect, BOX_FONT_COLOR, (0, 0, 0), 0, True)
        self.xpBox.mainPane.blit(textSurface, tempRect.topleft)

        self.rectReserve = pygame.Rect(tempRect)
        self.rectReserve.right = self.xpBox.rect.width - PLANNING_XP_BAR_PADDING

        tempRect.top += tempRect.height + PLANNING_XP_BAR_PADDING
        textSurface = textrect.render_textrect("Next Lvl:", tempFont, tempRect, BOX_FONT_COLOR, (0, 0, 0), 0, True)
        self.xpBox.mainPane.blit(textSurface, tempRect.topleft)

        self.rectNext = pygame.Rect(tempRect)
        self.rectNext.right = self.xpBox.rect.width - PLANNING_XP_BAR_PADDING

        self.xpBox.rect.top = self.pieceBox.box.rect.bottom + 5
        self.xpBox.center(ENTIRE_SCREEN, True, False)
        self.xpMeter.center(self.xpBox.rect, True, False)
        self.xpMeter.loc[1] += PLANNING_XP_BAR_PADDING
        self.xpMeter.loc[0] += self.xpBox.rect.left + (PLANNING_XP_TEXT_SIZE[0] / 2)
        self.xpMeter.loc[1] += self.xpBox.rect.top
Exemplo n.º 10
0
    def updateXP(self):
        tempFont = pygame.font.Font(PLANNING_BOX_FONT, PLANNING_BOX_FONT_SIZE)

        self.surfaceReserve = textrect.render_textrect(
            str(self.xp), tempFont, self.rectReserve, BOX_FONT_COLOR, (0, 0, 0), 2, True
        )

        if self.validCharacter():
            tempText = str(self.currNextLevel())
        else:
            tempText = ""
        self.surfaceNext = textrect.render_textrect(
            tempText, tempFont, self.rectNext, BOX_FONT_COLOR, (0, 0, 0), 2, True
        )
Exemplo n.º 11
0
    def __init__(self, chapterNumber, chapterName):

        chapterNumber += 1
        
        pattern1 = pygame.image.load(os.path.join(GRAPHICS_PATH, CHAPTER_NAME_PATTERN)).convert_alpha()
        pattern2 = pygame.transform.flip(pattern1, True, False)
        border1 = pygame.image.load(os.path.join(GRAPHICS_PATH, CHAPTER_NAME_BORDER)).convert_alpha()
        border2 = pygame.transform.rotate(border1, 90)
        border3 = pygame.transform.rotate(border1, 180)
        border4 = pygame.transform.rotate(border1, 270)

        font1 = pygame.font.Font(FONTS[0], CHAPTER_NAME_FONTSIZE1)
        font2 = pygame.font.Font(FONTS[0], CHAPTER_NAME_FONTSIZE2)

        sizeX = (CHAPTER_NAME_PATTERN_SIZE * 2)
        sizeY = CHAPTER_NAME_BAR_HEIGHT
        posX = (SCREEN_SIZE[0] / 2) - (sizeX / 2)
        posY = (SCREEN_SIZE[1] / 2) - (sizeY / 2)
        self.rect = pygame.Rect( (posX, posY), (sizeX, sizeY))
        self.box = pygame.Surface( (sizeX, sizeY) )

        #Create Primary Bar
        for y in range (sizeY):
            self.box.blit(pattern1, (0, y))
            tempX = (int(sizeX / 2))
            self.box.blit(pattern2, (tempX, y))

        
        #Create Text
        tempRect = pygame.Rect( (0, (CHAPTER_NAME_BORDER_SIZE + 2)), (self.rect.width, (CHAPTER_NAME_FONTSIZE1 + 4)) )
        tempText = "Chapter " + str(chapterNumber)
        textrect1 = textrect.render_textrect(tempText, font1, tempRect, CHAPTER_NAME_COLOR, (0, 0, 0), 1, True)
        self.box.blit(textrect1, tempRect.topleft)

        tempRect = pygame.Rect( (0, 0), (self.rect.width, (CHAPTER_NAME_FONTSIZE2 + 4)) )
        tempRect.top = (self.rect.height / 2) - (tempRect.height / 2)
        textrect2 = textrect.render_textrect(chapterName, font2, tempRect, CHAPTER_NAME_COLOR, (0, 0, 0), 1, True)
        self.box.blit(textrect2, tempRect.topleft)

        #Create Border Sides
        for y in range (sizeY):
            self.box.blit(border2, (0, y))
            tempX = sizeX - CHAPTER_NAME_BORDER_SIZE
            self.box.blit(border4, (tempX, y))
        for x in range(sizeX):
            self.box.blit(border1, (x, 0))
            tempY = sizeY - CHAPTER_NAME_BORDER_SIZE
            self.box.blit(border3, (x, tempY))
Exemplo n.º 12
0
def printText(screen, mousePos):
    pos = getZoomPos(mousePos)
    pixelPos = posRelatedToAnchor(pos)
    text = textrect.render_textrect(str(pixelPos), FONTS[0],
                                    Rect((0, 0), (SCREEN_SIZE[0], SCREEN_SIZE[1])),
                                    (250, 250, 250), (5, 5, 5), 0, True)
    screen.blit(text, (mousePos[0] + 15, mousePos[1] - 10))
Exemplo n.º 13
0
    def __init__(self, inText, inColor, inLoc):

        self.rect = pygame.Rect(inLoc, BATTLE_TEXT_SIZE)
        font = pygame.font.Font(BATTLE_TEXT_FONT, BATTLE_TEXT_FONT_SIZE)
        self.image = textrect.render_textrect(inText, font, self.rect, inColor, BLACK, 1, True)
        self.count = 0
        self.remove = False
Exemplo n.º 14
0
 def __init__(self, fade):
     super(Model, self).__init__()
     
     self.bg = pygame.Surface(SCREEN_SIZE)
     self.bg.fill(BLACK)
     
     creditData =    [
                         ["Christopher \"Southpaw Hare\" Czyzewski", ["Lead Designer", "Lead Programmer", "Creative Director",
                                                                      "Marketing Director", "Distribution Director"]],
                         ["Daniel \"Wopple\" Tashjian", ["Programmer", "Tester"]]
                         ["Matthew Grisham", ["Gameplay Designer", "Map Designer"]],
                         ["Kit", ["Character Artist", "Map Artist", "Background Artist"]],
                         ["Raquel M. Richardson", ["Portrait Artist"]],
                         
                         ["Additional Testers", ["Randy Sabella", "Robert Morris", "Eric Collins", "Fox Zeta", "Coffeefox"]]
                     ]
     
     for data in creditData:
         header = data[0]
         subItems = data[1]
         
         headerRect = Rect((0, 0), (40, SCREEN_SIZE[1]))
         headerImage = textrect.render_textrect(header, CREDITS_HEADER_FONT, headerRect, ALMOST_BLACK, WHITE, 0, True)
         self.credits.append(CreditText(headerRect, headerImage))
     
     self.credits = []
Exemplo n.º 15
0
    def _showcalibrationscreen(self, showtext=TRUE):
        "displays calibration screen until <<enter>> is pressed"
        img, rect = load_image(self.dcalibrationimage)
        self.dscreen.blit(img, rect)

        if showtext:
            my_font = pygame.font.Font(None, 22)
            tboxwidth = 300
            tboxheight = 125
            xpos = self.dscreen.get_width() / 2 - tboxwidth / 2
            ypos = 325
            my_string = 'Adjust your position so you can see all of the blue ring and none of the red ring.\n\nPress [enter] to continue.'
            my_rect = pygame.Rect((xpos, ypos, tboxwidth, tboxheight))
            rendered_text = textrect.render_textrect(my_string, my_font,
                                                     my_rect, (216, 216, 216),
                                                     (48, 48, 48), 1)

            if rendered_text:
                self.dscreen.blit(rendered_text, my_rect.topleft)

        pygame.display.update()

        pygame.event.get(
        )  #clear event queue, otherwise, was taking a long time and multiple enters could be pressed, bypassing calibration screen.
        while 1:
            event = pygame.event.wait()
            if (event.type == KEYDOWN) and (event.key == K_RETURN):
                break
Exemplo n.º 16
0
	def show(self):
		headlineFont = pygame.font.Font("leddigital.ttf", 70)
		font = pygame.font.Font(None, 50)
		run = True
		while run:
			inp = self.nowPlaying()

			# quit on "window close" and Escape
			for evt in pygame.event.get():
				if evt.type == KEYDOWN:
					if evt.key == K_ESCAPE:
						run = False
				elif evt.type == QUIT:
					return
			self.screen.fill((0, 0, 0))

			headline = headlineFont.render("mpd - Now playing:", True, (255, 0, 0))
			self.screen.blit(headline, (0, 0))

			# try to render all text and cut off if it's too large
			textRendered = False

			while not textRendered:
				try:
					# draw text and handle line breaks properly
					textSurface = render_textrect(inp, headlineFont, \
						self.screen.get_rect(), (255, 255, 255), (0, 0, 0))
					textRendered = True
				except TextRectException:
					# cut char off
					inp = inp[:-1]

			self.screen.blit(textSurface, (0, 120))
			pygame.display.flip()
			time.sleep(1)
Exemplo n.º 17
0
    def createImage(self):
        global STAT_BOX_IMAGE
        global STAT_BOX_SIZE

        statText = ["STR", "MAG", "SKI", "VIT", "WIL", "SPD"]
        elements = []
        tempRect = pygame.Rect( (0, 0), STAT_BOX_ELEMENT_SIZE )
        tempFont = pygame.font.Font(STAT_BOX_FONT, STAT_BOX_FONT_SIZE)
        for x in range(6):
            textrect1 = textrect.render_textrect(statText[x], tempFont, tempRect,
                                                 BOX_FONT_COLOR, (0, 0, 0), 0, True)
            elements.append(textrect1)

        sizeX = (STAT_BOX_ELEMENT_SIZE[0] * 2) + (STAT_BOX_BORDER_SIZE * 2) + (STAT_BOX_PADDING * 3)
        sizeY = (STAT_BOX_ELEMENT_SIZE[1] * 3) + (STAT_BOX_BORDER_SIZE * 2) + (STAT_BOX_PADDING * 2)
        STAT_BOX_SIZE = (sizeX, sizeY)
        tempRect = pygame.Rect((0, 0), (sizeX, sizeY))
        tempBox = box.Box(tempRect, STAT_BOX_PATTERN, STAT_BOX_PATTERN_SIZE,
                           STAT_BOX_BORDER, STAT_BOX_BORDER_SIZE)
        for col in range(2):
            for row in range(3):
                x, tempX, tempY = self.getXXY(col, row)
                tempBox.mainPane.blit(elements[x], (tempX, tempY))

        STAT_BOX_IMAGE = tempBox.mainPane
Exemplo n.º 18
0
def clear():
    screen.blit(background, (0, 0))
    titleFont = pygame.font.Font(None, 50)
    title_str = "Teacher's Database"
    title_rect = pygame.Rect((100,30),(600,100))
    title_print = textrect.render_textrect(title_str, titleFont, title_rect, black, grey, 1)
    screen.blit(title_print, title_rect.topleft)
Exemplo n.º 19
0
    def displaymainmenu(self):
        self.dscreen.fill((0, 0, 0))  #screen is a surface! fill it with black
        my_font = pygame.font.Font(None, 22)
        tboxwidth = 300
        tboxheight = 300
        xpos = self.dscreen.get_width() / 2 - tboxwidth / 2
        ypos = 250

        my_string = "Welcome to the Sedgwick lab!\n \nto begin, press [enter]"
        my_rect = pygame.Rect((xpos, ypos, tboxwidth, tboxheight))
        rendered_text = textrect.render_textrect(my_string, my_font, my_rect,
                                                 (216, 216, 216), (48, 48, 48),
                                                 0)
        if rendered_text:
            self.dscreen.blit(rendered_text, my_rect.topleft)
        pygame.display.update()
        #pygame.key.set_mods(KMOD_NONE)
        while 1:
            event = pygame.event.wait()
            if event.type == KEYDOWN:
                #attempting to be able to handle more complex keypresses:
                #keys = pygame.key.get_pressed()
                #pygame.key.get_mods()&(KMOD_SHIFT|KMOD_ALT) ==(KMOD_ALT|KMOD_SHIFT)
                #print pygame.key.get_mods()&(KMOD_SHIFT|KMOD_ALT|KMOD_CTRL) ==(KMOD_ALT|KMOD_SHIFT|KMOD_CTRL)
                #print (KMOD_ALT|KMOD_SHIFT|KMOD_CTRL)
                #print pygame.key.get_mods()
                #print keys
                if event.key == K_F12:  #new user
                    return 2
                elif event.key == K_RETURN:  #begin
                    return 1
                elif event.key == K_F5:  #quit
                    return 0
def save_file(keyFrames, frame_range, curFrame, font):
	Tk().withdraw()
	
	# Prompts user for what file name they would like to save their data as
	savefile = asksaveasfilename(filetypes=[("Python Pickle","*.p")])
	message = False
	message_str = ""
	message_rect = pygame.Rect((0,0), (200,150))
	temp = []
	
	# If they didn't hit cancel, this checks to see if they plotted all the data points correctly
	# If not, it will send them to the frame that they missed a data point
	if savefile != "":
		for i in range(frame_range[0], frame_range[1]+1):
			p = keyFrames[i]
			if p != (1000,1000):
				temp.append((p,(float(i)-frame_range[0])*1/float(FPS)))
			else:
				message_str = "Frame "+str(i)+" missing data point"
				message = True
				curFrame = i
				break
		
		if not message: # If there was no error, then it saves the data to the file
			savefile = check_filename(savefile)
			file = open(savefile, "wb")
			pickle.dump(temp,file)
			file.close()
			message = True
			message_str = ".p File Saved"
	
	message_area = render_textrect(message_str, font, message_rect, (255,0,0), (0,0,0), justification=1)
	return message_area, message, curFrame
Exemplo n.º 21
0
    def createImage(self):
        global MANA_BOX_IMAGE
        global MANA_BOX_SIZE
        global MANA_TICKS

        statText = ["RAGE", "SPIRIT", "FOCUS"]
        tempRect = pygame.Rect( (0, 0), MANA_BOX_ELEMENT_SIZE )
        tempFont = pygame.font.Font(MANA_BOX_FONT, MANA_BOX_FONT_SIZE)
        sizeX = (MANA_BOX_ELEMENT_SIZE[0]) + (MANA_BOX_BORDER_SIZE * 2) + (MANA_BOX_PADDING * 3) + (MANA_TICK_SPACING * (MANA_MAX - 1)) + (MANA_TICK_SIZE[0] * MANA_MAX)
        sizeY = (MANA_BOX_ELEMENT_SIZE[1] * 3) + (MANA_BOX_BORDER_SIZE * 2) + (MANA_BOX_PADDING * 2)

        tempRect = pygame.Rect((0, 0), (sizeX, sizeY))
        tempBox = box.Box(tempRect, MANA_BOX_PATTERN, MANA_BOX_PATTERN_SIZE,
                           MANA_BOX_BORDER, MANA_BOX_BORDER_SIZE)


        for x in range(3):
            textrect1 = textrect.render_textrect(statText[x], tempFont, tempRect,
                                                 BOX_FONT_COLOR, (0, 0, 0), 0, True)
            tempX = MANA_BOX_BORDER_SIZE + MANA_BOX_PADDING
            tempY = MANA_BOX_BORDER_SIZE + (MANA_BOX_PADDING * (x+1)) + (MANA_BOX_ELEMENT_SIZE[1] * x)
            MANA_BOX_SIZE = (sizeX, sizeY)
            tempRect = pygame.Rect((0, 0), (sizeX, sizeY))
            tempBox.mainPane.blit(textrect1, (tempX, tempY))

        MANA_BOX_IMAGE = tempBox.mainPane

        MANA_TICKS = []
        for m in range(4):
            tempSurface = pygame.Surface(MANA_TICK_SIZE)
            tempSurface.fill(MANA_TICK_COLORS[m])
            MANA_TICKS.append(tempSurface)
Exemplo n.º 22
0
    def __init__(self):
        super(Model, self).__init__()
        self.fadeSurface = pygame.Surface(SCREEN_SIZE)
        self.fadeSurfaceColor = []
        for i in range(3):
            self.fadeSurfaceColor.append(
                boundint.BoundInt(0, INTRO_MAX_FADE, 0))

        self.transSurface = pygame.Surface(SCREEN_SIZE)
        self.transSurface.fill(
            (INTRO_MAX_FADE, INTRO_MAX_FADE, INTRO_MAX_FADE))
        self.transAlpha = boundint.BoundInt(0, 255, 255)
        self.centerTextPos = (0, SCREEN_SIZE[1] / 2)
        self.stage = 0
        self.ticker = 0

        self.textMessages = [("Games from Beyond the Farth", 2, ALMOST_BLACK,
                              WHITE, 1, True)]
        self.textRects = []
        for i in self.textMessages:
            f = FONTS[i[1]]
            size = (SCREEN_SIZE[0], f.get_linesize() + f.get_height())
            tempRect = Rect((0, 0), size)
            self.textRects.append(
                textrect.render_textrect(i[0], f, tempRect, i[2], i[3], i[4],
                                         i[5]))
Exemplo n.º 23
0
	def aboutUs(self):
		aboutUsString = 'Η εφαρμογή αυτή υλοποιήθηκε στα πλαίσια του 3ου Σχολείου Κώδικα της Μονάδας Αριστείας ΕΛ/ΛΑΚ του Αριστοτελείου Πανεπιστημίου Θεσσαλονίκης. Συντελεστές του είναι οι:\nΑχιλλέας Μόσχος\nΣτέφανος Δραγούτσης\nΑλέξανδρος - Γεώργιος Μουντογιαννάκης\nΥπεύθυνοι του εγχειρήματος ήταν οι κ. Ιωάννης Σταμέλος και κ. Σταύρος Δημητριάδης, τους οποίους και ευχαριστούμε.'
		localFont = pygame.font.SysFont("monospace", 24)
		rectToPlaceText = pygame.Rect(0, 0, WIDTH, HEIGHT)
		rendered_text = textrect.render_textrect(aboutUsString, localFont, rectToPlaceText, dWHITE, bgImage)

		if rendered_text: 
			display.blit(rendered_text, (rectToPlaceText.left, rectToPlaceText.top))
		aboutLoop = True
		self.backButton.drawButton()
		while aboutLoop:
			for ev in pygame.event.get():
				if ev.type == QUIT:
					pygame.quit()
					sys.exit()
				if ev.type == MOUSEMOTION:
					self.backButton.hover()
				if ev.type == MOUSEBUTTONDOWN:
					if self.backButton.clicked(): #if we press the back button, we first delete it, and then we redraw the other three before we exit.
						display.blit(bgImage, display.get_rect())
						aboutLoop = False
						self.backButton.deleteButton() #not needed any more. still it's nice to have a delete function
						self.startButton.drawButton()
						self.instructionsButton.drawButton()
						self.exitButton.drawButton()
						self.gameName()
						self.aboutButton.drawButton()
						
			update()
Exemplo n.º 24
0
    def __init__(self, topRange, bottomRange, inPath):

        posX = (SCREEN_SIZE[0] / 2) - (MISSION_PICTURE_SIZE[0] / 2)
        posY = ((bottomRange - topRange) / 2) - (MISSION_PICTURE_SIZE[1] / 2) + topRange
        self.rect = pygame.Rect( (posX, posY), MISSION_PICTURE_SIZE)

        self.imageExists = False

        pathName = os.path.join(inPath, MISSION_PICTURE)
        if os.path.exists(pathName):
            image = pygame.image.load(pathName).convert_alpha()
            self.image = pygame.Surface( (self.rect.width, self.rect.height) )
            self.image.blit(image, (0, 0))
            self.imageExists = True


        global NOT_EXIST_TEXT
        global NOT_EXIST_RECT
        global SLATE
        if NOT_EXIST_TEXT is None:
            
            font = pygame.font.Font(FONTS[0], MISSION_PICTURE_NEM_SIZE)
            posY = (self.rect.height / 2) - (MISSION_PICTURE_NEM_SIZE / 2) + self.rect.top
            NOT_EXIST_RECT = pygame.Rect( (self.rect.left, posY), (self.rect.width, (MISSION_PICTURE_NEM_SIZE + 4)) )
            NOT_EXIST_TEXT = textrect.render_textrect("No Picture Available", font, NOT_EXIST_RECT, MISSION_PICTURE_NEM_COLOR, MISSION_PICTURE_COLOR, 1)

            SLATE = pygame.Surface( (self.rect.width, self.rect.height) )
            SLATE.fill (MISSION_PICTURE_COLOR, (0, 0, self.rect.width, self.rect.height))
Exemplo n.º 25
0
	def instructions(self):
		
		display.blit(bgImage, display.get_rect()) #first we delete everything
		#the instructions String. Its a long one.
		instructionsString = 'Το Mastermind είναι παιχνίδι σπάσιμου κώδικα. Ο υπολογιστής θέτει τον κώδικα, ο οποίος αποτελείται από 4 "πούλια". Κάθε πούλι χαρακτηρίζεται από το χρώμα του και τη θέση του.  Ένα πούλι μπορεί να έχει 1 από 6 χρώματα, και σε κάθε κλειδί δύο ή περισσότερα πούλια μπορούν να έχουν το ίδιο χρώμα. Σκοπός του παιχνιδιού είναι ο παίχτης να μαντέψει το κλειδί που έχει θέσει ο υπολογιστής σε 8 ή λιγότερες προσπάθειες.'
		instructionsString+=	' Ο παίχτης αρχικά μαντέυει ένα κλειδί, τοποθετώντας στην πρώτη σειρά (ξεκινώντας από κάτω) του πίνακα τυχαία έναν συνδυασμό. Όταν ο συνδυασμός είναι έτοιμος, πατώντας το κουμπί  "Έλεγχος", ο παίχτης μπορεί να τσεκάρει πόσες σωστές επιλογές χρώματος και πόσες σωστές επιλογές χρώματος και σειράς έχει κάνει. Εάν ένας παίχτης έχει βρει το σωστό χρώμα και τη σωστή σειρά από ένα οποιοδήποτε πούλι, επιστρέφεται ένας μαύρος πόντος. Εάν ένας παίχτης έχει βάλει στην υπόθεσή του ένα πούλι, το χρώμα του οποίου υπάρχει μέσα στο κλείδι, αλλά το πούλι αυτό δεν βρίσκεται στην ίδια θέση με αυτή του κλειδιού, επιστρέφεται ένας άσπρος πόντος. Το παιχνίδι τελειώνει επιτυχώς, όταν επιστραφούν 4 μαύροι πόντοι, όποτε όλα τα πούλια βρίσκονται στην ίδια θέση και έχουν το ίδιο χρώμα με αυτό του κλειδιού.\n ΠΡΟΣΟΧΗ: Οι άσπροι ή μαύροι πόντοι συμβολίζουν μόνο πόσες και όχι ποιες είναι οι σωστές υποθέσεις.'
		instructionsString+=	' Σε περίπτωση που μία υπόθεση είναι λάθος, μετά το πάτημα του "Έλεγχος", δίνεται μία νέα ευκαιρία στον παίχτη να βρει το σωστό κλειδί. Ο παίχτης πρέπει κάθε φορά να συγκρίνει κάθε υπόθεσή του με τις προηγούμενες και, μελετώντας τους άσπρους και μαύρους πόντους  που του επιστράφηκαν την εκάστοτε φορά, να καταλήξει στο σωστό αποτέλεσμα.'
	
		localFont = pygame.font.SysFont("monospace", 18) #we render a new local font so we can fit the whole instructions String.
		rectToPlaceText = pygame.Rect(0, 0, WIDTH, HEIGHT) #we create a rectangle to place our string. In this case it's the whole screen.
		rendered_text = textrect.render_textrect(instructionsString, localFont, rectToPlaceText, dWHITE, bgImage) #the result of the render_textrect method, i.e the instructions ready to be transferred in the screen (blit). 
		display.blit(bgImage, display.get_rect())
		if rendered_text: #we check if there is an actual text
				display.blit(rendered_text, (rectToPlaceText.left, rectToPlaceText.top))
		instructionsLoop = True
		self.backButton.drawButton()
		
		while instructionsLoop:
			for ev in pygame.event.get():
				if ev.type == QUIT:
					pygame.quit()
					sys.exit()
				if ev.type == MOUSEMOTION:
					self.backButton.hover()
				if ev.type == MOUSEBUTTONDOWN:
					if self.backButton.clicked(): #if we press the back button, we first delete it, and then we redraw the other three before we exit.
						display.blit(bgImage, display.get_rect())
						instructionsLoop = False
						self.backButton.deleteButton() #not needed any more. still it's nice to have a delete function
						self.startButton.drawButton()
						self.instructionsButton.drawButton()
						self.exitButton.drawButton()
						self.gameName()
						self.aboutButton.drawButton()
			update()
Exemplo n.º 26
0
	def draw( self):
		# Clear the screen
		#self.set_video_mode()
		#self.background=pygame.image.tostring(self.screen, 'RGB')
		self.screen.fill((255,255,255))

		# Draw the title
		xw,yh = self.titlefont.size("W")
		x1=(self.screen_width-740)/2
		y1=self.titletop
		x2=self.screen_width-x1
		y2= self.titletop+(yh*2+2)
		title_rec = pygame.Rect(x1,y1,x2,y2)
		rendered_text=textrect.render_textrect(self.title, self.titlefont, title_rec , (0,0,255), (255,255,255),1)
		textpos=rendered_text.get_rect()
		textpos.centerx=self.screen.get_rect().centerx
		textpos[1]=y1
		self.screen.blit(rendered_text,textpos)
		#
		#Draw Input Text Rectangle
		xw,yh = self.font.size("W")
		x1=int ((self.screen_width-750)/2)
		y1=self.texttop-5
		x2=750
		y2= yh+10
		text_rec=pygame.Rect(x1, y1 , x2 , y2 )
		pygame.draw.rect(self.screen,(0,0,0),text_rec, 1)

		# Draw the keyboard
		self.screen.blit( self.image, (self.xpos, self.ypos))
		
		#update the screen
		pygame.display.update()

		self.draw_text()
Exemplo n.º 27
0
    def __init__(self, fade):
        super(Model, self).__init__()

        self.bg = pygame.Surface(SCREEN_SIZE)
        self.bg = scrollingbackground.ScrollingBackground(Rect((0, 0), SCREEN_SIZE), MAIN_MENU_BACKGROUND_IMAGE, [0.2, 0.5])
        
        tempRect = Rect( (50, 50), (200, 0) )
        menuOptions = ["Play Single Player", "Play via Network",
                       "Character Setup", "Options", "Credits", "Exit"]
        self.menu = minimenu.MiniMenu(tempRect, menuOptions,
                                           MAIN_MENU_FONT, MAIN_MENU_COLOR_ON,
                                           MAIN_MENU_COLOR_OFF,
                                           MAIN_MENU_COLOR_BG)
        self.menu.center(ENTIRE_SCREEN, False, True)
        self.menu.rect.left = MAIN_MENU_OFFSET_FROM_SIDE

        self.textMessages = [ ("Fimbulvetr", 3, ALMOST_BLACK, WHITE, 1, True),
                              ("War of the Great Winter", 2, ALMOST_BLACK, WHITE, 1, True)]
        self.textRects = []
        for i in self.textMessages:
            f = FONTS[i[1]]
            size = (SCREEN_SIZE[0], f.get_linesize() + f.get_height())
            tempRect = Rect( (0, 0), size )
            self.textRects.append(textrect.render_textrect(
                i[0], f, tempRect, i[2], i[3], i[4], i[5]))

        self.transSurface = pygame.Surface(SCREEN_SIZE)
        self.transSurface.fill((INTRO_MAX_FADE, INTRO_MAX_FADE, INTRO_MAX_FADE))
        self.transAlpha = boundint.BoundInt(0, 255, 255)
        self.transChecker = True
        self.transDirection = False

        if not fade:
            self.transAlpha.value = 0
            self.transChecker = False
Exemplo n.º 28
0
        def Render(self):

                # determine color scheme according to textbox status
                if self.Enabled == True:
                        if self.Clicked == True:
                                self.bordercolor = self.ColorBorderClick
                                self.textcolor = self.ColorTextClick
                        else:
				self.bordercolor = self.ColorBorderNormal
				self.textcolor = self.ColorTextNormal
                else:
                        self.bordercolor = self.ColorBorderDisabled
                        self.textcolor = self.ColorTextDisabled

                # draw textbox if visible
                if self.Visible == True:
			# textbox border set to visible?
			if self.BorderVisible == True:
	                        # yes, draw border and background
	                        pygame.draw.rect(self.Surface, self.bordercolor,(self.PosX, self.PosY, self.SizeX, self.SizeY))
	                        pygame.draw.rect(self.Surface, self.ColorBackground,(self.PosX+1, self.PosY+1, self.SizeX-2, self.SizeY-2))
			else:
				# no, draw only background
				pygame.draw.rect(self.Surface, self.ColorBackground,(self.PosX, self.PosY, self.SizeX, self.SizeY))
                        # draw button text
                        self.fontObject = pygame.font.Font(self.FontPath, self.FontSize)
                        # multiline text, use word wrapped drawing method
                        self.textrectangle = pygame.Rect((self.PosX + 1, self.PosY + 1, self.SizeX - 2, self.SizeY - 2))
                        self.textSurface = textrect.render_textrect(self.Text, self.fontObject, self.textrectangle, self.textcolor, self.ColorBackground, self.TextAlignHorizontal)
                        self.Surface.blit(self.textSurface, self.textrectangle)
                else:
                        # draw background color rectangle if invisible
			# TODO: implement background buffering/redrawing
                        pygame.draw.rect(self.Surface, self.ColorBackground, (self.PosX, self.PosY, self.SizeX, self.SizeY))
Exemplo n.º 29
0
    def __init__(self):
        super(Model, self).__init__()

        self.tempRect = Rect( (50, 50), (200, 0) )
        menuOptions = ["Host", "Client"]
        self.menuHostClient = minimenu.MiniMenu(self.tempRect, menuOptions,
                                           MAIN_MENU_FONT, MAIN_MENU_COLOR_ON,
                                           MAIN_MENU_COLOR_OFF,
                                           MAIN_MENU_COLOR_BG)
        self.menuHostClient.center(ENTIRE_SCREEN, True, True)
        
        menuOptions = ["Cancel"]
        self.menuCancelWait = minimenu.MiniMenu(self.tempRect, menuOptions,
                                           MAIN_MENU_FONT, MAIN_MENU_COLOR_ON,
                                           MAIN_MENU_COLOR_OFF,
                                           MAIN_MENU_COLOR_BG)
        self.menuCancelWait.center(ENTIRE_SCREEN, True, True)

        menuOptions = ["Try Again", "Cancel"]
        self.menuTryAgain = minimenu.MiniMenu(self.tempRect, menuOptions,
                                           MAIN_MENU_FONT, MAIN_MENU_COLOR_ON,
                                           MAIN_MENU_COLOR_OFF,
                                           MAIN_MENU_COLOR_BG)
        self.menuTryAgain.center(ENTIRE_SCREEN, True, True)
        
        self.textHostWaiting = textrect.render_textrect("Listening for Client...",
                                                        MAIN_MENU_FONT, self.tempRect,
                                                        MAIN_MENU_COLOR_OFF,
                                                        MAIN_MENU_COLOR_BG, 2)
        self.textClientWaiting = textrect.render_textrect("Searching for Host...",
                                                        MAIN_MENU_FONT, self.tempRect,
                                                        MAIN_MENU_COLOR_OFF,
                                                        MAIN_MENU_COLOR_BG, 2)
        self.textConnTimeout = textrect.render_textrect("Connection timed out",
                                                        MAIN_MENU_FONT, self.tempRect,
                                                        MAIN_MENU_COLOR_OFF,
                                                        MAIN_MENU_COLOR_BG, 1)

        self.workingIconList = []
        temp = [0, 270, 180, 90]
        for i in temp:
            theCopy = INTERFACE_GRAPHICS[3].copy()
            self.workingIconList.append(pygame.transform.rotate(theCopy, i))
        self.workingIconTick = boundint.BoundInt(0, NET_ICON_SPEED, 0, True)
        self.workingIconCurr = boundint.BoundInt(0, 3, 0, True)
        
        self.changePhase(1)
Exemplo n.º 30
0
 def updateDamagePercent(self):
     if (not self.currCharacter is None):
         if not self.currCharacter.isDead():
             self.image.blit(self.damageTag, self.damageTagRect.topleft)
             
             textSurface = textrect.render_textrect(self.currCharacter.getDamagePercentText(), DAMAGE_PERCENT_FONT, self.damagePercentRect,
                                              ALMOST_BLACK, BLACK, 1, True)
             self.image.blit(textSurface, self.damagePercentRect.topleft)
Exemplo n.º 31
0
def printText(screen, mousePos):
    pos = getZoomPos(mousePos)
    pixelPos = posRelatedToAnchor(pos)
    text = textrect.render_textrect(
        str(pixelPos), FONTS[0], Rect(
            (0, 0), (SCREEN_SIZE[0], SCREEN_SIZE[1])), (250, 250, 250),
        (5, 5, 5), 0, True)
    screen.blit(text, (mousePos[0] + 15, mousePos[1] - 10))
Exemplo n.º 32
0
    def render(self):
            # Render to the main display
            SCREEN.fill(BG_COLOR1)
            rect = pg.Rect(100, 200, 600, 500)
            surf = render_textrect(self.message, FONT_NORMAL, rect, WHITE, 1)
            SCREEN.blit(surf, rect)

            for index, item in enumerate(self.menuitems):
                item.render(index == self.selected_index)
Exemplo n.º 33
0
 def updateImage(self):
     if self.time == 0:
         msg = "GO!"
         self.startFlag = True
     else:
         msg = str(self.time)
     
     self.image = textrect.render_textrect(msg, COUNTDOWN_FONT, self.rect,
                                           COUNTDOWN_COLOR, ALMOST_BLACK, 1, True)
Exemplo n.º 34
0
 def createText(self, t, just):
     if t is None:
         self.text = None
     else:
         w = self.rect.width
         h = ENERGY_BAR_FONT.get_height() + 2
         self.text = textrect.render_textrect(t, ENERGY_BAR_FONT,
                                              Rect((0, 0), (w, h)),
                                              self.fontColor,
                                              (0, 0, 0), just, True)
def load_results(screen, fitResults, font, data_rect, g, vi, Cd, state):
	# There are 3 possible states: loading = 0, fit data = 1, and advanced = 2
	if state == 0:
		fitResults[0] = render_textrect("", font, data_rect, (255,0,0), (0,0,0), justification=1)
		screen.blit(fitResults[0],(15,210))
		screen.blit(fitResults[0],(15,240))
		screen.blit(fitResults[0],(15,270))
	elif state in [1,2]:
		fitResults[0] = render_textrect("g = "+str(g)+" m/s^2", font, data_rect, (255,0,0), (0,0,0), justification=1)
		fitResults[1] = render_textrect("vi = "+str(vi)+" m/s", font, data_rect, (255,0,0), (0,0,0), justification=1)
		fitResults[2] = render_textrect("", font, data_rect, (255,0,0), (0,0,0), justification=1)
		screen.blit(fitResults[0],(15,210))
		screen.blit(fitResults[1],(15,240))
		screen.blit(fitResults[2],(15,270))
	if state == 2:
		fitResults[2] = render_textrect("Cd = "+str(Cd), font, data_rect, (255,0,0), (0,0,0), justification=1)
		screen.blit(fitResults[2],(15,270))
	
	return fitResults
Exemplo n.º 36
0
    def createDescription(self, name=None, desc=None):
        if name is None:
            self.descSurface = None
        else:
            text = str(name + "\n\n" + desc)

            self.descSurface = textrect.render_textrect(text, CHAR_EDITOR_FONT,
                                                        Rect(self.charMenu.rect.topleft, self.idealSize),
                                                        CHAR_EDITOR_COLOR_OFF,
                                                        CHAR_EDITOR_BLACK_PANEL_COLOR)
Exemplo n.º 37
0
    def updateImage(self):
        if self.time == 0:
            msg = "GO!"
            self.startFlag = True
        else:
            msg = str(self.time)

        self.image = textrect.render_textrect(msg, COUNTDOWN_FONT, self.rect,
                                              COUNTDOWN_COLOR, ALMOST_BLACK, 1,
                                              True)
Exemplo n.º 38
0
    def showBookDetails(self, screen, options):
        self.bookNumber = self.index
        print "index", self.index
        book = self.bookshelf[self.bookNumber]

        self.font = pygame.font.SysFont('Arial', 15)

        rendered_title = tx.render_textrect(
            "\'" + book.title + "\' by \'" + book.author + "\'", self.font,
            Rect(20, 200, 400, 400), (255, 255, 255), (48, 48, 48), 0)
        screen.blit(rendered_title, options.lowerHalfScreenrect.topleft)

        file = open(
            options.bookshelfPath + '/' + book.filepath + '/' + "text.txt",
            'r')
        content = file.read()

        (timeToRead, numWords, self.summary) = Summarize.main(content,
                                                              10,
                                                              needSummary=True)
        book.timeToRead = round(timeToRead, 2)
        self.summary = self.summary[:650] + "..."
        print "*summary*", self.summary, " : ", "*timeToRead*", book.timeToRead

        screen.blit(
            self.font.render("Total time : " + str(book.timeToRead) + " min",
                             True, (250, 150, 150)), (0, 220))

        rendered_sumtitle = tx.render_textrect(
            "Summary (There were " +
            str(numWords) + " words in actual document)", self.font,
            Rect(20, 240, 400, 400), (48, 48, 48), (200, 200, 200), 0)
        screen.blit(rendered_sumtitle, (0, 240))

        rendered_summary = tx.render_textrect(self.summary, self.font,
                                              options.summary, (60, 60, 60),
                                              (230, 230, 230), 0)

        if rendered_summary:
            screen.blit(rendered_summary, options.summary.topleft)

        #screen.blit(self.font.render(summary, True, (255,0,0)), (40, 200))
        pygame.display.flip()
Exemplo n.º 39
0
    def createDescription(self, name=None, desc=None):
        if name is None:
            self.descSurface = None
        else:
            text = str(name + "\n\n" + desc)

            self.descSurface = textrect.render_textrect(
                text, CHAR_EDITOR_FONT,
                Rect(self.charMenu.rect.topleft, self.idealSize),
                CHAR_EDITOR_COLOR_OFF, CHAR_EDITOR_BLACK_PANEL_COLOR)
Exemplo n.º 40
0
    def runGame(self):
        """
        Method that runs the game until player dies or all houses are cleared. Passes key presses to other method
        """
        self.createScreen()
        pygame.init()
        self.__font = pygame.font.Font(None, 24)
        clock = pygame.time.Clock()
        pygame.display.flip()
        pygame.event.clear()
        self.__endText = "Game Over"
        self.__helpText = """Use arrows to move, B for Bag, S for Stats, Z for Hershey's Kisses, X For Nerds, C for Sour Straws, and V for Chocolate Bars. Press H to see this again, Q to quit, W to see where you are, and M for a list of monsters."""
        rendered_text = textrect.render_textrect(self.__helpText, self.__font,
                                                 self.__textBox,
                                                 (255, 255, 255), (0, 0, 0), 0)
        if rendered_text:
            self.__screen.blit(rendered_text, self.__textBox.topleft)
        while pygame.event.wait().type != pygame.locals.QUIT:
            clock.tick(60)
            key = pygame.key.get_pressed()
            self.getInput(key)
            pygame.display.flip()
            pygame.event.clear()
            clock.tick(60)
            if (self.__game.deadGuy() or self.__game.gameOver()):
                if (self.__game.deadGuy()):
                    self.__endText = "You've been defeated, bad luck mate, press Q to quit"
                    rendered_text = textrect.render_textrect(
                        self.__endText, self.__font, self.__textBox,
                        (255, 255, 255), (0, 0, 0), 0)
                    if rendered_text:
                        self.__screen.blit(rendered_text,
                                           self.__textBox.topleft)

                if (self.__game.gameOver()):
                    self.__endText = "You've killed all the monsters, good job. Press Q to quit"
                    rendered_text = textrect.render_textrect(
                        self.__endText, self.__font, self.__textBox,
                        (255, 255, 255), (0, 0, 0), 0)
                    if rendered_text:
                        self.__screen.blit(rendered_text,
                                           self.__textBox.topleft)
Exemplo n.º 41
0
def printList(screen):
    global boxList

    for i, b in enumerate(boxList):
        pos = (0, i * 15)
        line = (str(posRelatedToAnchor(b[1].topleft)) +
                " - " + str(posRelatedToAnchor(b[1].bottomright)) )
        text = textrect.render_textrect(line, FONTS[0],
                                    Rect((0, 0), (SCREEN_SIZE[0], SCREEN_SIZE[1])),
                                    (250, 250, 250), (5, 5, 5), 0, True)
        screen.blit(text, pos)
Exemplo n.º 42
0
def pgParagraf(text, rect_info, font_name=GAME_FONT):
    """Menulis paragraf rata kiri warna hitam
    dengan warna background windows pada layar"""

    font = pygame.font.Font(font_name, 20)
    rect = pg.Rect(rect_info)
    rendered = textrect.render_textrect(text, font, rect,
                                        adt.color_use("black"),
                                        adt.color_use("background"), 0)
    if rendered:
        gameDisplay.blit(rendered, rect.topleft)
Exemplo n.º 43
0
def printList(screen):
    global boxList

    for i, b in enumerate(boxList):
        pos = (0, i * 15)
        line = (str(posRelatedToAnchor(b[1].topleft)) + " - " +
                str(posRelatedToAnchor(b[1].bottomright)))
        text = textrect.render_textrect(
            line, FONTS[0], Rect((0, 0), (SCREEN_SIZE[0], SCREEN_SIZE[1])),
            (250, 250, 250), (5, 5, 5), 0, True)
        screen.blit(text, pos)
Exemplo n.º 44
0
    def render(self):
        # Render to the main display
        SCREEN.fill(BG_COLOR1)

        for i in range(15):
            set_tile(6, i, 'vertical_divider')

        rect = pg.Rect(15, 20, 200, 300)
        surf = render_textrect('请从列表\n中选择你\n喜欢的职业', FONT_SMALL, rect, WHITE, 1, 1.5)
        SCREEN.blit(surf, rect)

        for index, item in enumerate(self.menuitems):
            is_selected = index == self.selected_index
            menu_type = 2 if index == self.role_index else -1
            item.render(is_selected, menu_type)

        role = self.dic_roles.get(self.role_index)
        if role:
            rect = pg.Rect(400, 50, 400, 240)
            surf = render_textrect(role.Name, FONT_NORMAL3, rect, WHITE, 0, 1.4)
            SCREEN.blit(surf, rect)

            text = role.get_status_str()
            rect = pg.Rect(400, 100, 400, 240)
            surf = render_textrect(text, FONT_NORMAL, rect, WHITE, 0, 1.4)
            SCREEN.blit(surf, rect)

            image = IMAGES[role.sprite_name]
            SCREEN.blit(image, (500, 50))

        message = ('我们的世界由五大属性组成,分别是:\n'
                   '防御值(AC):在你遭受攻击时挡住攻击\n'
                   '生命值(HP):在你受到攻击时遭受的伤害\n'
                   '攻击加值(AB):在你挥出巨剑时带给敌方的痛苦感受\n'
                   '灵敏值(QB):在你躲过敌方致命一击时的冲刺\n'
                   '金钱(Money):你胜利击退可恶的铁脑壳时获取的奖赏\n'
                   '除Money之外, 任何一项为0,你都会死亡')
        
        rect = pg.Rect(300, 360, 440, 240)
        surf = render_textrect(message, FONT_SMALL, rect, (200, 200, 200), 0, 1.5)
        SCREEN.blit(surf, rect)
Exemplo n.º 45
0
 def draw_label(self,
                text,
                rect,
                foreground=Color.white,
                background=Color.black,
                font='normal'):
     self.display.blit(
         render_textrect(text,
                         self.fonts[font],
                         pygame.Rect(0, 0, rect[2], rect[3]),
                         foreground.value,
                         background.value,
                         justification=1), (rect[0], rect[1]))
Exemplo n.º 46
0
    def _savedata(self, silent=FALSE):
        "saves data, and displays screen saying so, unless function parameter 'silent' is TRUE"
        self.datafile.close(
        )  #close data file so all data in buffer is written out.
        myresumedata = resumedata()  #instance of resumedata class
        myresumedata.n = self.n
        myresumedata.list = self.imagelist
        myresumedata.label = self.dlabel
        myresumedata.imagedir = self.dimagedir
        myresumedata.sessionlist = self.sessionlist
        myresumedata.sessiontype = self.sessiontype
        f2 = open(self.ddatafilename[:-4] + '.dat', 'w')
        pickle.dump(myresumedata, f2)  #save (pickle) data to file f2.
        f2.close()
        try:
            #copy saved data to backup directory on \\\\g6-200
            filename = self.ddatafilename
            shutil.copyfile(filename, '\\\\g6-200\\bdata\\' + filename)
            filename = filename[:-4] + '.dat'
            shutil.copyfile(filename, '\\\\g6-200\\bdata\\' + filename)
            filename = self.dparticipantlistfilename
            shutil.copyfile(filename, '\\\\g6-200\\bdata\\' + filename)
        except:
            #send error message-- this would not work if cable gets disconnected!
            os.system('net send g6-200 failed to copy ' + filename)

        if not silent:
            self.dscreen.fill(
                (0, 0, 0))  #screen is a surface! fill it with black
            tboxwidth = 250
            tboxheight = 250
            xpos = self.dscreen.get_width() / 2 - tboxwidth / 2
            ypos = 300
            my_font = pygame.font.Font(None, 22)
            #if not the screen displayed after the very last trial:
            my_string = '\n\nYour data has been saved.\n\nThank you for participating in our study!\n\nTo return to the main menu, press [enter]'
            my_rect = pygame.Rect((xpos, ypos, tboxwidth, tboxheight))
            rendered_text = textrect.render_textrect(my_string, my_font,
                                                     my_rect, (216, 216, 216),
                                                     (48, 48, 48), 1)
            if rendered_text:
                self.dscreen.blit(rendered_text, my_rect.topleft)
            pygame.display.update()

            #code to set up a delayed return to main menu even if no key is pressed(?):
            #pygame.time.set_timer(USEREVENT, self.dintermissiondelay*1000)

            while 1:
                event = pygame.event.wait()
                if (event.type == KEYDOWN) and (event.key == K_RETURN):
                    return
    def _displayMessage(self,width,height,yPos,displayString,textColor=(216,216,216)):
        """textColor is in the form: (216, 216, 216)"""
        #my_font = pygame.font.Font(None, 22)
        my_font = self.font
        tboxwidth = width * 3 #making adjustment for increase in font size
        tboxheight = height * 2 
        yPos = yPos - 200
        xPos =  self.dscreen.get_width()/2 - tboxwidth/2 
        my_rect = pygame.Rect((xPos, yPos, tboxwidth, tboxheight))
        rendered_text = textrect.render_textrect(displayString, my_font, my_rect, textColor, (48, 48, 48), 1)

        if rendered_text:
            self.dscreen.blit(rendered_text, my_rect.topleft)

        pygame.display.update()
Exemplo n.º 48
0
def menu():
    font = pygame.font.Font(customfont, 36)
    title_string = "\nMove Cowboy Dan: arrow keys\n\nSwitch Levels: " \
    "1 and 2\n\nSuper Speed & Invincibility: P\n\nPress ENTER to return to game"
    screen_rect = screen.get_rect()
    title = textrect.render_textrect(title_string, font, screen_rect,
                                     (255, 255, 255), 2)

    done = False
    while not done:
        screen.blit(title, (0, 0))

        for event in pygame.event.get():
            if event.type == KEYDOWN and event.key == K_RETURN:
                done = True
        pygame.display.update()
        clock.tick(20)
Exemplo n.º 49
0
def found_horse_screen():
    font = pygame.font.Font(customfont, 36)
    title_string = "\nCowboy Dan has found his horse!\n\nHelp Cowboy " \
        "Dan get back to present day!\n\nPress ENTER to continue"
    screen_rect = screen.get_rect()
    title = textrect.render_textrect(title_string, font, screen_rect,
                                     (255, 255, 255), 0)

    done = False
    while not done:
        screen.blit(title, (0, 0))

        for event in pygame.event.get():
            if event.type == KEYDOWN and event.key == K_RETURN:
                done = True
        pygame.display.update()
        clock.tick(20)
Exemplo n.º 50
0
    def __init__(self):
        super(Instruction, self).__init__()

        #self.image = pygame.Surface((800, 600), pygame.SRCALPHA)
        (tam_x, tam_y) = (600, 500)
        self.image = pygame.Surface((tam_x, tam_y), pygame.SRCALPHA)
        self.image.fill((30, 170, 70, 250))
        self.rect = self.image.get_rect()

        self.font = pygame.font.Font('fonts/Mandingo.ttf', 48)
        self.font2 = pygame.font.Font('fonts/Mandingo.ttf', 34)
        self.font3 = pygame.font.Font('fonts/Mandingo.ttf', 24)

        self.rect = self.image.get_rect()

        x = self.rect.centerx
        y = 50

        t = self.font.render(prop.TITLE, True, (0, 0, 0))
        self.image.blit(t, (x - (t.get_width() / 2),
                            y - (t.get_height() / 2)))

        y += 10 + t.get_height()

        text_r = textrect.render_textrect(unicode(prop.MM_INST.upper()), self.font3, pygame.Rect(0,0,tam_x-100,tam_y-250), (0,0,0), (100,100,200,0))
        self.image.blit(text_r, (x-(text_r.get_width()/2), y))
        y += 10 + text_r.get_height()

#        for i in [prop.OBJECTIVE, prop.INSTRUCTIONS, prop.COMMANDS]:
#            t = self.font2.render(i[0], True, (0,0,0))
#            self.image.blit(t, (x-(t.get_width()/2), y))
#            y += 5 + t.get_height()
#
#            text_r = textrect.render_textrect(unicode(i[1]), self.font3, pygame.Rect(0,0,700,100), (0,0,0), (100,100,200,0))
#            self.image.blit(text_r, (x-(text_r.get_width()/2), y))
#            y += 10 + text_r.get_height()

        t = self.font2.render(u"PRESIONÁ ESPACIO PARA COMENZAR", True, (0,0,0))
        self.image.blit(t, (x-(t.get_width()/2), y))
        y += 5 + t.get_height()


        self.rect.center = pygame.display.get_surface().get_rect().center
Exemplo n.º 51
0
def applyTextBox(textToAdd,x,y,LeftRight):

	textSize = len(textToAdd)
	print ("Text size: %s",(textSize))
        my_font = pygame.font.Font(None, 20)
        my_rect = pygame.Rect((x, y-textSize*1.05, 150, 100))
 	rendered_text = render_textrect(textToAdd, my_font, my_rect, white, black, 0)

 	if rendered_text:
		screen.blit(rendered_text, my_rect.topleft)
        if(LeftRight):
                screen.blit(leftTalk,(x,y))
                pygame.display.flip()

        else:
                screen.blit(rightTalk,(x,y))
                pygame.display.flip()

	pygame.display.update()
Exemplo n.º 52
0
    def __init__(self, title, banList=[], ip=False, maxLength=None):
        super(Model, self).__init__()

        if maxLength is None:
            self.maxLength = TEXT_ENTRY_LENGTH_MAX
        else:
            self.maxLength = maxLength

        self.ipCheck = ip
        self.font = TEXT_ENTRY_FONT
        self.response = []
        self.banList = banList

        size = (TEXT_ENTRY_LINE_WIDTH + (TEXT_ENTRY_BORDER_SIZE * 2),
                self.font.get_linesize() + self.font.get_height() +
                (TEXT_ENTRY_BORDER_SIZE * 2))
        pos = [0, 0]
        for i in range(2):
            pos[i] = (SCREEN_SIZE[i] / 2) - (size[i] / 2)
        self.rect = Rect(pos, size)

        self.base = pygame.Surface(size)
        self.base.fill(BLACK)
        pygame.draw.rect(self.base, WHITE, (0, 0, size[0], size[1]), 1)
        pygame.draw.rect(
            self.base, WHITE,
            (0 + TEXT_ENTRY_BORDER_SIZE, 0 + TEXT_ENTRY_BORDER_SIZE, size[0] -
             (TEXT_ENTRY_BORDER_SIZE * 2), size[1] -
             (TEXT_ENTRY_BORDER_SIZE * 2)), 1)

        self.updateImage()

        size = (self.rect.width,
                self.font.get_linesize() + self.font.get_height())
        self.titleRect = Rect((0, 0), size)
        self.titleRect.bottom = self.rect.top
        self.titleRect.left = self.rect.left
        temp = textrect.render_textrect(title, self.font, self.titleRect,
                                        WHITE, BLACK, 1)
        self.titlePanel = pygame.Surface(size)
        self.titlePanel.blit(temp,
                             (0,
                              (size[1] / 2) - (self.font.get_linesize() / 2)))
Exemplo n.º 53
0
def title_screen():
    #customfont = os.path.join('assets', 'custom.ttf')
    font = pygame.font.Font(customfont, 36)
    title_string = "Cowboy Dan has got himself into a predicament. His horse wandered into a wormhole and got transported back in " \
        "time to the age of the dinosaurs. Of course Cowboy Dan had to follow to save his favorite horse.\n\nHelp Cowboy " \
        "Dan find his horse and get back to present day!\n\nPress ENTER to continue"
    screen_rect = screen.get_rect()
    title = textrect.render_textrect(title_string, font, screen_rect,
                                     (255, 255, 255), 0)

    done = False
    while not done:
        screen.blit(title, (0, 0))

        for event in pygame.event.get():
            if event.type == KEYDOWN and event.key == K_RETURN:
                done = True
        pygame.display.update()
        clock.tick(20)
Exemplo n.º 54
0
def game_over():
    pygame.time.wait(1000)
    font = pygame.font.Font(customfont, 36)
    title_string = "\n\nYou killed Cowboy Dan!\n\nPress ENTER to try again\nEsc to exit"
    screen_rect = screen.get_rect()
    title = textrect.render_textrect(title_string, font, screen_rect,
                                     (255, 255, 255), 2)

    done = False
    while not done:
        screen.blit(title, (0, 0))

        for event in pygame.event.get():
            if event.type == KEYDOWN and event.key == K_RETURN:
                main()
                done = True
            if event.type == KEYDOWN and event.key == K_ESCAPE:
                pygame.quit()
        pygame.display.update()
        clock.tick(20)
Exemplo n.º 55
0
    def draw_paragraph(self, sentence, size, rect):
        """
        Draw paragraph onto the screen.
        Automatically aligns sentence so that they don't go out of border.

        Arguments:
        sentence -> string to show on the screen
        size -> size of the font
        rect -> rectangle to put the paragraph in
        """
        white = (220, 220, 220)
        black = (0, 0, 0)
        font = pygame.font.Font(self.font_type, size)

        my_rect = textrect.render_textrect(sentence,
                                           font,
                                           rect,
                                           white,
                                           black,
                                           justification=0)
        self.screen.blit(my_rect, rect.topleft)
Exemplo n.º 56
0
def end_of_game_screen(player, levelList):
    font = pygame.font.Font(customfont, 36)
    title_string = "\nCowboy Dan has saved his horse and made it back to present day! Good job! \n\nThank you for playing! \n\nPress Esc to exit\nENTER to play again"
    screen_rect = screen.get_rect()
    title = textrect.render_textrect(title_string, font, screen_rect,
                                     (255, 255, 255), 0)

    done = False
    while not done:
        screen.blit(title, (0, 0))

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True
            elif event.type == KEYDOWN and event.key == K_ESCAPE:
                done = True
            elif event.type == KEYDOWN and event.key == K_RETURN:
                main()
                done = True
        pygame.display.update()
        clock.tick(20)
    pygame.quit()