Created
September 21, 2011 03:41
-
-
Save durub/1231179 to your computer and use it in GitHub Desktop.
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 pygame, sys, time, random | |
from pygame.locals import * | |
# Constants | |
BLACK = (0, 0, 0) | |
WHITE = (255, 255, 255) | |
RED = (255, 0, 0) | |
GREEN = (0, 255, 0) | |
BLUE = (0, 0, 255) | |
# Initialize | |
pygame.init() | |
windowSurface = pygame.display.set_mode((600, 600), 0, 32) | |
basicFont = pygame.font.SysFont(None, 48) | |
pygame.display.set_caption('Boxes Game') | |
# Map | |
tiles = [[0, 1, 2, 3, 4, 1], | |
[4, 3, 2, 1, 0, 4], | |
[0, 1, 0, 3, 4, 1], | |
[4, 3, 4, 1, 0, 4], | |
[0, 1, 2, 3, 4, 1], | |
[4, 3, 2, 1, 0, 4]] | |
def render_map(tiles, width = 100, height = 100): | |
rect = pygame.Rect(0, 0, width, height) | |
colors = [BLACK, WHITE, RED, GREEN, BLUE] | |
for row in tiles: | |
for tile in row: | |
pygame.draw.rect(windowSurface, colors[tile], rect) | |
rect.left += width | |
rect.left = 0 | |
rect.top += height | |
def randomize(tiles): | |
for i in range(len(tiles)): | |
for j in range(len(tiles[i])): | |
tiles[i][j] = random.randint(0, 4) | |
def render(tiles): | |
render_map(tiles) | |
pygame.display.update() | |
render(tiles) | |
while True: | |
for event in pygame.event.get(): | |
if event.type == QUIT: | |
pygame.quit() | |
sys.exit() | |
elif event.type == MOUSEBUTTONUP: | |
randomize(tiles) | |
render(tiles) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment