本文整理汇总了Python中level.Level.render方法的典型用法代码示例。如果您正苦于以下问题:Python Level.render方法的具体用法?Python Level.render怎么用?Python Level.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类level.Level
的用法示例。
在下文中一共展示了Level.render方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import render [as 别名]
class Game(object):
def __init__(self, screen_height, screen_width):
pygame.init()
self.screen_height = screen_height
self.screen_width = screen_width
self.level_maps = ("./data/level1.map", "./data/level2.map", "./data/level3.map")
self.current_level_map_index = 0
self.pause = False
self.won_grow_rate = 10
height_width = (self.screen_height, self.screen_width)
self.screen = pygame.display.set_mode(height_width)
pygame.display.set_caption("PySnake")
self.score = Score((0, 500))
self.reload_game = False
self.speed = 5
def init_resources(self):
self.level = Level(self.level_maps[self.current_level_map_index])
self.snake = Snake((64, 64))
self.move_direction = Direction.RIGHT
self.food = None
def start(self):
clock = pygame.time.Clock()
game_over = False
won = True
first_load = True
while not game_over:
clock.tick(self.speed)
for event in pygame.event.get():
self.event_handler(event)
if self.reload_game:
break
if not self.pause:
background = self.level.render()
self.snake.render(background)
if self.food == None:
position = self.generate_free_position()
self.food = Food(position, 1)
background.blit(self.food.image, self.food.rect)
self.screen.fill((0, 0, 0))
self.screen.blit(background, (0, 0))
self.screen.blit(self.score.image, self.score.rect)
pygame.display.flip()
if first_load:
first_load = False
self.pause = True
continue
not_collide = self.snake.update(self.move_direction)
if not not_collide or self.level.collide(self.snake.position):
game_over = True
won = False
if self.food.rect.colliderect(self.snake.head.rect):
self.snake.grow(self.food.grow_rate)
self.score.add(100)
self.food = None
if self.snake.length() == self.won_grow_rate:
game_over = True
if self.reload_game:
self.load_game()
elif won and game_over:
self.load_next_level()
elif game_over:
print("Game over")
def event_handler(self, event):
if event.type == QUIT:
sys.exit(0)
elif event.type == KEYDOWN:
key = pygame.key.get_pressed()
new_direction = self.move_direction
if key[pygame.K_LEFT]:
new_direction = Direction.LEFT
elif key[pygame.K_RIGHT]:
new_direction = Direction.RIGHT
elif key[pygame.K_UP]:
new_direction = Direction.UP
elif key[pygame.K_DOWN]:
new_direction = Direction.DOWN
elif key[pygame.K_p]:
self.pause = not self.pause
elif key[pygame.K_s]:
self.pause = True
level = self.current_level_map_index
snake = self.snake.get_snake_coords()
food = self.food.get_food_position()
direction = self.move_direction
SaveGame.save(level, snake, food, direction)
elif key[pygame.K_l]:
self.reload_game = True
#.........这里部分代码省略.........
示例2: run
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import render [as 别名]
#.........这里部分代码省略.........
if scripted_event_trigger == None:
scripted_event_trigger = level.update()
else:
level.update()
#Objects are only updated when there's not a scripted event going on
normal_updating = not scripted_event_on and not fading and not paused
if changing_level:
player.update(level)
elif normal_updating:
for o in objects:
if o.dead and o.itemclass != "player":
objects.remove(o)
continue
new_particles = o.update(level)
if o.itemclass == "projectile":
if player.rect.collidepoint(o.x, o.y) and o.current_animation == "default":
new_particles = player.take_damage(o.damage)
o.die()
if type(new_particles) == list: #Sometimes the type of the return value is int (hackity hack)
if new_particles != None:
for p in new_particles:
particles.append(p)
if normal_updating or changing_level:
for p in particles:
p.update()
if p.dead:
particles.remove(p)
#Rendering level - background and tiles
level.render()
#Rendering objects and particles
for o in objects:
if o.itemclass == "player":
o.render(None, None, (fading or paused) )
else:
o.render(None, None, (scripted_event_on or fading or paused) )
#On special conditions the animations aren't updated. The player is updated on a scripted event, others are not.
for p in particles:
p.render()
#Rendering GUI on top of game graphics:
if (not paused) or (not Variables.vdict["devmode"]):
render_gui(screen, player.life, score.score, (5, 5))
# Scripted event triggering:
if scripted_event_trigger != None:
if player.on_ground:
for ev in scripted_events:
if ev.trigger_type == scripted_event_trigger:
scripted_event_on = True
current_scripted_event = ev
current_scripted_event_element = None
text = None
phase = 0
cleared = False # Clearing dialog boxes
player.dy = 0
player.dx = 0
player.update()
scripted_event_trigger = None
示例3: run
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import render [as 别名]
#.........这里部分代码省略.........
play_sound("coins")
player.inventory.append(pick_up_item)
scripted_event_trigger = pick_up_item.itemclass
trigger = level.trigger(player.x, player.y)
if inputs[SPECIAL]:
trigger = TRIGGER_FLIP
if not moved or (player.current_animation == "dying" and player.on_ground):
player.dec((PLAYER_MAX_ACC, 0))
if trigger == TRIGGER_FLIP:
if flip_wait == -1:
flip_wait = 0
play_sound("woosh")
if flip_wait != -1:
flip_wait += 1
if flip_wait > FLIP_DELAY:
flip_wait = -1
level.flip()
for o in objects:
o.flip()
for p in particles:
p.flip()
#Rendering and updating objects:
if scripted_event_trigger == TRIGGER_NONE:
scripted_event_trigger = level.update()
else:
level.update()
level.render()
if not scripted_event_on:
for o in objects:
if o.dead and o.itemclass != "player":
objects.remove(o)
continue
new_particles = o.update(level)
if o.itemclass == "projectile":
if player.rect.collidepoint(o.x, o.y) and o.current_animation == "default":
new_particles = player.take_damage(o.damage)
o.die()
if new_particles != None:
for p in new_particles:
particles.append(p)
for o in objects:
o.render()
for p in particles:
p.update()
p.render()
if p.dead:
particles.remove(p)
#Dust effect:
if (player.current_animation == "walking"):
particles.append(Particle(screen, 10, player.rect.centerx - player.dx / 2 + random.uniform(-2, 2), player.rect.bottom, -player.dx * 0.1, 0.1, 0.3))
#Rendering GUI on top of everything else:
render_gui(screen, player.life, score.score, (5, 5))