Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion slither/slither.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,27 @@ def play(self): pass

slitherSound = Sound()

# Convienience function to blit text
def blitText(text, x=0, y=0, size=12, font=False, fontPath=False, antialias=0, color=(0,0,0)):
global globalscreen
if font:
textFont = pygame.font.SysFont(font, size)
elif fontPath:
textFont = pygame.font.Font(fontPath, size)
else:
textFont = pygame.font.SysFont("Helvetica", size) # Users should always have Helvetica installed

textImage = textFont.render(text, antialias, color)

globalscreen.blit(textImage, (x, y))

#pygame.display.flip()

def setup(caption=sys.argv[0]):
'''Sets up PyGame and returns a screen object that can be used with blit().'''
global globalscreen
pygame.init()
pygame.font.init()
screen = pygame.display.set_mode(SCREEN_SIZE)
caption = pygame.display.set_caption(caption)
globalscreen = screen
Expand Down Expand Up @@ -277,7 +294,7 @@ def blit(screen):
new_rect.center = (obj.xpos, obj.ypos)
screen.blit(image, new_rect)

pygame.display.flip()
#pygame.display.flip()

def registerCallback(eventname, func=None):
'''Register the function func to handle the event eventname'''
Expand Down Expand Up @@ -313,4 +330,5 @@ def runMainLoop(frameFunc):
eventCallbacks[event.type](event)
# eventCallbacks would be a dictionary mapping
# event types to handler functions.
pygame.display.flip() # Always flip at the end
clock.tick(projectFPS) # Run at however many FPS the user specifies
12 changes: 12 additions & 0 deletions slither/tests/textTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import slither

slither.slitherStage.bgColor = (40, 222, 40)

slither.setup() # Begin slither

slither.blitText("Hello, world!")

def run_a_frame():
slither.blitText("Hello, world!", size=40)

slither.runMainLoop(run_a_frame)