本文整理汇总了Python中Timer.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.draw方法的具体用法?Python Timer.draw怎么用?Python Timer.draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer.draw方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Level1State
# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import draw [as 别名]
#.........这里部分代码省略.........
self.cloud_images.append(img.Image(
DatabaseReceiver.get_level_data(
"IMAGE", "Level1", "cloud1"), 1200, 300, 0.5))
self.cloud_images.append(img.Image(
DatabaseReceiver.get_level_data(
"IMAGE", "Level1", "cloud2"), 1500, 250, 0.5))
self.cloud_images.append(img.Image(
DatabaseReceiver.get_level_data(
"IMAGE", "Level1", "cloud3"), 2000, 500, 0.5))
def run(self):
self.map.run()
# Make the enemy objects and add every enemy to the enemy_list.
# Every enemy takes a x and y coordinate as argument.
# (Spawn point)
# And the range it can walk on the x axis.
# The fish takes a third argument.
# You got two choices: 'Water' or 'Lava'.
# According to the fish you want.
self.enemy_list.append(Fly(500, 600, 100))
self.enemy_list.append(Fly(1500, 100, 100))
self.enemy_list.append(Tank(2600, 50, 380))
self.enemy_list.append(Fish(1000, 700, 200, 'Water'))
# Add a collider for the enemies and the player.
# It takes the player, map group(tiles),
# an array with all the enemy objects, Reference to
# LevelStateManager
# as arguments.
self.collider = Collider(self.player, self.map.get_group(),
self.enemy_list, self.LevelStateManager)
# Load the background music.
# The pygame.mixer.music.load
# method takes the file location as an argument.
# It has to be .wav or .mp3.
self.level_background_music = \
pygame.mixer.music.load('../Data/Music/Level4_2.mp3')
# Play the background music.
# This is only necessary in level1,
# because we don't stop the music when creating level2.
pygame.mixer.music.play()
# Create a camera for this level.
self.camera = Camera(self.shift_start, self.shift_end,
self.map, self.player, self.enemy_list)
# Create a timer for this level.
self.timer = Timer()
# Load the best time of level 1.
self.timer.load_best_time(1)
def update(self):
# Update the camera with the player's x speed.
self.camera.update_camera(self.player.x_speed)
self.timer.update()
self.player.update()
# Update all the enemies in the enemy_list.
self.enemy_list = self.collider.enemy_list
for e in self.enemy_list:
e.update()
self.collider.update()
self.background.update(self.player.x_speed, 0, self.player.rect.x)
# Update the clouds.
for image in self.cloud_images:
image.update(self.player.x_speed, 0, self.player.rect.x)
# Opens the MainMenu when you press on the escape key.
if pygame.key.get_pressed()[pygame.K_ESCAPE]:
self.LevelStateManager.level_state = self
self.LevelStateManager.states = self.main_menu
def draw(self):
self.background.draw()
# Draw all the clouds on the surface.
for cloud in self.cloud_images:
cloud.draw()
self.map.draw()
# Draw all the enemies.
for e in self.enemy_list:
e.draw()
self.player.draw()
self.timer.draw()
# Reset the best time with the given level.
# The best time is in the lower right corner of all the levels.
def reset_best_time(self):
self.timer.reset_best_time(1)