def main(argv): engine = GameEngine() engine.check_file_integrity("../data/test_init.json") engine.initialize_from_file("../data/test_init.json") result = engine.compute() print(result)
class Game(Screen): def __init__(self): super().__init__() self.engine = GameEngine(self.resolution, **self.game_config['settings']) self.lost_overrun = 0 self.running = True @property def lives(self): active_lives = [FULL_HEARTH] * self.engine.lives lost_lives = [EMPTY_HEARTH ] * (self.engine.max_lives - self.engine.lives) return active_lives + lost_lives @property def level(self): return self.font_50.render(f'Level: {self.engine.level}', 1, (255, 255, 255)) @property def score(self): return self.font_50.render(f'Score: {self.engine.score}', 1, (255, 255, 255)) def render(self): super().animate_background() if self.engine.player: self.window.blit(self.engine.player.ship_img, (self.engine.player.x, self.engine.player.y)) pygame.draw.rect(self.window, (200, 0, 0), ((self.engine.player.x, self.engine.player.y + self.engine.player.height + 10, self.engine.player.width, 10))) pygame.draw.rect( self.window, (0, 200, 0), ((self.engine.player.x, self.engine.player.y + self.engine.player.height + 10, self.engine.player.width * (self.engine.player.hp / self.engine.player.max_hp), 10))) for enemy in self.engine.enemies: self.window.blit(enemy.ship_img, (enemy.x, enemy.y)) for laser in self.engine.lasers: self.window.blit(laser.src.laser_img, (laser.x, laser.y)) x = 10 for life in self.lives: self.window.blit(life, (x, 10)) x += life.get_width() + 5 self.window.blit(self.level, (self.width - self.level.get_width() - 10, 10)) self.window.blit(self.score, (self.width - self.score.get_width() - 10, 60)) def run(self): while self.running: self.render() self.engine.compute() if self.engine.lost: if self.lost_overrun > self.FPS * 2: self.running = False else: self.lost_overrun += 1 else: self.engine.navigate() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit(0) pygame.display.update() self.clock.tick(self.FPS)