Created
December 1, 2011 18:10
-
-
Save johtso/1418661 to your computer and use it in GitHub Desktop.
Ascii Games with Pygame and Pygcurse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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):