game.py
import pygame
import scene
pygame.init()
pygame.font.init()
class Game:
def __init__(self):
self.screenSize = (1200, 800)
self.screen = pygame.display.set_mode(self.screenSize)
self.clock = pygame.time.Clock()
self.FPS = 60
self.font = pygame.font.Font("Fonts/LeagueGothic.ttf", 32)
self.mainMenuScene = scene.MainMenuScene(self)
self.gameMenuScene = scene.GameMenuScene(self)
self.battleScene = scene.Scene(self)
self.scene = self.mainMenuScene
self.running = True
def run(self):
while self.running:
self.updateInput()
self.updateLogic()
self.updateDraw()
def updateInput(self):
for event in pygame.event.get():
self.scene.updateInput(event)
if event.type == pygame.QUIT:
self.exit()
def updateLogic(self):
self.scene.updateLogic()
def updateDraw(self):
self.scene.updateDraw()
def exit(self):
self.running = False
def changeScene(self, scene):
self.scene = scene
--------------------------------------------------
scene.py
import pygame
from GUI import Button
class Scene:
def __init__(self, game):
self.game = game
self.buttons = []
def updateInput(self, event):
if event.type == pygame.QUIT:
self.running = False
for button in self.buttons:
button.checkInput(event)
def updateLogic(self):
for button in self.buttons:
button.update()
self.game.clock.tick(self.game.FPS)
def updateDraw(self):
self.game.screen.fill((0, 0, 0))
for button in self.buttons:
button.draw(self.game.screen)
pygame.display.flip()
def text(self, position, text, color=(255, 255, 255)):
textSurface = self.game.font.render(text, True, color)
self.game.screen.blit(textSurface, position)
class MainMenuScene(Scene):
def __init__(self, game,):
super().__init__(game)
self.buttons = []
self.buttons.append(Button(self.game, (10, 10), (200, 32), "New Game", lambda: game.changeScene(game.gameMenuScene)))
self.buttons.append(Button(self.game, (10, 10+48), (200, 32), "Exit", lambda: game.exit()))
class GameMenuScene(Scene):
def __init__(self, game,):
super().__init__(game)
self.buttons = []
self.buttons.append(Button(self.game, (10, 10), (200, 32), "New Battle", lambda: game.changeScene(game.battleScene)))
self.buttons.append(Button(self.game, (10, 10+48), (200, 32), "Main Menu", lambda: game.changeScene(game.mainMenuScene)))
class BattleScene(Scene):
def __init__(self, game,):
super().__init__(game)
self.buttons = []