예제 #1
0
파일: main.py 프로젝트: zoibot/onslaught
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()
예제 #2
0
파일: tank.py 프로젝트: zoibot/onslaught
 def find_target(self):
     [target] = object_manager.find_objects(Jeep)
     return target