本文整理汇总了Python中level.Level.restart方法的典型用法代码示例。如果您正苦于以下问题:Python Level.restart方法的具体用法?Python Level.restart怎么用?Python Level.restart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类level.Level
的用法示例。
在下文中一共展示了Level.restart方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import restart [as 别名]
class Game(object):
fps = 100
def __init__(self, screen):
self.screen = screen
self.level = Level(self.screen.get_size())
def quit(self):
self.done = True
def update(self):
dt = self.clock.tick(self.fps)
self.level.update(dt)
def draw(self):
self.level.draw(self.screen)
def run(self):
self.done = False
self.clock = pygame.time.Clock()
self.level.restart()
while not self.done:
# input
for event in pygame.event.get():
if event.type == QUIT:
self.quit()
elif event.type == KEYDOWN and event.key == K_ESCAPE:
self.quit()
self.update()
self.draw()
pygame.display.flip()
示例2: Game
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import restart [as 别名]
class Game(ApplicationState):
fps = 60
def setup(self):
self.level = Level(self.app.screen.get_size())
self.level.restart()
def resume(self):
self.clock = pygame.time.Clock()
pygame.mixer.music.unpause()
def quit(self):
self.done = True
def update(self):
dt = self.clock.tick(self.fps)
self.level.update(dt)
def draw(self, screen):
self.level.draw(screen)
示例3: Game
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import restart [as 别名]
class Game(ApplicationState):
fps = 60
def setup(self):
self.level = Level(self.app.screen.get_size())
self.level.restart()
def resume(self):
self.clock = pygame.time.Clock()
pygame.mixer.music.unpause()
def handle_event(self, event):
if event.type == KEYDOWN and event.key == K_ESCAPE:
self.app.set_state(PauseMenu)
def update(self):
dt = self.clock.tick(self.fps)
self.level.update(dt)
def draw(self, screen):
self.level.draw(screen)
示例4: GameState
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import restart [as 别名]
class GameState(AppState):
fps = 60
def setup(self):
AppState.setup(self)
self.level = Level(self.screen.get_size())
self.level.restart()
def resume(self):
self.clock = pygame.time.Clock()
def handle_event(self, event):
if event.type == KEYDOWN and event.key == K_ESCAPE:
self.app.set_state(PauseState)
def update(self):
dt = self.clock.tick(self.fps)
self.level.update(dt)
def draw(self):
self.level.draw(self.screen)
pygame.display.flip()
示例5: Game
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import restart [as 别名]
class Game(Application.State):
fps = 60
CHEAT = [ K_UP, K_UP, K_DOWN, K_DOWN, K_LEFT, K_RIGHT, K_LEFT, K_RIGHT, K_b, K_a ]
def setup(self):
scr_size = self.app.screen.get_size()
self.level = Level(scr_size)
self.level.restart()
self.cheat_idx = 0
self.background = TiledImage(load_image("grass"))
# makes things look a bit nicer for some reason
w = self.background.rect.width
self.background.rect.move_ip(-w/2, -w/2)
self.l_shadow = ShadowLayer(scr_size)
self.l_sprite = Layer(scr_size)
self.sprites = Group()
self.app.scores.reset()
self.font = pygame.font.Font(None, 60)
self.cheating = False
play_song("maintheme", volume=0.7)
def resume(self):
self.clock = pygame.time.Clock()
pygame.mixer.music.unpause()
def pause(self):
pygame.mixer.music.pause()
def handle_event(self, event):
if event.type == KEYDOWN and event.key == K_ESCAPE:
self.level.player.cheating = False
self.app.set_state(PauseMenu)
elif event.type == KEYDOWN and event.key == self.CHEAT[self.cheat_idx]:
self.cheat_idx += 1
elif event.type == KEYDOWN:
self.cheat_idx = 0
if self.cheat_idx == len(self.CHEAT):
self.cheat_idx = 0
self.level.player.cheating = not self.level.player.cheating
def update(self):
dt = self.clock.tick(self.fps)
self.level.update(dt)
if self.level.player.cheating:
self.cheating = True
elif not self.level.player.cheating and len(self.level.coins) == 1:
self.cheating = False
if not self.cheating:
self.app.scores.update( len(self.level.coins) )
else:
self.app.scores.update(-1)
def draw(self, screen):
self.l_shadow.clear()
self.l_sprite.clear()
# switch to layers
screen.fill((80,80,80))
self.background.draw(screen)
# create a list of sprites we need to draw
self.sprites.empty()
self.sprites.add(self.level.player)
for coin in self.level.coins:
if coin.visible:
self.sprites.add(coin)
# sort the sprites by their height
sprites = sorted(self.sprites, sortby_y_h)
self.l_shadow.draw_sprites(sprites)
self.l_sprite.draw_sprites(sprites)
self.l_shadow.draw(screen)
self.l_sprite.draw(screen)
# draw score
score = self.font.render("Coins: %d" % self.app.scores.score, True, (255,255,255))
rect = score.get_rect()
rect.bottomleft = screen.get_rect().bottomleft
screen.blit(score, rect)
hiscore = self.font.render("Hiscore: %d" % self.app.scores.hiscore, True, (255,255,255))
#.........这里部分代码省略.........