当前位置: 首页>>代码示例>>Python>>正文


Python World.process方法代码示例

本文整理汇总了Python中world.World.process方法的典型用法代码示例。如果您正苦于以下问题:Python World.process方法的具体用法?Python World.process怎么用?Python World.process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在world.World的用法示例。


在下文中一共展示了World.process方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: InGameState

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import process [as 别名]

#.........这里部分代码省略.........
            human_red = Human(self.world, human_count+1)
            human_red.location = self.get_safe_spot()
            self.world.add_entity(human_red)
            self.humans.append(human_red)
            offset = human_count*SCREEN_SIZE[0]/2+1
            r = pygame.Rect(offset, 0, SCREEN_SIZE[0]/2-1, SCREEN_SIZE[1])
            viewport = Viewport(r, human_red)
            self.viewports.append(viewport)

        for fire_count in xrange(randint(10,50)):
            fire = Fire(self.world, self.fire_images)
            fire.location = self.get_safe_spot()
            self.world.add_entity(fire)
            self.world.fire_count += 1

        for water_count in xrange(randint(5, 10)):
            water = Water(self.world, self.water_images)
            water.location = self.get_safe_spot()
            self.world.add_entity(water)
            self.world.hare_count += 1

    def onEvent(self, event):
        if event.type == KEYDOWN and event.key == pygame.K_ESCAPE:
            self.done = True
        if event.type == AudioSystem.SONG_END:
            self.music_playing = False
            
    def get_safe_spot(self):
        while True:
            p = (randint(1, WORLD_SIZE[0]-1), randint(1, WORLD_SIZE[1]-1))
            if not self.world.grid.getBlock(p[0], p[1]):
                return Vector2(p[0], p[1]) * BLOCK_SIZE

    def update(self, passed_time, state_list):
        if self.world.human_count < 1:
            done = True
            state_list.pop()
            state_list.append(EndState(self.humans[0].age, self.humans[1].age))
            return
        if self.done:
            state_list.pop()
            return

        distance_of_humans = self.humans[0].location.get_distance_to(self.humans[1].location)
        if distance_of_humans < 40:
            hunger = self.humans[0].hunger + self.humans[1].hunger
            thirst = self.humans[0].thirst + self.humans[1].thirst
            heat = self.humans[0].heat + self.humans[1].heat
            for h in self.humans:
                h.hunger = hunger / 2.0
                h.thirst = thirst / 2.0
                h.heat = heat / 2.0

        if self.world.hare_count < 30:
            self.hare_timer -= passed_time

        if self.hare_timer < 0.0:
            hare = Hare(self.world, self.hare_images_lf, self.hare_images_rf)
            hare.location = self.get_safe_spot()
            hare.heading = choice([Vector2(1, 0), Vector2(-1, 0), Vector2(0, -1), Vector2(0, 1)])
            self.world.add_entity(hare)
            self.hare_timer = self.hare_timer_add
            self.hare_timer_add += randint(2, 5)
            self.world.hare_count += 1
            print "hare spawned"

        if self.world.fire_count < 30:
            self.fire_timer -= passed_time

        if self.fire_timer < 0.0:
            fire = Fire(self.world, self.fire_images)
            fire.location = self.get_safe_spot()
            self.world.add_entity(fire)
            self.world.fire_count += 1
            self.fire_timer = self.fire_timer_add
            self.fire_timer_add += randint(2, 5)
            print "fire spawned"

        if not self.music_playing:
            self.wait_for_song -= passed_time            
            if self.wait_for_song < 0.0:
                self.player.PlayTrack()
                self.music_playing = True
                self.wait_for_song = randint(5000, 20000)
                
        self.world.process(passed_time)

    def render(self, screen):
        for viewport in self.viewports:
            viewport.render(screen)
        for plr in xrange(2):
            x = plr*640 + 16
            y = 16
            #screen.fill((0, 255, 0), (x, y+00, int(self.humans[plr].hunger), 10))
            #screen.fill((0, 0, 255), (x, y+10, int(self.humans[plr].thirst), 10))
            #screen.fill((255, 0, 0), (x, y+20, int(self.humans[plr].heat), 10))
        
            screen.blit(self.world.hunger_images[self.humans[plr].hunger_image_index], (x,y))
            screen.blit(self.world.thirst_images[self.humans[plr].thirst_image_index], (x,y))
            screen.blit(self.world.warmth_images[self.humans[plr].heat_image_index], (x,y))
开发者ID:svuolli,项目名称:coldworld,代码行数:104,代码来源:ingamestate.py

示例2: __init__

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import process [as 别名]
class GameEngine:
    """The main game object, responsible for running the simulation and the
    ui.
    """

    def __init__(self):

        # This initialization needs to be done before other pygame calls.
        pygame.init()
        pygame.display.set_caption(globaldata.GAME_TITLE)

        # Reference to the globaldata for our application.
        self.globaldata = globaldata

        # Reference to the game clock for handling framerate.
        self.clock = pygame.time.Clock()

        self.world = World(globaldata.WORLD_SIZE[0], globaldata.WORLD_SIZE[1])

        # -------------------------------------------- UI

        # Cache of image assets.
        self.game_assets = GameAssets(globaldata.ASSETS_PATH)

        # The main display, which all other views should be nested with.
        # Display needs to be set before any graphics calls and the main
        # UI controller.
        self.display = PygameDisplay(globaldata.SCREEN_SIZE[0], globaldata.SCREEN_SIZE[1])

        # Controller for all UI elements.
        self.ui_controller = GameUIController(self)

        # Map scales itself to the screensize.
        self.display.addchild(Map(controller=self.ui_controller))

        # TODO: Should have a debug panel, and the following two things should
        # be added.
        # Frames per second.
        self.display.addchild(FPSDisplay(5, 5, controller=self.ui_controller))
        # Mouse coordinates.
        self.display.addchild(MouseDisplay(5, 25, controller=self.ui_controller))

        # On screen player controls and information readouts.
        self.display.addchild(ControlPanel(controller=self.ui_controller))

    def process(self):

        # Time_passed is in milliseconds.
        time_passed = self.clock.tick(60)

        # Update logic.
        self.world.process(time_passed)

        self.ui_controller.process(time_passed)

        # Update UI.
        self.display.render()

    def run(self):
        """Call to start the game.
        """

        if __debug__:
            print pygame.display.Info()

        # Main game loop.
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    return
                else:
                    self.ui_controller.handle_event(event)

            self.process()
开发者ID:jeremyosborne,项目名称:ant_cities,代码行数:76,代码来源:gameengine.py

示例3: runLevel

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import process [as 别名]
def runLevel(screen, level_number, cat_number):
    soundChannel = pygame.mixer.Channel(0)
    finishSound = pygame.mixer.Sound('../sounds/finish.ogg')  
    
    builder = LevelBuilder()
    level = builder.buildLevelFromFile('../levels/level%s.txt' % level_number)
    world = World(SCREEN_SIZE, level)
    
    car = Car(Vector2(100,100))
    player = Player(Vector2(100, 180))
    
    world.add_entity(player)
    world.add_entity(car)
    world.setFocus(player)
    
    worldobserver = WorldObserver(world)
    clock = pygame.time.Clock()
    
    for i in range(cat_number):
        cat = Cat(Vector2(randint(0, world.dimension[0]), 
                          randint(0, world.dimension[1])), 
                  world)
        world.add_entity(cat)
    
    countdown_to_next_level = LEVEL_INTERMEDIATE_TIME
    while True:
        
        for event in pygame.event.get():
            if event.type == QUIT:
                exit()
            if event.type == KEYDOWN:
                if event.key == K_LEFT:
                    player.move(LEFT)
                elif event.key == K_RIGHT:
                    player.move(RIGHT)
                elif event.key == K_UP:
                    player.move(UP)
                elif event.key == K_DOWN:
                    player.move(DOWN)
                elif event.key == K_SPACE:
                    food = player.dropFood()
                    if food is not None:
                        world.add_entity(food)
                elif event.key == K_c:
                    player.switchVehicle(car)
                    world.setFocus(player.vehicle or player)
                elif event.key == K_m:
                    world.toggleMinimap()
                        
        time_passed = clock.tick(30)
        
        world.process(time_passed)
        world.render(screen)
        worldobserver.writeMessages(screen)
        
        if worldobserver.levelFinished:
            if countdown_to_next_level == LEVEL_INTERMEDIATE_TIME:
                soundChannel.play(finishSound)
            countdown_to_next_level -= 2
            if countdown_to_next_level <= 0:
                return
            
            for r in range(countdown_to_next_level+1, LEVEL_INTERMEDIATE_TIME, 8):
                pygame.draw.circle(screen, (0, 0, 0), (SCREEN_SIZE[0]/2, SCREEN_SIZE[1]/2), r, 1)
        
        pygame.display.update()
开发者ID:jcharra,项目名称:StreetCatz,代码行数:68,代码来源:main.py


注:本文中的world.World.process方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。