Created
July 25, 2010 22:06
-
-
Save AtkinsSJ/489931 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
# import the pygame module, so you can use it | |
import pygame | |
from pygame.locals import * | |
#Main class | |
class Main: | |
scale = 1 | |
basewidth = 320 | |
baseheight = 240 | |
def __init__(self): | |
# initialize the pygame module | |
pygame.init() | |
pygame.key.set_repeat(1, 30) | |
# load and set the logo | |
#logo = pygame.image.load("logo32x32.png") | |
#pygame.display.set_icon(logo) | |
pygame.display.set_caption("Can you tell what it is yet?") | |
self.width, self.height = self.basewidth*self.scale, self.baseheight*self.scale | |
self.screen = pygame.display.set_mode((self.width, self.height)) | |
self.clock = pygame.time.Clock() | |
# Load the dlw file. Currently we discard all but the first tile image | |
f = open('forest.dlw', 'rb') # World to open! | |
f.seek(82) | |
tilenumber = 1 | |
tile = f.read(768 * tilenumber) | |
# Grab the tile! | |
self.tileimage = pygame.image.fromstring(tile, (32, 24*tilenumber), 'P') | |
print self.tileimage | |
self.tileimage.set_palette( [(0,0,0), (8,8,8), (16,16,16), (24,24,24), (32,32,32), (40,40,40), (48,48,48), (56,56,56), | |
(64,64,64), (72,72,72), (80,80,80), (88,88,88), (96,96,96), (104,104,104), (112,112,112), (120,120,120), | |
(128,128,128), (136,136,136), (144,144,144), (152,152,152), (160,160,160), (168,168,168), (176,176,176), (184,184,184), | |
(192,192,192), (200,200,200), (208,208,208), (216,216,216), (228,228,228), (236,236,236), (244,244,244), (252,252,252), | |
(0,0,0), (0,16,0), (0,32,0), (0,48,0), (0,64,0), (0,84,0), (0,100,0), (0,116,0), | |
(0,132,0), (0,148,0), (0,168,0), (0,184,0), (0,200,0), (0,216,0), (0,232,0), (0,252,0), | |
(16,252,16), (32,252,32), (44,252,44), (60,252,60), (76,252,76), (92,252,92), (108,252,108), (124,252,124), | |
(140,252,140), (156,252,156), (172,252,172), (188,252,188), (204,252,204), (220,252,220), (236,252,236), (252,252,252), | |
(0,0,0), (8,4,0), (16,12,4), (28,20,8), (36,24,12), (44,32,16), (56,40,16), (64,44,20), | |
(72,52,24), (84,60,28), (92,64,32), (100,72,32), (112,80,36), (120,84,40), (128,92,44), (140,100,48), | |
(144,108,60), (152,116,72), (160,128,84), (168,136,96), (172,148,112), (180,156,124), (188,164,136), (196,176,148), | |
(200,184,160), (208,192,176), (216,204,188), (224,212,200), (228,224,212), (236,232,224), (244,240,236), (252,252,252), | |
(0,0,0), (0,0,16), (0,0,32), (0,0,48), (0,0,68), (0,0,84), (0,0,100), (0,0,116), | |
(0,0,136), (0,0,152), (0,0,168), (0,0,184), (0,0,204), (0,0,220), (0,0,236), (0,0,252), | |
(16,16,252), (32,32,252), (44,44,252), (60,60,252), (76,76,252), (92,92,252), (108,108,252), (124,124,252), | |
(140,140,252), (156,156,252), (172,172,252), (188,188,252), (204,204,252), (220,220,252), (236,236,252), (252,252,252), | |
(0,0,0), (16,0,0), (32,0,0), (48,0,0), (64,0,0), (84,0,0), (100,0,0), (116,0,0), | |
(132,0,0), (148,0,0), (168,0,0), (184,0,0), (200,0,0), (216,0,0), (232,0,0), (252,0,0), | |
(252,16,16), (252,32,32), (252,44,44), (252,60,60), (252,76,76), (252,92,92), (252,108,108), (252,124,124), | |
(252,140,140), (252,156,156), (252,172,172), (252,188,188), (252,204,204), (252,220,220), (252,236,236), (252,252,252), | |
(0,0,0), (16,16,0), (32,32,0), (48,48,0), (68,68,0), (84,84,0), (100,100,0), (116,116,0), | |
(136,136,0), (152,152,0), (168,168,0), (184,184,0), (204,204,0), (220,220,0), (236,236,0), (252,252,0), | |
(252,252,16), (252,252,32), (252,252,44), (252,252,60), (252,252,76), (252,252,92), (252,252,108), (252,252,124), | |
(252,252,140), (252,252,156), (252,252,172), (252,252,188), (252,252,204), (252,252,220), (252,252,236), (252,252,252), | |
(0,0,0), (16,0,16), (32,0,32), (48,0,48), (68,0,68), (84,0,84), (100,0,100), (116,0,116), | |
(136,0,136), (152,0,152), (168,0,168), (184,0,184), (204,0,204), (220,0,220), (236,0,236), (252,0,252), | |
(252,16,252), (252,32,252), (252,44,252), (252,60,252), (252,76,252), (252,92,252), (252,108,252), (252,124,252), | |
(252,140,252), (252,156,252), (252,172,252), (252,188,252), (252,204,252), (252,220,252), (252,236,252), (252,252,252), | |
(0,0,0), (0,16,16), (0,32,32), (0,48,48), (0,68,68), (0,84,84), (0,100,100), (0,116,116), | |
(0,136,136), (0,152,152), (0,168,168), (0,184,184), (0,204,204), (0,220,220), (0,236,236), (0,252,252), | |
(16,252,252), (32,252,252), (44,252,252), (60,252,252), (76,252,252), (92,252,252), (108,252,252), (124,252,252), | |
(140,252,252), (156,252,252), (172,252,252), (188,252,252), (204,252,252), (220,252,252), (236,252,252), (252,252,252)]) | |
s = pygame.image.tostring(self.tileimage, 'P') | |
temp = '' | |
for c in s: | |
temp += `ord(c)` + ', ' | |
print temp | |
self.tileimage = self.tileimage.convert(self.screen) | |
print self.tileimage | |
def mainLoop(self): | |
# define a variable to control the main loop | |
self.running = True | |
# main loop | |
while self.running: | |
#self.clock.tick(60) | |
# event handling, gets all event from the eventqueue | |
for event in pygame.event.get(): | |
# only do something if the event is of type QUIT | |
if event.type == pygame.QUIT: | |
# change the value to False, to exit the main loop | |
self.running = False | |
elif event.type == KEYUP: | |
if event.key == K_ESCAPE: | |
self.running = False | |
elif event.key == K_SPACE: | |
pass #self.running = self.level.win() | |
# elif ((event.key == K_RIGHT) or (event.key == K_LEFT) | |
# or (event.key == K_UP) or (event.key == K_DOWN)): | |
# self.level.player.sprite.move(event.key) | |
#self.level.update() | |
# Drawing | |
pygame.transform.scale(self.tileimage, (self.width, self.height), self.screen) | |
#self.screen.blit(self.tileimage, (0,0)) | |
#self.screen.blit( , (0,0) ) | |
pygame.display.flip() | |
# run the main function only if this module is executed as the main script | |
# (if you import this as a module then nothing is executed) | |
if __name__=="__main__": | |
# call the main function | |
Game = Main() | |
Game.mainLoop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment