def init(): global background,title,clock #Initialize Everything pygame.init() gfx.init() # load some global images background,back_rect = gfx.load_image("background.png") title,title_rect = gfx.load_image("title.png") gfx.screen.blit(background,(0,0)) gfx.screen.blit(title,(120,20)) pygame.display.flip() # load and set some defaults game_state = 0 clock = pygame.time.Clock() #load some global sounds # load some music # wait till mouse is clicked or loops interates 1000 times i = 0 while 1: clock.tick(60) if i==200: return 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: return gfx.screen.blit(background,(0,0)) gfx.screen.blit(title,(120,20)) pygame.display.flip() i = i + 1
def main(): pygame.init() pygame.display.set_caption("Fanorona v0.9") gfx.init() game.init() while not game.finished: game.clock.tick(60) gfx.update() for event in pygame.event.get(): if event.type is pygame.QUIT: # QUIT # game.finished = True break if game.current == game.player: # player's turn if event.type is pygame.MOUSEBUTTONDOWN and event.button == 1: game.player_move( game.grid.collision(pygame.mouse.get_pos())) if event.type is pygame.KEYDOWN and event.key == pygame.K_ESCAPE: game.finished = True if game.current == game.cpu and not game.game_over(): # computer's turn game.cpu_move() if not game.moving and game.game_over(): game.finished = True if game.winner == game.player: gfx.text = "YOU WIN!" else: gfx.text = "YOU LOSE!" quitting = False while not quitting: game.clock.tick(60) gfx.update() for event in pygame.event.get(): if event.type is pygame.QUIT: quitting = True
def main(): global objects gfx.init() inp = KeyboardController() clock = pygame.time.Clock() ticks = 0 score_text = gfx.create_text() gfx.show_text(score_text, True) gfx.set_text_transform(score_text, [520, 20], 0) lives_text = gfx.create_text() gfx.show_text(lives_text, True) gfx.set_text_transform(lives_text, [20, 20], 0) inp.bind_key_down(pygame.K_o, lambda x: print(objects)) jeep = None while True: clock.tick(60) ticks += clock.get_time() gfx.set_text(score_text, game_state.get_score()) gfx.set_text(lives_text, game_state.get_lives()) # todo rename from init because it's really update object_manager.init(objects) if not jeep or jeep.dead: jeep = spawn_jeep() if ticks > waves[0] and len(object_manager.find_objects(Tank)) == 0: waves.pop(0) spawn_tank() if not waves: # need to actually kill tanks print('you win!') sys.exit(0) # lol if int(game_state.get_lives()) < 0: print('you lose!') sys.exit(1) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit(0) elif event.type == pygame.KEYUP: if event.key == pygame.K_q: sys.exit(0) if objects_to_add: objects += objects_to_add del objects_to_add[:] for obj in objects: obj.update() # TODO clean this up new_objects = [] for object in objects: if object.dead: for component in object.components: component.detach(object) else: new_objects.append(object) objects = new_objects gfx.loop()