def main(): """this function is called when the program starts. it initializes everything it needs, then runs in a loop until the function returns.""" global ticks, show_world #Initialize Everything pygame.init() font = pygame.font.Font(None, 36) textcolor = (100, 255, 255) text = font.render("Autonomous Motion Demo", 1, textcolor) screen = pygame.display.set_mode(screen_size) #, FULLSCREEN) pygame.display.set_caption('Autonomous Motion Demo') pygame.mouse.set_visible(False) world = pygame.Surface(world_size) world = world.convert() #Create The Backgound Images.load_image('grass.jpg') background = pygame.Surface(world_size) background = background.convert() background_image = Images.get('grass') for x in range(0, background.get_width(), background_image.get_width()): for y in range(0, background.get_height(), background_image.get_height()): background.blit(background_image, (x, y)) #Display The Background screen.blit(background, (0, 0)) pygame.display.flip() #Prepare Game Objects clock = pygame.time.Clock() Images.load_image('square.png') Images.load_character('dino', os.path.join("T_dino_red", "dino red bitmaps")) Images.load_character('ogre', os.path.join("T_ogre", "ogre 96x bitmaps")) w, h = world_size # Blocks if (True): b = Block((0, 0)) bw, bh = b.rect.size for x in range(0, w, bw): blocks.add(Block((x, 0))) blocks.add(Block((x, h - bh))) for y in range(bh, h - bh, bh): blocks.add(Block((0, y))) blocks.add(Block((w - bw, y))) # Mobs for d in range(ndinos): add_mob(dinos) for o in range(nogres): add_mob(ogres) mobs.add(dinos) mobs.add(ogres) everything.add(mobs) everything.add(blocks) dtext = "Wait" for o in ogres: o.changeState(S.User()) print """ c: slow clock H: show heading F12: show world b: show box 0: wait w: wander s: seek p: pursuit f: flee e: evasion """ #Main Loop while 1: clock.tick(ticks) #Handle Input Events for event in pygame.event.get(): if event.type == QUIT: return elif event.type == KEYDOWN: if event.key == K_ESCAPE: return elif event.key == K_c: if ticks < 30: ticks = 30 else: ticks = 10 elif event.key == K_F12: show_world = not show_world if show_world: screen = pygame.display.set_mode( world_size) #, FULLSCREEN) else: screen = pygame.display.set_mode( screen_size) #, FULLSCREEN) elif event.key == K_h: for m in mobs: m.showheading = not m.showheading elif event.key == K_b: for m in everything: m.showbox = not m.showbox elif event.key == K_0: dtext = "Wait" text = font.render(dtext, 1, textcolor) for m in dinos: m.changeState(S.Wait()) elif event.key == K_w: dtext = "Wander" text = font.render(dtext, 1, textcolor) for m in dinos: m.changeState(S.Wander()) elif event.key == K_s: dtext = "Seek" text = font.render(dtext, 1, textcolor) pick_on(ogres, dinos, S.Seek()) elif event.key == K_p: dtext = "Pursuit" text = font.render(dtext, 1, textcolor) pick_on(ogres, dinos, S.Pursuit()) elif event.key == K_f: dtext = "Flee" text = font.render(dtext, 1, textcolor) pick_on(ogres, dinos, S.Flee()) elif event.key == K_e: dtext = "Evasion" text = font.render(dtext, 1, textcolor) pick_on(ogres, dinos, S.Evasion()) #Update sprites mobs.update(everything) #Draw Everything world.blit(background, (0, 0)) everything.draw(world) screen.fill((0, 0, 0)) if show_world: screen.blit(world, (0, 0)) else: screen.blit(world, (0, 0), ogres.sprites()[0].rect.inflate(screen_size)) screen.blit(text, (32, 32)) pygame.display.flip()
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(screen_size, FULLSCREEN) pygame.display.set_caption('Wait!') pygame.mouse.set_visible(True) #Create The Backgound Images.load_image('grass.jpg') background = pygame.Surface(screen.get_size()) background = background.convert() background_image = Images.get('grass') for x in range(0, background.get_width(), background_image.get_width()): for y in range(0, background.get_height(), background_image.get_height()): background.blit(background_image, (x, y)) #Display The Background screen.blit(background, (0, 0)) pygame.display.flip() #Prepare Game Objects clock = pygame.time.Clock() Images.load_character('dino', os.path.join("T_dino_red", "dino red bitmaps")) Images.load_character('ogre', os.path.join("T_ogre", "ogre 96x bitmaps")) w, h = screen.get_size() for d in range(ndinos): dinos.add(Dino(random_pos())) for o in range(nogres): ogres.add(Ogre(random_pos())) everybody.add(dinos) everybody.add(ogres) for e in everybody: e.changeState(S.Wander()) #Main Loop while 1: clock.tick(ticks) #Handle Input Events for event in pygame.event.get(): if event.type == QUIT: return elif event.type == KEYDOWN and event.key == K_ESCAPE: return elif event.type == MOUSEBUTTONDOWN and event.button == 1: for e in everybody: e.showheading = not e.showheading elif event.type == MOUSEBUTTONDOWN and event.button == 2: for e in everybody: e.showbox = not e.showbox elif event.type == MOUSEBUTTONDOWN and event.button == 3: d = dinos.sprites()[0] if d.state == S.Wander(): randomogre = random.choice(ogres.sprites()) for d in dinos: d.changeState(S.Pursuit(), target=randomogre) else: for d in dinos: d.changeState(S.Wander()) #Update sprites everybody.update() #Draw Everything screen.blit(background, (0, 0)) everybody.draw(screen) pygame.display.flip()
def main(): """this function is called when the program starts. it initializes everything it needs, then runs in a loop until the function returns.""" global ticks, show_world #Initialize Everything pygame.init() font = pygame.font.Font(None, 36) textcolor = (100, 255, 255) text = font.render("Autonomous Motion Demo", 1, textcolor) screen = pygame.display.set_mode(screen_size)#, FULLSCREEN) pygame.display.set_caption('Autonomous Motion Demo') pygame.mouse.set_visible(False) world = pygame.Surface(world_size) world = world.convert() #Create The Backgound Images.load_image('grass.jpg') background = pygame.Surface(world_size) background = background.convert() background_image = Images.get('grass') for x in range(0,background.get_width(),background_image.get_width()): for y in range(0,background.get_height(),background_image.get_height()): background.blit(background_image,(x,y)) #Display The Background screen.blit(background, (0, 0)) pygame.display.flip() #Prepare Game Objects clock = pygame.time.Clock() Images.load_image('square.png') Images.load_character('dino', os.path.join("T_dino_red", "dino red bitmaps")) Images.load_character('ogre', os.path.join("T_ogre", "ogre 96x bitmaps")) w,h = world_size # Blocks if (True): b = Block((0,0)) bw, bh = b.rect.size for x in range(0,w,bw): blocks.add(Block((x,0))) blocks.add(Block((x,h-bh))) for y in range(bh,h-bh,bh): blocks.add(Block((0,y))) blocks.add(Block((w-bw,y))) # Mobs for d in range(ndinos): add_mob(dinos) for o in range(nogres): add_mob(ogres) mobs.add(dinos) mobs.add(ogres) everything.add(mobs) everything.add(blocks) dtext = "Wait" for o in ogres: o.changeState(S.User()) #Main Loop while 1: clock.tick(ticks) #Handle Input Events for event in pygame.event.get(): if event.type == QUIT: return elif event.type == KEYDOWN: if event.key == K_ESCAPE: return elif event.key == K_c: if ticks < 30 : ticks = 30 else: ticks = 10 elif event.key == K_F12: show_world = not show_world if show_world: screen = pygame.display.set_mode(world_size)#, FULLSCREEN) else: screen = pygame.display.set_mode(screen_size)#, FULLSCREEN) elif event.key == K_h: for m in mobs: m.showheading = not m.showheading elif event.key == K_b: for m in everything: m.showbox = not m.showbox elif event.key == K_0: dtext = "Wait" text = font.render(dtext, 1, textcolor) for m in dinos: m.changeState(S.Wait()) elif event.key == K_w: dtext = "Wander" text = font.render(dtext, 1, textcolor) for m in dinos: m.changeState(S.Wander()) elif event.key == K_s: dtext = "Seek" text = font.render(dtext, 1, textcolor) pick_on(ogres, dinos, S.Seek()) elif event.key == K_p: dtext = "Pursuit" text = font.render(dtext, 1, textcolor) pick_on(ogres, dinos, S.Pursuit()) elif event.key == K_f: dtext = "Flee" text = font.render(dtext, 1, textcolor) pick_on(ogres, dinos, S.Flee()) elif event.key == K_e: dtext = "Evasion" text= font.render(dtext, 1, textcolor) pick_on(ogres, dinos, S.Evasion()) #Update sprites mobs.update(everything) #Draw Everything world.blit(background, (0,0)) everything.draw(world) screen.fill((0,0,0)) if show_world: screen.blit(world, (0,0)) else: screen.blit(world, (0,0), ogres.sprites()[0].rect.inflate(screen_size)) screen.blit(text, (32,32)) pygame.display.flip()
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(screen_size, FULLSCREEN) pygame.display.set_caption('Wait!') pygame.mouse.set_visible(True) #Create The Backgound Images.load_image('grass.jpg') background = pygame.Surface(screen.get_size()) background = background.convert() background_image = Images.get('grass') for x in range(0,background.get_width(),background_image.get_width()): for y in range(0,background.get_height(),background_image.get_height()): background.blit(background_image,(x,y)) #Display The Background screen.blit(background, (0, 0)) pygame.display.flip() #Prepare Game Objects clock = pygame.time.Clock() Images.load_character('dino', os.path.join("T_dino_red", "dino red bitmaps")) Images.load_character('ogre', os.path.join("T_ogre", "ogre 96x bitmaps")) w,h = screen.get_size() for d in range(ndinos): dinos.add(Dino(random_pos())) for o in range(nogres): ogres.add(Ogre(random_pos())) everybody.add(dinos) everybody.add(ogres) for e in everybody: e.changeState(S.Wander()) #Main Loop while 1: clock.tick(ticks) #Handle Input Events for event in pygame.event.get(): if event.type == QUIT: return elif event.type == KEYDOWN and event.key == K_ESCAPE: return elif event.type == MOUSEBUTTONDOWN and event.button == 1: for e in everybody: e.showheading = not e.showheading elif event.type == MOUSEBUTTONDOWN and event.button == 2: for e in everybody: e.showbox = not e.showbox elif event.type == MOUSEBUTTONDOWN and event.button == 3: d = dinos.sprites()[0] if d.state == S.Wander(): randomogre = random.choice(ogres.sprites()) for d in dinos: d.changeState(S.Pursuit(), target=randomogre) else: for d in dinos: d.changeState(S.Wander()) #Update sprites everybody.update() #Draw Everything screen.blit(background, (0, 0)) everybody.draw(screen) pygame.display.flip()