本文整理汇总了Python中stage.Stage.update方法的典型用法代码示例。如果您正苦于以下问题:Python Stage.update方法的具体用法?Python Stage.update怎么用?Python Stage.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stage.Stage
的用法示例。
在下文中一共展示了Stage.update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from stage import Stage [as 别名]
# 或者: from stage.Stage import update [as 别名]
class Game:
def __init__(self, world, datadir, configdir):
self.world = world
self.datadir = datadir
self.configdir = configdir
self.enemies = []
self.stage = Stage(self)
self.sprites = Group(self.stage)
self.screen = world.screen
# Visor de energia para el enemigo
self._create_player()
self.energy = Energy(10, 10, 100, 10)
self.energy.set_model(self.player.id)
self.stage.player = self.player
self.stage.load_level(1)
if VISIBLE_DEBUG:
# Visor de rendimiento
self.text = Text(world.font, world.fps, "FPS: %d")
def _create_player(self):
control = Control(0, self.configdir)
self.player = Player(self, control, self.sprites, self.datadir)
shadow_player = Shadow(self.player, self.datadir)
self.sprites.add([self.player, shadow_player])
def update(self):
self.stage.update()
self.sprites.update()
self.energy.update()
if VISIBLE_DEBUG:
self.text.update()
if DEBUG:
b1, b2, b3 = pygame.mouse.get_pressed()
if b1:
self.stage.do_camera_effect()
elif b2:
self.stage.do_camera_effect(10)
elif b3:
self.world.fps.slow()
def draw(self):
self.stage.draw(self.screen)
self.sprites.draw(self.screen)
self.screen.blit(self.energy.image, self.energy.rect)
if VISIBLE_DEBUG:
self.screen.blit(self.text.image, self.text.rect)
pygame.display.flip()
示例2: Vacuum
# 需要导入模块: from stage import Stage [as 别名]
# 或者: from stage.Stage import update [as 别名]
#.........这里部分代码省略.........
#handle input events
ok = self.handle_keys()
if ok == False:
return
if self.game_started == False:
start_text = self.font.render('Press any key to start', 2, (0,0,0))
self.screen.blit(start_text, (150, 200))
pygame.display.flip()
continue
if self.game_paused == 1:
start_text = self.font.render('Game paused', 2, (255,255,255))
self.screen.blit(start_text, (150, 200))
pygame.display.flip()
continue
new_enemies = self.level.getenemies()
for enemy_y in new_enemies:
#if random.randint(0,50) == 0:
alien = Alien(enemy_y)
alien.set_target(self.ship)
self.enemies.add(alien)
#aliens damaging the player, remove them
damage = pygame.sprite.spritecollide(self.ship, self.enemies, True)
self.process_powerups()
#check colisions with stage
if self.level.checkcollide(self.ship.rect):
#add some fancy explosions in the damage area
self.explosions.add(Explosion(pygame.Rect(self.ship.rect.x,self.ship.rect.y,0,0)))
damage.append(1)
#Apply damages to the player
if len(damage) > 0:
self.background.warning()
self.ship.damage()
self.lifemeter.shake()
self.explosions.add(Explosion(self.ship.rect))
self.sounds['warning'].play()
self.lifemeter.life = self.ship.life
if self.lifemeter.life < 1:
self.game_finished = True
self.sounds['warning'].stop()
#print (pygame.sprite.spritecollide(ship, level, True))
#aliens hit by the fire, remove them
penetration = self.ship.powerup['penetrate']
for fireball in self.fire:
hit = pygame.sprite.spritecollide(fireball, self.enemies, True)
for dead in hit:
if dead.has_powerup():
powerup = Powerup(dead.rect, dead.value)
self.powerups.add(powerup)
self.explosions.add(Explosion(pygame.Rect(dead.rect.x,dead.rect.y,0,0)))
self.score+=dead.value*1000
if penetration == False:
fireball.kill()
#draw the level
all_sprites = pygame.sprite.Group()
all_sprites.add(self.player.sprites())
all_sprites.add(self.enemies.sprites())
all_sprites.add(self.powerups.sprites())
all_sprites.add(self.fire.sprites())
all_sprites.add(self.hud.sprites())
all_sprites.add(self.explosions.sprites())
all_sprites.update()
self.level.update()
self.background.update()
#Move and draw the background
score_text = 'Score: {0}'.format((self.score))
text = self.font.render(score_text, 1, (255, 255, 255))
text_shadow = self.font.render(score_text, 1, (0,0,0))
self.screen.blit(self.background, (0, 0))
self.screen.blit(self.level, (0, 0))
self.screen.blit(text_shadow, (12, 12))
self.screen.blit(text, (10, 10))
if self.game_finished == True:
gameover_text = self.font.render("Game Over", 2, (255, 255, 255))
self.screen.blit(gameover_text, (280, 200))
gameover_text = self.font.render("Press Esc", 2, (255, 255, 255))
self.screen.blit(gameover_text, (280, 230))
else:
all_sprites.draw(self.screen)
#draw all the groups of sprites
pygame.display.flip()
示例3: Vacuum
# 需要导入模块: from stage import Stage [as 别名]
# 或者: from stage.Stage import update [as 别名]
#.........这里部分代码省略.........
self.score.add_score(scored)
self.hud.add(Flying_Label( fireball.rect, scored))
if penetration == False:
fireball.kill()
#Main Loop
def loop(self):
count = 0
count = (count+1)%50
#handle input events
ok = self.handle_keys()
if ok == False:
return
if self.game_started == False:
start_text = self.font.render('Press any key to start', 2, (0,0,0))
self.screen.blit(start_text, (150, 200))
pygame.display.flip()
return
if self.game_paused == 1:
start_text = self.font.render('Game paused', 2, (255,255,255))
self.screen.blit(start_text, (150, 200))
pygame.display.flip()
return
try:
(new_enemies, new_minibosses, new_bosses, end) = self.level.getenemies()
for enemy_y in new_enemies:
alien = Alien(enemy_y)
alien.set_target(self.ship)
self.enemies.add(alien)
for enemy_y in new_minibosses:
miniboss = Miniboss(enemy_y, self)
miniboss.set_target(self.ship)
self.minibosses.add(miniboss)
if end:
self.level_finished = True
except ValueError:
self.level_finished = True
#aliens damaging the player, remove them
damage = pygame.sprite.spritecollide(self.ship, self.enemies, True)
damage.extend(pygame.sprite.spritecollide(self.ship, self.enemylasers, True))
for miniboss in self.minibosses:
if pygame.sprite.collide_mask(self.ship, miniboss):
damage.append(miniboss)
self.process_powerups()
collisions = self.process_stagecollisions()
for collision in collisions:
damage.append(1)
self.process_damage(damage)
self.process_killedaliens()
#Dummy lines to show the ship's current limits
if show_dummies:
the_limits = self.level.the_limits(self.ship.rect)
self.dummy.rect.top = the_limits[0]*self.level.ratio
self.dummy2.rect.top = the_limits[1]*self.level.ratio
self.dummy.rect.height = 2
self.dummy2.rect.height = 2
self.dummy.rect.left = self.ship.rect.left
self.dummy2.rect.left = self.ship.rect.left
#draw the level
all_sprites = pygame.sprite.Group()
all_sprites.add(self.player.sprites())
all_sprites.add(self.enemies.sprites())
all_sprites.add(self.minibosses.sprites())
all_sprites.add(self.powerups.sprites())
all_sprites.add(self.buddies.sprites())
all_sprites.add(self.fire.sprites())
all_sprites.add(self.enemylasers.sprites())
all_sprites.add(self.hud.sprites())
all_sprites.add(self.explosions.sprites())
all_sprites.update()
if len(self.minibosses.sprites()) == 0:
self.level.update()
self.background.update()
#Move and draw the background
self.screen.blit(self.background, (0, 0))
self.screen.blit(self.level, (-self.level.scrolled, 0))
if self.level_finished == True:
level_text = self.font.render("Level finished", 2, (255, 255, 255))
self.screen.blit(level_text, (280, 200))
elif self.game_finished == True:
gameover_text = self.font.render("Game Over", 2, (255, 255, 255))
self.screen.blit(gameover_text, (280, 200))
gameover_text = self.font.render("Press Esc", 2, (255, 255, 255))
self.screen.blit(gameover_text, (280, 230))
else:
all_sprites.draw(self.screen)
all_sprites.empty()
示例4: __init__
# 需要导入模块: from stage import Stage [as 别名]
# 或者: from stage.Stage import update [as 别名]
class Game:
"Representa la escena de pelea, donde el shaolin camina por el escenario."
def __init__(self, world):
self.world = world
self.enemies = []
self.sprites = group.Group()
self.stage = Stage(self, self.sprites)
self.sprites.camera = self.stage
self.sprites_in_front = pygame.sprite.RenderPlain()
self._create_player()
self.stage.object_to_follow = self.player
self.stage.load_level(1)
if VISIBLE_DEBUG:
# Visor de rendimiento
self.text = Text(world.font, world.fps, "FPS: %d")
self.sprites_in_front.add(self.text)
def _create_player(self):
self.control = Control()
self.player = Player(self, self.control, self.sprites, DATADIR)
self.sprites.add(self.player)
self.sprites.add(self.player.shadow)
self.sprites.add(self.player.bandage)
self.energy = energy.EnergyView(10, 10, self.world.font)
self.energy.set_model(self.player.energy_model)
self.sprites_in_front.add(self.energy)
self.enemy_energy = energy.EnergyView(440, 10, self.world.font)
self.sprites_in_front.add(self.enemy_energy)
def handle_event(self, event):
if event.type == pygame.KEYDOWN:
self.control.update(event, True)
if event.key == pygame.K_ESCAPE:
new_scene = scenes.mainmenu.MainMenu(self.world)
self.world.change_state(new_scene)
elif event.type == pygame.KEYUP:
self.control.update(event, False)
def update(self):
self.stage.update()
self.sprites.update()
self.sprites_in_front.update()
if DEBUG:
b1, b2, b3 = pygame.mouse.get_pressed()
if b1:
self.stage.do_camera_effect()
elif b2:
self.stage.do_camera_effect(10)
elif b3:
self.world.fps.slow()
self.control.post_update()
def draw(self, screen):
self.stage.draw(screen)
self.sprites.draw(screen)
self.sprites_in_front.draw(screen)
self.stage.last_draw(screen)
pygame.display.flip()
def on_player_energy_model_change(self, model):
pass
def on_enemy_energy_model_change(self, model):
self.enemy_energy.set_model(model)