import sys import pygame from common.constants import * from common.helpers import print_numbers from logic.level import Level from ui.logs import Logs from ui.screens.credits import Credits from ui.screens.main_menu import MainMenu from ui.screens.options import Options from ui.stats import Stats from logic.health_bar import HealthBar class Game: def __init__(self): pygame.init() pygame.display.set_caption(GAME_TITLE) pygame.display.set_icon(pygame.image.load('./resources/icons/sword.png')) self.screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) self.clock = pygame.time.Clock() self.bg = pygame.image.load("./resources/textures/bg.jpg") self.screens = {'credits': Credits(self.screen, self.clock), 'options': Options(self.screen, self.clock)} def main_menu(self): menu = MainMenu(self.screen, self.clock, self.bg, self.game, self.screens['options'].display_screen, self.screens['credits'].display_screen) menu.display_screen() def game(self): logs = Logs(self.screen) level = Level(self.screen, logs) # setup clock for rounds NEXT_TURN = pygame.USEREVENT + 1 pygame.time.set_timer(NEXT_TURN, TURN_INTERVAL) # create level level.create_map() stats = Stats(self.screen, level.list_knights_blue, level.list_knights_red) print_numbers_flag = False running = True while running: self.screen.blit(self.bg, (0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = False if event.key == pygame.K_n: print_numbers_flag = not print_numbers_flag # if event.type == NEXT_TURN: # is called every 'TURN_INTERVAL' milliseconds # level.handle_turn() stats.update() logs.draw() level.update() if print_numbers_flag: print_numbers() pygame.display.update() self.clock.tick(FPS_COUNT)