forked from s464965/WMICraft
refactor: separated dir for screens
This commit is contained in:
parent
190b2bec01
commit
b647ba3423
@ -7,7 +7,9 @@ from common.constants import GAME_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT, FPS_COUNT,
|
||||
from common.helpers import draw_text
|
||||
from models.knight import Knight
|
||||
from models.monster import Monster
|
||||
from ui.screens.credits import Credits
|
||||
from ui.logs import Logs
|
||||
from ui.screens.options import Options
|
||||
from ui.stats import Stats
|
||||
from .grid import Grid
|
||||
from .spawner import Spawner
|
||||
@ -28,6 +30,7 @@ class Game:
|
||||
self.tiles.append((tile_path, converted_tile))
|
||||
|
||||
self.bg = pygame.image.load("./resources/textures/bg.jpg")
|
||||
self.screens = {'credits': Credits(self.screen, self.clock), 'options': Options(self.screen, self.clock)}
|
||||
|
||||
click = False
|
||||
|
||||
@ -48,10 +51,10 @@ class Game:
|
||||
self.game()
|
||||
if button_2.collidepoint((mx, my)):
|
||||
if click:
|
||||
self.options()
|
||||
self.screens['options'].display_screen()
|
||||
if button_3.collidepoint((mx, my)):
|
||||
if click:
|
||||
self.credits()
|
||||
self.screens['credits'].display_screen()
|
||||
pygame.draw.rect(self.screen, (0, 191, 255), button_1, 0, 4)
|
||||
draw_text('PLAY', WHITE, self.screen, 870, 255)
|
||||
|
||||
@ -77,38 +80,6 @@ class Game:
|
||||
pygame.display.update()
|
||||
self.clock.tick(60)
|
||||
|
||||
def options(self):
|
||||
running = True
|
||||
while running:
|
||||
self.screen.fill((0, 0, 0))
|
||||
|
||||
draw_text('options', WHITE, self.screen, 20, 20, 30)
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
running = False
|
||||
|
||||
pygame.display.update()
|
||||
self.clock.tick(60)
|
||||
|
||||
def credits(self):
|
||||
running = True
|
||||
while running:
|
||||
self.screen.fill((0, 0, 0))
|
||||
|
||||
draw_text('credits', WHITE, self.screen, 20, 20, 30)
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
running = False
|
||||
|
||||
pygame.display.update()
|
||||
self.clock.tick(60)
|
||||
|
||||
def game(self):
|
||||
running = True
|
||||
grid = Grid(self.tiles)
|
||||
|
0
ui/screens/__init__.py
Normal file
0
ui/screens/__init__.py
Normal file
6
ui/screens/credits.py
Normal file
6
ui/screens/credits.py
Normal file
@ -0,0 +1,6 @@
|
||||
from ui.screens.screen import Screen
|
||||
|
||||
|
||||
class Credits(Screen):
|
||||
def __init__(self, screen, clock):
|
||||
super().__init__('credits', screen, clock)
|
6
ui/screens/options.py
Normal file
6
ui/screens/options.py
Normal file
@ -0,0 +1,6 @@
|
||||
from ui.screens.screen import Screen
|
||||
|
||||
|
||||
class Options(Screen):
|
||||
def __init__(self, screen, clock):
|
||||
super().__init__('options', screen, clock)
|
28
ui/screens/screen.py
Normal file
28
ui/screens/screen.py
Normal file
@ -0,0 +1,28 @@
|
||||
import pygame
|
||||
|
||||
from common.colors import WHITE
|
||||
from common.helpers import draw_text
|
||||
|
||||
|
||||
class Screen:
|
||||
def __init__(self, screen_name, screen, clock):
|
||||
self.screen_name = screen_name
|
||||
self.screen = screen
|
||||
self.clock = clock
|
||||
|
||||
def display_screen(self):
|
||||
"""override this method in order to get specific layout"""
|
||||
running = True
|
||||
while running:
|
||||
self.screen.fill((0, 0, 0))
|
||||
|
||||
draw_text(self.screen_name, WHITE, self.screen, 20, 20, 30)
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
running = False
|
||||
|
||||
pygame.display.update()
|
||||
self.clock.tick(60)
|
Loading…
Reference in New Issue
Block a user