Skip to content

Instantly share code, notes, and snippets.

@johtso
Created December 1, 2011 18:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johtso/1418661 to your computer and use it in GitHub Desktop.
Save johtso/1418661 to your computer and use it in GitHub Desktop.
Ascii Games with Pygame and Pygcurse
import sys
import pygcurse
import pygame
from pygame.locals import *
WINWIDTH = 40
WINHEIGHT = 50
FPS = 40
win = pygcurse.PygcurseWindow(WINWIDTH, WINHEIGHT, fullscreen=False)
pygame.display.set_caption('Window Title')
win.autoupdate = False
clock = pygame.time.Clock()
def main():
while True:
win.fill(bgcolor='blue')
handle_events()
win.fill('#', 'red', region=(5, 5, 10, 10))
win.update()
clock.tick(FPS)
def handle_events():
for event in pygame.event.get():
if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
terminate()
def terminate():
pygame.quit()
sys.exit()
if __name__ == '__main__':
main()
@Matt-Is-Confused
Copy link

if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
This results in an error and you should use
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment