Пример #1
0
 def update(self, dt):
     if self.time >= 140:
         self.switch_requested("WinContext")
     
     self.time += dt
     self.spawn_enemies(dt)
     for thing in self.things:
         thing.update(dt)
     people_to_remove = []
     for person in self.people:
         person.update(dt)
         if len(self.people) > settings.max_people and len(person.joints) <= 3:
             people_to_remove.append(person)
         elif person.Chest.position.x >= self.world_width - 2 and not person.is_dead:
             person.remove_from_world()
             gamestats.add_survivor()
     
     #Only remove one of the People To Remove
     if len(people_to_remove):
         people_to_remove[-1].remove_from_world()
         self.people.remove(people_to_remove[-1])
     
     if self.mouse_down:
         d = (b2Vec2(self.mx, self.my) - self.camera.look_at).Length()
         self.camera.move_towards(self.mx, self.my, max(d, 2), dt)
     
     self.murder.update(dt)
     self.weather.update(dt)
     self.camera.update(dt)
     self.world.SetContinuousPhysics(True)
     
     # Tell Box2D to step
     if dt > .1: dt = .1
     self.world.Step(dt, 10, 10)
     self.world.Validate()
Пример #2
0
    def run(self):
        while not self.done:
            self.handleEvents()

            for arrow in self.arrows:
                arrow.update()

            for row in self.board.board:
                for tile in row:
                    tile.update()
                    if tile.item:
                        tile.item.update()

            floatingTile = self.board.getFloatingTile()
            floatingTile.update()
            if floatingTile.item:
                floatingTile.item.update()

            for person in self.board.people:
                person.update()


            self.draw()
Пример #3
0
def main():
    # Initialize pygame
    pygame.init()
    # Create pygame window
    WIDTH = HEIGHT = 600
    # Used to draw in later
    screen = pygame.display.set_mode([WIDTH, HEIGHT])
    pygame.display.set_caption('Corona simulation')
    screen.fill(pygame.Color('gray'))
    # Control the framerates with the clock function
    clock = pygame.time.Clock()
    MAX_FPS = 20

    # For our running simulation program
    running = True
    spawnBuffer = 10 # pixels
    numPeople = 200
    factorSocialDistancing = 0.75

    # Create people
    # Place patient zero at a random position in the screen (not practicing socialDistancing)
    patientZero = Person(random.randint(spawnBuffer,WIDTH-spawnBuffer), random.randint(spawnBuffer,HEIGHT-spawnBuffer), 'infected', False)
    # Other people
    people = [patientZero]
    for i in range(numPeople-1):
        socialDistancing = False
        if i < factorSocialDistancing * numPeople: # Those who are doing socialDistancing
            socialDistancing = True

        # Make sure that each spawn location is unique
        colliding = True
        while colliding:
            person = Person(random.randint(spawnBuffer,WIDTH-spawnBuffer), random.randint(spawnBuffer,HEIGHT-spawnBuffer), 'susceptible', socialDistancing)
            colliding = False
            for p in people:
                if person.checkCollidingWithOther(p):
                    colliding = True
                    break
        people.append(person)

    while running: # While the app is running
        # to empty the event queue
        for event in pygame.event.get():
            # Check if user clicked top right X to close program
            if event.type == pygame.QUIT:
                running = False
        # Update people
        # # Update patient zero
        # patientZero.update(screen, [])
        for person in people:
            person.update(screen, people)
        # Update graphics
        # If you don't do this, you will see a trace after the person.
        screen.fill(pygame.Color('gray'))
        # # Draw patient zero
        # patientZero.draw(screen)
        # Draw all people
        for person in people:
            person.draw(screen)
        # Update - crucial
        pygame.display.flip()
        # Pauze for frame to be displayed
        clock.tick(MAX_FPS)
    # If quit, stop the program
    pygame.quit()