Skip to content

Instantly share code, notes, and snippets.

@mutaku
Created July 18, 2012 17:46
Show Gist options
  • Save mutaku/3137692 to your computer and use it in GitHub Desktop.
Save mutaku/3137692 to your computer and use it in GitHub Desktop.
samurai, samurai, samurai
#!/usr/bin/env python
import sys
import random
import pygame
from pygame.locals import *
# window shit
pygame.init()
DS = pygame.display.set_mode((800, 600), 0, 32)
pygame.display.set_caption('I CAN HAZ SAMURAI?')
FPS = 15
fpsClock = pygame.time.Clock()
# some colors
colors = {
'BLACK': (0, 0, 0),
'WHITE': (255, 255, 250),
'RED': (255, 0, 0),
'GREEN': (0, 255, 0),
'BLUE': (0, 0, 255)
}
# graphic
sam = pygame.image.load('samurai.jpg')
maxx = DS.get_width() - sam.get_width() - 10
maxy = DS.get_height() - sam.get_height() - 10
# game loop
while True:
# bad call here but want to preserve color names for other stuff
DS.fill(colors[random.choice(colors.keys())])
DS.blit(sam, (
random.randint(10, maxx),
random.randint(10, maxy)
)
)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
fpsClock.tick(FPS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment