本文整理汇总了Python中World.processEntities方法的典型用法代码示例。如果您正苦于以下问题:Python World.processEntities方法的具体用法?Python World.processEntities怎么用?Python World.processEntities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World
的用法示例。
在下文中一共展示了World.processEntities方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import World [as 别名]
# 或者: from World import processEntities [as 别名]
#.........这里部分代码省略.........
while i < zombie_count:
entity = Zombie(self.world)
entity.location = Vector(randint(80, w), randint(80, h))
entity.brain.set_state("exploring")
self.world.add_entity(entity)
i += 1
i = 0
while i < food_count:
entity = Food(self.world)
entity.location = Vector(randint(100, w), randint(100, h))
self.world.add_entity(entity)
i += 1
i = 0
while i < trapdoor_count:
entity = Trapdoor(self.world)
entity.location = Vector(50,50)
entity.brain.set_state("trapdoor_open")
self.world.add_entity(entity)
i += 1
i = 0
while i < player_count:
entity = Player(self.world)
entity.location = Vector(50,50)
entity.brain.set_state("playing")
self.world.add_entity(entity)
i += 1
i = 0
self.state = "idle"
def handleEvent(self, event):
"""Returns a new state for the Game object.
based on the previous state and input from the user,
which essentially depends on what world is currently being displayed
pressed_keys: The keys pressed by the user. Determined by the
pygame.key.get_pressed module
"""
pressed_keys = pygame.key.get_pressed()
mouse_pressed = pygame.mouse.get_pos()
if event == MOUSEBUTTONDOWN:
self.world.state = self.world.get_clickable_entity(mouse_pressed)
elif self.world.state == "idle" and pressed_keys[K_ESCAPE]:
self.world.state = "startup"
elif event == pygame.QUIT: exit()
def run(self):
"""Function that controls the whole running of the Game.
Determines which world should be presented to the user, along with the
required entities and display's them on the screen
world: used to store the currently displaying world. Should
be a World object
time_passed: stores the update of the clock object, running at 20fps
screen: Specifies the screen to which the world and its entities
should be displayed
"""
# initialise pygame
pygame.init()
# The animation loop (infinite)
while 1:
if self.world.state == "startup":
self.startup()
elif self.world.state == "newGame":
self.runGame()
elif self.world.state == "completed":
self.completed()
elif self.world.state == "dead":
self.playerDead()
elif self.world.state == "quitGame":
exit()
# checks to see if there are any events occuring in pygame
for event in pygame.event.get():
# passes the event type to the handleEvent function which determines what shall be done
self.handleEvent(event.type)
time_passed= clock.tick(30)
self.world.processEntities(time_passed)
self.world.renderEntities(screen)
# flips display from buffer onto the screen
pygame.display.flip()