2022-03-09 16:59:58 +01:00
|
|
|
import sys
|
|
|
|
|
2022-03-11 19:42:17 +01:00
|
|
|
import pygame
|
|
|
|
|
2022-03-24 16:32:14 +01:00
|
|
|
from common.constants import *
|
2022-04-10 20:28:50 +02:00
|
|
|
from helpers.debug import print_numbers
|
|
|
|
from logic.level import Level
|
2022-03-11 19:42:17 +01:00
|
|
|
from ui.logs import Logs
|
2022-03-21 20:30:02 +01:00
|
|
|
from ui.screens.credits import Credits
|
2022-04-10 20:28:50 +02:00
|
|
|
from ui.screens.main_menu import MainMenu
|
2022-03-11 20:00:42 +01:00
|
|
|
from ui.screens.options import Options
|
2022-03-11 19:42:17 +01:00
|
|
|
from ui.stats import Stats
|
2022-03-09 16:59:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Game:
|
|
|
|
def __init__(self):
|
|
|
|
pygame.init()
|
|
|
|
pygame.display.set_caption(GAME_TITLE)
|
2022-03-11 19:42:17 +01:00
|
|
|
pygame.display.set_icon(pygame.image.load('./resources/icons/sword.png'))
|
2022-03-09 16:59:58 +01:00
|
|
|
|
|
|
|
self.screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
|
|
|
|
self.clock = pygame.time.Clock()
|
|
|
|
|
2022-03-11 19:42:17 +01:00
|
|
|
self.bg = pygame.image.load("./resources/textures/bg.jpg")
|
2022-03-11 20:00:42 +01:00
|
|
|
self.screens = {'credits': Credits(self.screen, self.clock), 'options': Options(self.screen, self.clock)}
|
2022-03-09 16:59:58 +01:00
|
|
|
|
2022-04-10 20:28:50 +02:00
|
|
|
self.level = Level(self.screen)
|
2022-03-09 16:59:58 +01:00
|
|
|
|
|
|
|
def main_menu(self):
|
2022-04-10 20:28:50 +02:00
|
|
|
menu = MainMenu(self.screen, self.clock, self.bg,
|
|
|
|
self.game,
|
|
|
|
self.screens['options'].display_screen,
|
|
|
|
self.screens['credits'].display_screen)
|
|
|
|
menu.display_screen()
|
2022-03-09 16:59:58 +01:00
|
|
|
|
|
|
|
def game(self):
|
|
|
|
stats = Stats()
|
|
|
|
logs = Logs()
|
2022-03-21 20:30:02 +01:00
|
|
|
|
2022-04-10 20:28:50 +02:00
|
|
|
print_numbers_flag = False
|
|
|
|
running = True
|
2022-03-09 16:59:58 +01:00
|
|
|
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
|
2022-04-10 20:28:50 +02:00
|
|
|
if event.key == 110: # clicked n letter on keyboard
|
|
|
|
print_numbers_flag = not print_numbers_flag
|
2022-03-09 16:59:58 +01:00
|
|
|
|
|
|
|
stats.draw(self.screen)
|
|
|
|
logs.draw(self.screen)
|
|
|
|
|
2022-04-10 20:28:50 +02:00
|
|
|
self.level.run()
|
2022-03-24 12:54:22 +01:00
|
|
|
|
2022-04-10 20:28:50 +02:00
|
|
|
if print_numbers_flag:
|
|
|
|
print_numbers()
|
2022-03-24 16:32:14 +01:00
|
|
|
|
2022-04-10 20:28:50 +02:00
|
|
|
pygame.display.update()
|
|
|
|
self.clock.tick(FPS_COUNT)
|