#Import Modules import os, pygame from pygame.locals import * from Util import * from World import * from Player import * if not pygame.font: print 'Warning, fonts disabled' if not pygame.mixer: print 'Warning, sound disabled' def main(): """this function is called when the program starts. it initializes everything it needs, then runs in a loop until the function returns.""" #Initialize Everything pygame.init() screen = pygame.display.set_mode((800, 450)) pygame.display.set_caption('Segregation') #pygame.mouse.set_visible(0) #load sound draw = load_sound("a_draw.wav") bgMusic = load_sound("a_backgroundMusic02.wav") bgMusic.play(-1) mousedown = False user = Player() #Create The Backgound background = pygame.Surface(screen.get_size()) background = background.convert() #background.fill((0, 0, 255)) bgimgTut,imgrect = load_image("bgLevel1.png") #background.blit(bgimgTut,(0,0)) bgimgGame,imgrect = load_image("bgLevel2.png") #background.blit(bgimgGame,(0,0)) #Put Text On The Background, Centered if pygame.font: font = pygame.font.Font('data/arial.ttf', 36) text = font.render("Score", 1, (10, 10, 10)) textpos = text.get_rect(centerx=background.get_width()/2) background.blit(text, textpos) pygame.display.flip() #Prepare Game Objects clock = pygame.time.Clock() #Main Loop while 1: #test point = (-100,-100) clock.tick(60) #Handle Input Events for event in pygame.event.get(): if event.type == QUIT: return if event.type == MOUSEBUTTONDOWN: mousedown = True draw.play(-1) if event.type == MOUSEBUTTONUP: user.endPath() mousedown = False draw.stop() if event.type == MOUSEMOTION and mousedown: point = pygame.mouse.get_pos() user.addMouseMotion(point) elif event.type == KEYDOWN and event.key == K_ESCAPE: return Game().update() user.update() #Draw Everything background = pygame.Surface(screen.get_size()) background = background.convert() if(World().gameStarted==0): background.blit(bgimgTut,(0,0)) World().tutorialSound.play() else: background.blit(bgimgGame,(0,0)) World().tutorialSound.stop() if pygame.font: font = pygame.font.SysFont("Arial", 22, 1) font if(World().gameStarted==0): text = font.render("High Score: %d"%World().hiscore, 1, (255, 255, 255)) else: text = font.render("Score: %d"%World().points, 1, (255, 255, 255)) textpos = text.get_rect(centerx=background.get_width()/2) background.blit(text, textpos) screen.blit(background, (0, 0)) Game().draw(screen) # draw paths pathlist = user.getPathlist() for path in user.getPathlist(): if not (path.isEmpty()): color = (220,0,0) if path.leader!=None: if path.leader.teamID==1: color = (255,228,40) else: color = (110,0,250) # and len(path.pointlist[path.leader.pathIndex:]) >0 if path.leader!=None and len(path.pointlist[path.leader.pathIndex-2:]) >= 2 : pygame.draw.aalines(screen,color,False,path.pointlist[path.leader.pathIndex-2:],1) #Line drawing function else: pygame.draw.aalines(screen,color,False,path.pointlist,1) #Line drawing function #test pointrect = Rect(point,(0,0)) pointrect = pointrect.inflate(15,15) pygame.draw.rect(screen,(0,220,0), pointrect, 2) pygame.display.flip() #Game Over #this calls the 'main' function when this script is executed if __name__ == '__main__': main()