Hardware Reference
In-Depth Information
Listing 4-2 continued
tryLine = tryLine + words[test] + “ “
textSurface[segment] = font.render(tryLine, ;
True, cText, cBackground )
tryWidth = textSurface[segment].get_rect()
wordsWidth = tryWidth.right
print tryLine ,” -> is “,wordsWidth,” pixels wide”
useLine = “”
if wordsWidth > screenWidth - margin :;
# for the end of a line
wordsToUse -= 1 # use one less word
else :
endOfLine = True
for test in range(0, wordsToUse): ;
# build up the line you want
useLine = useLine + words[test] + “ “
textSurface[segment] = font.render(useLine,;
True, cText, cBackground )
print “Using the line :- “, useLine
print
newsLines[index] = newsLines[index][len(useLine) :]
if endOfLine : # work on the next line next time
index += 1
return index
def drawWords(index,offset) :
textRect = textSurface[index].get_rect()
textRect.centerx = screenWidth / 2
textRect.top = screenHeight - (textHeight ;
* index) - offset
screen.blit(textSurface[index], textRect)
def terminate(): # close down the program
print (“Closing down please wait”)
pygame.quit() # close pygame
sys.exit()
def checkForEvent(): # see if you need to quit
global scrollSize
event = pygame.event.poll()
if event.type == pygame.QUIT :
terminate()
if event.type == pygame.KEYDOWN :
Search WWH ::




Custom Search