本文整理汇总了Python中hero.Hero.move_left方法的典型用法代码示例。如果您正苦于以下问题:Python Hero.move_left方法的具体用法?Python Hero.move_left怎么用?Python Hero.move_left使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hero.Hero
的用法示例。
在下文中一共展示了Hero.move_left方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import move_left [as 别名]
class Game():
block_list = None
sprites_list = None
player_score = 0
game_status = True
def __init__(self):
self.player_score = 0
self.game_status = True
self.block_list = pygame.sprite.Group()
self.sprites_list = pygame.sprite.Group()
self.hero = Hero()
#receive list of blocks per level
self.level_list = []
self.level_list.append(level.Level01(self.hero))
self.level_list.append(level.Level02(self.hero))
self.current_level = 0
self.current_level = self.level_list[self.current_level]
self.hero.level = self.current_level
self.hero.x = 340
self.hero.y = 200 #constants.SCREEN_HEIGHT - self.hero.height
self.sprites_list.add(self.hero)
def process_events(self):
for event in pygame.event.get():
if event.Type == pygame.QUIT:
return False
# list of all events
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
self.hero.move_left()
if event.key == pygame.K_RIGHT:
self.hero.move_rigth()
if event.key == pygame.K_UP:
self.hero.jump()
return True
def update_game_state(self):
if self.game_status:
#update sprites position
self.sprites_list.update()
self.current_level.update()
# check collision
#blocks_collided = pygame.sprite.spritecollide(self.hero, self.block_list, True)
self.current_level.draw(screen)
self.sprites_list.draw(screen)
#check it collision
#for block in blocks_collided:
# if len(self.block_list) == 0:
def display_frame(self,screen):
self.current_level.draw(screen)
self.sprites_list.draw(screen)
pygame.display.flip()
示例2: Game
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import move_left [as 别名]
class Game(object):
def __init__(self, canvas):
self.canvas = canvas
self.hero = Hero()
self.map = Map(self.hero, self.canvas)
self.font_status = font.Font(size=11)
self.font_game_over = font.Font(size=25)
def is_hero_dead(self):
return self.hero.current_hp <= 0
def is_monster_dead(self, monster):
return monster.hp <= 0
def is_boss_dead(self, monster):
if monster.position == self.map.boss_position()[0].position:
return self.is_monster_dead(monster)
def combat(self):
if self.is_hero_dead():
self.canvas.delete('all')
self.draw_end_screen()
monster = self.map.get_monster()[0]
self.hero.attack(monster)
if self.is_boss_dead(monster):
self.hero.level_up()
self.new_level_buff()
self.map.generate_level()
self.hero.position = {'x': 0, 'y': 0}
self.draw_map()
if type(monster) == Skeleton:
self.map.map_texture.remove(monster)
self.hero.level_up()
def random_chance(self):
return random.randrange(0, 100)
def new_level_buff(self):
if self.random_chance() >= 90:
self.hero.current_hp = self.hero.hp
elif self.random_chance() >= 60:
self.hero.current_hp += self.hero.current_hp // 3
if self.hero.current_hp > self.hero.hp:
self.hero.current_hp = self.hero.hp
else:
self.hero.current_hp += self.hero.current_hp // 10
if self.hero.current_hp > self.hero.hp:
self.hero.current_hp = self.hero.hp
def move_route(self, key):
# if self.hero.move_count == 2:
# print("move")
# self.map.move_monsters()
# self.draw_map()
# self.hero.move_count = 0
pressed_key = key.keysym
if pressed_key == 'Up':
self.hero.move_up()
if not self.map.is_valid_move():
self.hero.move_down()
elif pressed_key == 'Down':
self.hero.move_down()
if not self.map.is_valid_move():
self.hero.move_up()
elif pressed_key == 'Right':
self.hero.move_right()
if not self.map.is_valid_move():
self.hero.move_left()
elif pressed_key == 'Left':
self.hero.move_left()
if not self.map.is_valid_move():
self.hero.move_right()
elif pressed_key == 'space':
if self.map.is_valid_move():
self.combat()
def draw_map(self):
if self.is_hero_dead():
self.draw_end_screen()
for i in self.map.map_texture:
i.draw()
self.draw_hero(self.hero.position['x'], self.hero.position['y'])
self.draw_hero_status_bar()
if self.map.is_valid_attack():
self.draw_monster_status_bar(self.map.get_monster()[0])
def draw_hero(self, x, y):
self.canvas.create_image(x * 72, y * 72, image=self.hero.current_img, anchor=NW)
def draw_hero_status_bar(self):
self.canvas.delete("status")
self.canvas.create_text(5, 722, text=self.hero, justify=CENTER, tags="status", anchor=NW, font=self.font_status)
def draw_monster_status_bar(self, monster):
self.canvas.create_text(400, 722, text=monster, tags="status", anchor=NW, font=self.font_status, fill="red")
def draw_end_screen(self):
self.canvas.delete('all')
self.canvas.create_text(300, 350, text="You died", anchor=NW, font=self.font_game_over, fill="red")