本文整理汇总了Python中die.Die.update方法的典型用法代码示例。如果您正苦于以下问题:Python Die.update方法的具体用法?Python Die.update怎么用?Python Die.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类die.Die
的用法示例。
在下文中一共展示了Die.update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from die import Die [as 别名]
# 或者: from die.Die import update [as 别名]
class LD26Main:
def __init__(self, width=800,height=600):
pygame.init()
self.width = width
self.height = height
self.screen = pygame.display.set_mode((self.width, self.height))
self.state = "menu"
pygame.display.set_caption("Shoot Guys")
def load_sprites(self):
self.player_group = CameraSpriteGroup()
self.player_bullet_group = CameraSpriteGroup()
self.player_max_hp = 20
self.player_healthbar = HealthBar(self.player_max_hp, self.player_max_hp, "res/player_healthbar.png", (128, 16))
self.player_healthbar.rect.x = -55
self.player_healthbar.rect.y = 10
self.player_hb_group = CameraSpriteGroup()
self.player_hb_group.add(self.player_healthbar)
self.enemy_group = CameraSpriteGroup()
self.enemy_bullet_group = CameraSpriteGroup()
self.health_bar_sprites = CameraSpriteGroup()
self.max_badguys = 0
self.guys_killed = 0
self.levels = [{"img":"res/levels/level1.png", "badguys":2, "goal":6}, {"img":"res/levels/level2.png", "badguys":5, "goal":10}]
self.cur_level = 0
self.load_level(0)
self.menu = Menu()
self.win = Win()
self.die = Die()
def load_level(self, levelnum):
if levelnum >= len(self.levels):
self.state = "win"
else:
leveldict = self.levels[levelnum]
self.player = Player((self.width, self.height))
self.player_group.add(self.player)
self.level = Level((self.width, self.height), leveldict["img"])
self.bdrop1 = Backdrop(self.level.dims, 1)
self.bdrop2 = Backdrop(self.level.dims, 2)
self.max_badguys = leveldict["badguys"]
self.guys_killed = 0
self.kill_goal = leveldict["goal"]
self.player_healthbar.set_hp(self.player_max_hp)
def go(self):
self.load_sprites()
self.clock = pygame.time.Clock()
while 1:
self.clock.tick(60)
self.screen.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == K_ESCAPE:
if self.state == "game":
self.state = "menu"
else:
sys.exit()
elif event.key == K_RETURN:
if self.state == "menu":
self.state = "game"
elif self.state == "win" or self.state == "die":
self.load_level(0)
self.state = "game"
if self.state == "menu":
self.do_menu()
elif self.state == "game":
self.do_main_game()
elif self.state == "win":
self.do_win()
else:
self.do_die()
pygame.display.flip()
def do_die(self):
self.die.update()
self.die.draw(self.screen)
def do_win(self):
self.win.update()
self.win.draw(self.screen)
def do_menu(self):
self.menu.update()
self.menu.draw(self.screen)
def do_main_game(self):
if self.guys_killed > self.kill_goal:
self.cur_level += 1
self.player.kill()
self.load_level(self.cur_level)
#.........这里部分代码省略.........