#Zombie Brawler #Started 05/03/07 #Much code stolen from the PySRPG from last year import os, sys import pygame from pygame.locals import * if not pygame.font: print 'Warning, fonts disabled' if not pygame.mixer: print 'Warning, sound disabled' # underscore_separated variable names # camelCaps methods # CamelCaps classes # Actors are anything that loads in front of the background and affects gameplay or results from it. # Zombies, players, power-ups, projectiles, etc. class GameMain: def __init__(self,width=800,height=600): """Initialize""" """Initialize PyGame""" pygame.init() """Set the window Size""" self.width = width self.height = height """Create the Screen""" self.screen = pygame.display.set_mode((self.width, self.height)) def gameLoop(self): """This is the main game loop""" """Load background""" self.loadBackground() """Load actors""" # self.LoadInitialActors() """Start loop""" # Commented out a huge raft of shit that I'll need later # Should probably stub out some functions. while 1: #main_interrupt == 0: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() # elif event.type == MOUSEBUTTONDOWN: # for unit in self.unit_sprites: # if unit.rect.collidepoint(event.pos): # if self.is_selected: # self.is_selected.Deselect() # unit.BecomeSelected() # self.is_selected = unit # else: # unit.BecomeSelected() # self.is_selected = unit # elif event.type == KEYDOWN: # if self.is_selected: # if (event.key == K_RIGHT): # self.is_selected.Move([1,0]) # elif (event.key == K_LEFT): # self.is_selected.Move([-1,0]) # elif (event.key == K_UP): # self.is_selected.Move([0,-1]) # elif (event.key == K_DOWN): # self.is_selected.Move([0,1]) # # #for terrain in self.terrain_sprites: - this is mouse movement code # #if terrain.rect.collidepoint(event.pos): # #self.is_selected.Move(ToCoords(terrain.rect.center)) # self.screen.blit(self.background, (0, 0)) # self.unit_sprites.draw(self.screen) # pygame.display.flip() #Use this to load images for the game def loadImage(self, name, colorkey=None): fullname = os.path.join('data', 'images') fullname = os.path.join(fullname, name) if os.path.isfile(fullname): 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, image.get_rect() #Background loader, duh. #Stuff that's commented out is either redundant, or to be used later. def loadBackground(self): # self.is_selected = 0 locale, rect = self.loadImage('snip.png') """Create the background""" self.background = pygame.Surface(self.screen.get_size()).convert() self.background = self.background.blit(locale,(0,0)) # self.background = self.background.convert() # self.background.fill((0,0,0)) if __name__ == "__main__": MainWindow = GameMain() MainWindow.gameLoop()