WMICraft/logic/game.py

76 lines
2.3 KiB
Python
Raw Normal View History

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-11 00:01:57 +02:00
from common.helpers import print_numbers
2022-04-10 20:28:50 +02:00
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-04-28 14:13:59 +02:00
from logic.health_bar import HealthBar
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))
2022-03-09 16:59:58 +01:00
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-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):
logs = Logs(self.screen)
level = Level(self.screen, logs)
2022-03-21 20:30:02 +01:00
2022-04-11 00:01:57 +02:00
# 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)
2022-04-11 00:01:57 +02: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
if event.key == pygame.K_n:
2022-04-10 20:28:50 +02:00
print_numbers_flag = not print_numbers_flag
2022-05-26 23:34:46 +02:00
# if event.type == NEXT_TURN: # is called every 'TURN_INTERVAL' milliseconds
# level.handle_turn()
2022-03-09 16:59:58 +01:00
2022-04-28 14:13:59 +02:00
stats.update()
logs.draw()
level.update()
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)