Tuesday, December 11, 2007

Dragon Starver: The Beginning of Starvation



import sys, os
import pygame
from pygame.locals import *
from cgkit.cgtypes import vec3

def load_image(name, colorkey=None):

fullname = os.path.dirname(sys.argv[0])
fullname = os.path.join(fullname, 'data')
fullname = os.path.join(fullname, name)
try:
image = pygame.image.load(fullname)
except pygame.error, message:
print 'Cannot load image:', fullname
raise SystemExit, message
image = image.convert()
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0,0))
image.set_colorkey(colorkey, RLEACCEL)
return image

class Spritesheet:
def __init__(self, filename):
self.sheet = pygame.image.load(filename).convert()
def imgat(self, rect, colorkey = None):
rect = Rect(rect)
image = pygame.Surface(rect.size).convert()
image.blit(self.sheet, (0, 0), rect)
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0, 0))
image.set_colorkey(colorkey, RLEACCEL)
return image
def imgsat(self, rects, colorkey = None):
imgs = []
for rect in rects:
imgs.append(self.imgat(rect, colorkey))
return imgs

class AnimatedSprite:
def __init__(self, images, rect):
self.images = images

class Dragon:
def __init__(self):
self.surface = load_image("Dragon.bmp", (255,255,255))
self.pos = vec3(0,0,0)

def main():
pygame.init()

screen = pygame.display.set_mode((1024, 768),1)
pygame.display.set_caption('Dragon Starver')

fnt = pygame.font.Font(pygame.font.get_default_font(),18)

back = pygame.Surface((1024,768),1)
back = back.convert()
back.fill((200,200,200))

keys = {K_a:False,K_d:False,K_w:False,K_s:False}

dragon = Dragon();

while True:
for event in pygame.event.get():
if event.type == QUIT:
sys.exit(0)
elif event.type == KEYDOWN:
keys[event.key] = True
elif event.type == KEYUP:
keys[event.key] = False

if keys[K_a]:
dragon.pos.x -= 1
if keys[K_d]:
dragon.pos.x += 1
if keys[K_w]:
dragon.pos.y -= 1
if keys[K_s]
code to load images, and pull images off of a sprite sheet
and it moves a dragon around on the screen
Sent at 4:58 PM on Tuesday
me: sweet
haha
Sent at 5:15 PM on Tuesday
me: meh
took me a while because i haven't actually opened Flash before
but i have a little placeholder
do you need transparency in the image?
it's a bmp right now
Sent at 5:30 PM on Tuesday
Thomas's new status message - I'm not here right now 5:36 PM
Thomas: I can do transparency on bitmaps now
didnt you read the code!
Sent at 5:55 PM on Tuesday
me: nope
haha
sorry
i will now
though
hang on

1 comment:

tsturzl said...

By the gods, not Pygame!