76 lines
2.3 KiB
Python
76 lines
2.3 KiB
Python
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
|
|
|
|
|
|
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)}
|
|
|
|
self.level = Level(self.screen)
|
|
|
|
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):
|
|
stats = Stats(self.screen)
|
|
logs = Logs()
|
|
|
|
# setup clock for rounds
|
|
NEXT_TURN = pygame.USEREVENT + 1
|
|
pygame.time.set_timer(NEXT_TURN, TURN_INTERVAL)
|
|
|
|
# create level
|
|
self.level.create_map()
|
|
|
|
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.key == pygame.K_r:
|
|
stats.red_team_hp_bar.take_dmg(5)
|
|
if event.type == NEXT_TURN: # is called every 'TURN_INTERVAL' milliseconds
|
|
self.level.handle_turn()
|
|
|
|
stats.draw()
|
|
logs.draw(self.screen)
|
|
|
|
self.level.update()
|
|
|
|
if print_numbers_flag:
|
|
print_numbers()
|
|
|
|
pygame.display.update()
|
|
self.clock.tick(FPS_COUNT)
|