107 lines
3.7 KiB
Python
107 lines
3.7 KiB
Python
import pygame
|
|
from pygame.locals import *
|
|
|
|
from Classes.Objects.Cards.MonsterCard import MonsterCard
|
|
from Classes.System.Window import Window
|
|
from Classes.System.InputHandler import InputHandler
|
|
from Classes.System.World import World
|
|
|
|
|
|
class App:
|
|
|
|
__window:Window
|
|
__running:bool = True
|
|
__FPS = 60
|
|
__clock = pygame.time.Clock()
|
|
|
|
def __init__(self, width:int=1920, height:int=1080, title:str="default title"):
|
|
self.__window = Window(width=width, height=height, title=title)
|
|
self.startGameLoop()
|
|
self.onCleanup()
|
|
|
|
def startGameLoop(self):
|
|
|
|
# create sprite groups
|
|
cards = pygame.sprite.Group()
|
|
|
|
# game word
|
|
# the field
|
|
playerMonsterGroup = []
|
|
playerSpellGroup = []
|
|
enemyMonsterGroup = []
|
|
ememySpellGroup = []
|
|
enemyOtherGroup = []
|
|
playerOtherGroup = []
|
|
|
|
cardWith = 200
|
|
cardHeight = 250
|
|
cardOffset = 400
|
|
|
|
# player card fields
|
|
for i in range(5):
|
|
playerMonsterGroup.append(pygame.Rect(cardOffset + ((cardWith + 10) * i), (2 * cardHeight) + 60, cardWith, cardHeight))
|
|
playerSpellGroup.append(pygame.Rect(cardOffset + ((cardWith + 10) * i), (2 * cardHeight) + cardHeight + 70, cardWith, cardHeight))
|
|
|
|
enemyMonsterGroup.append(pygame.Rect(cardOffset + ((cardWith + 10) * (i+1)), 15, cardWith, cardHeight))
|
|
ememySpellGroup.append(pygame.Rect(cardOffset + ((cardWith + 10) * (i+1)), cardHeight + 25, cardWith, cardHeight))
|
|
|
|
enemyOtherGroup.append(pygame.Rect(cardOffset + ((cardWith + 10) * 0), 15, cardWith, cardHeight))
|
|
enemyOtherGroup.append(pygame.Rect(cardOffset + ((cardWith + 10) * 0), cardHeight + 25, cardWith, cardHeight))
|
|
|
|
playerOtherGroup.append(pygame.Rect(cardOffset + ((cardWith + 10) * 5), (2*cardHeight) + 60, cardWith, cardHeight))
|
|
playerOtherGroup.append(pygame.Rect(cardOffset + ((cardWith + 10) * 5), (2*cardHeight) + cardHeight + 70, cardWith, cardHeight))
|
|
|
|
testMonsterCard = MonsterCard((500,500), "Assets/Cards/MonsterCards/testmonstercard/")
|
|
cards.add(testMonsterCard)
|
|
|
|
while self.__running:
|
|
|
|
self.__clock.tick(self.__FPS)
|
|
|
|
self.__window.getScreen().fill((0,0,0))
|
|
# world.draw(self.__window.getScreen())
|
|
|
|
for card in playerOtherGroup:
|
|
pygame.draw.rect(self.__window.getScreen(), (0,255,0), card)
|
|
|
|
for card in playerMonsterGroup:
|
|
pygame.draw.rect(self.__window.getScreen(), (255,255,255), card)
|
|
|
|
for card in playerSpellGroup:
|
|
pygame.draw.rect(self.__window.getScreen(), (255,255,255), card)
|
|
|
|
for card in enemyOtherGroup:
|
|
pygame.draw.rect(self.__window.getScreen(), (255,0,0), card)
|
|
|
|
for card in enemyMonsterGroup:
|
|
pygame.draw.rect(self.__window.getScreen(), (255,0,255), card)
|
|
|
|
for card in ememySpellGroup:
|
|
pygame.draw.rect(self.__window.getScreen(), (255,0,255), card)
|
|
|
|
# update sprite groups
|
|
cards.update()
|
|
|
|
# draw groups
|
|
self.__window.drawSpriteGroup(cards)
|
|
|
|
# event handler
|
|
self.handleEvent(pygame.event.get())
|
|
|
|
# emits update to the game
|
|
pygame.display.update()
|
|
|
|
# handles incoming event queue
|
|
def handleEvent(self, events):
|
|
for event in events:
|
|
if event.type == pygame.QUIT:
|
|
self.onCleanup()
|
|
|
|
# sets the running state for the gameloop
|
|
def setRunning(self, running:bool):
|
|
self.__running = running
|
|
|
|
# ensures the gameloop stops running and the pygame instance is stopped properly
|
|
def onCleanup(self):
|
|
self.__running = False
|
|
pygame.quit() |