本文整理匯總了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)
#.........這裏部分代碼省略.........