def run(self):
# Setup
for event in pygame.event.get():
if (event.type == pygame.QUIT):
return (False, '', None)
if (event.type == pygame.KEYDOWN):
if (event.key == pygame.K_UP and not self.dino.is_jumping()):
self.dino.set_movement(8)
self.dino.set_jumping(True)
if (event.key == pygame.K_DOWN):
self.dino.set_movement(-5)
if (event.key == pygame.K_h):
if self.dino.get_coins() > 4:
self.dino.set_coins(self.dino.get_coins() - 5)
self.powers.append(power(self.dino.get_position()))
# Movement
self.move_all_objects()
# Enemies
if (self.enemy.check_hitted(self.dino) and not self.enemy.get_hitted()):
del self.enemy
self.enemy = enemy(self.screen_size, self.ground_limit)
self.dino.set_lives(1, type='decrement')
if (not self.dino.get_lives()):
return(True, 'game_over', None)
# Prize
self.check_prize_hitted()
# Objects to show
objects_to_show = {}
objects_to_show['lives'] = self.dino.get_lives()
objects_to_show['coins'] = self.dino.get_coins()
objects_to_show['power'] = self.powers
objects_to_show['char'] = self.dino
objects_to_show['enemy'] = self.enemy
objects_to_show['prize'] = self.prize
self.clock.tick(self.difficulty * 60)
return (True, 'match_running', objects_to_show)
评论列表
文章目录