Esempio n. 1
0
class Game:
    TIME_TO_SLEEP = 1
    DELTA = 1

    def __init__(self):
        self.is_running = True
        self.manager = Manager()

        Attack(frequence=4, max_to_kill=2).register_to(self.manager)
        MoodSwings().register_to(self.manager)
        Reproduction().register_to(self.manager)
        Time().register_to(self.manager)
        Weather(constants.WEATHER_SUNNY, 10).register_to(self.manager)

        self.api_server_thread = api_handler.setup(self.manager)

    def run(self):
        self.api_server_thread.start()

        while self.is_running:
            time.sleep(Game.TIME_TO_SLEEP)
            self.manager.update(Game.DELTA)

        self.api_server_thread.stop()

    def stop(self):
        self.is_running = False
Esempio n. 2
0
def main():
    # Init Pygame
    width, height = 800, 600
    pygame.init()
    screen = pygame.display.set_mode((width, height))

    # Create a manager and balls (balls are smiley images)
    manager = Manager()
    number_balls = random.randint(1, 20)
    for i in range(number_balls):
        create_ball(manager, {
            'x': random.randint(0, width),
            'y': random.randint(0, height)
        })

    # Add the processors (or systems) to the manager
    Input((width, height)).register_to(manager)
    Physic((width, height)).register_to(manager)
    Graphic((width, height)).register_to(manager)
    Render(screen).register_to(manager)

    # And start the big loop!
    clock = pygame.time.Clock()
    while is_running:
        delay = clock.tick(60)
        manager.update(float(delay) / 1000)