本文整理汇总了Python中Character.Character.draw_hud方法的典型用法代码示例。如果您正苦于以下问题:Python Character.draw_hud方法的具体用法?Python Character.draw_hud怎么用?Python Character.draw_hud使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Character.Character
的用法示例。
在下文中一共展示了Character.draw_hud方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Character import Character [as 别名]
# 或者: from Character.Character import draw_hud [as 别名]
#.........这里部分代码省略.........
# So we can call each monster's attack method.
self.monster_group = PgGroup(self.monsters)
# Used to update everything to screen.
self.all_sprites = PgGroup((self.character, self.monsters, self.background, self.walls))
# Used to draw. We separate background so we can ensure it gets pictured before other things.
self.all_but_background.add(self.monsters)
self.time_test = False # Changed things in while loop so need to recreate timetest.
self.time_dict = {'drawmove': 0, 'abilitydraw': 0, 'eventloop': 0, 'attacks': 0, 'collisions': 0,
'move': 0, 'clear/recover': 0, 'drawbars': 0}
self.loop_counter = 0
self.find_key = {K_LSHIFT: 0, K_SPACE: 1, LEFT: 2, RIGHT: 3}
def clear_weapon(self):
# If sword is on screen, clear it off.
for sprite in self.all_but_background:
if isinstance(sprite, Attack) and sprite.is_dead():
sprite.kill()
def clear_dead(self):
# Remove dead monsters/players from game.
for sprite in self.all_but_background:
if type(sprite) is Monster or Character:
if sprite.is_dead():
sprite.kill()
if isinstance(sprite, Monster):
self.character.experience += sprite.exp_value
if self.character.level_up():
self.character.ability_manager.ability_points += 1
elif type(sprite) is Character:
exit()
def main(self):
elapsed_time = 0
while True:
for event in pygame.event.get():
if event.type == QUIT:
if self.time_test:
for key, value in self.time_dict.items():
print(key, value/self.loop_counter)
pygame.display.quit()
pygame.quit()
exit()
if event.type == KEYUP:
Mover.handle_character_event(event, False)
elif event.type == KEYDOWN:
if event.key == K_LSHIFT or event.key == K_SPACE:
key = self.find_key[event.key]
weapon = self.character.attack(pygame.mouse.get_pos(), self.character.ability_manager.elements[key])
if weapon is not None:
self.all_but_background.add(weapon) # For collisions
self.all_sprites.add(weapon) # For movement
else:
Mover.handle_character_event(event, True)
elif event.type == MOUSEBUTTONDOWN:
if Rect(30, 640, 370, 100).collidepoint(event.pos) or (self.character.ability_manager.menu_up and Rect(30, 360, 370, 300).collidepoint(event.pos)):
ability_leveled = self.character.ability_manager.handle_click(event)
if ability_leveled:
self.character.ability_levels[ability_leveled] += 1
self.character.increment_maxes()
elif Rect(880, 640, 370, 115).collidepoint(event.pos) or (self.character.inventory.menu_up and Rect(880, 280, 370, 360).collidepoint(event.pos)):
self.character.inventory.handle_click(event, self.character.ability_levels)
self.character.increment_maxes() # If Item that boost ToughenUp is equipped, health needs to change.
else:
self.character.ability_manager.menu_up = False
self.character.inventory.menu_up = False
if event.button == LEFT or event.button == RIGHT:
key = self.find_key[event.button]
weapon = self.character.attack(event.pos, self.character.ability_manager.elements[key])
if weapon is not None:
self.all_but_background.add(weapon) # For collisions
self.all_sprites.add(weapon) # For movement
self.screen.fill((0, 0, 0))
self.character.calc_velocity(elapsed_time)
monster_weapons = PgGroup.monster_attack(self.monster_group, self.character.rect.center)
self.all_but_background.add(monster_weapons)
self.all_sprites.add(monster_weapons)
Collider.check_collision_group(self.all_but_background, self.screen)
self.all_sprites.update(self.character.velocity, self.character.rect, elapsed_time)
PgGroup.draw(self.screen, self.background, self.all_but_background)
self.clear_weapon() # Must be after draw. Keep at end of loop, since attack happens in event for loop.
self.clear_dead()
self.character.recover(elapsed_time)
self.character.draw_hud(self.screen)
PgGroup.draw_monster_bars(self.monsters, self.screen)
pygame.display.update()
elapsed_time = self.my_clock.tick(FRAME_RATE)