moved position system over to use vector2
This commit is contained in:
@ -4,8 +4,7 @@ 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
|
||||
|
||||
from Classes.Objects.World import World
|
||||
|
||||
class App:
|
||||
|
||||
@ -13,71 +12,38 @@ class App:
|
||||
__running:bool = True
|
||||
__FPS = 60
|
||||
__clock = pygame.time.Clock()
|
||||
__myFont:pygame.font
|
||||
__world:World
|
||||
__inputHandler: InputHandler
|
||||
|
||||
def __init__(self, width:int=1920, height:int=1080, title:str="default title"):
|
||||
pygame.font.init()
|
||||
self.__myFont = pygame.font.SysFont('Comic Sans MS', 30)
|
||||
self.__window = Window(width=width, height=height, title=title)
|
||||
self.__inputHandler = InputHandler()
|
||||
|
||||
# game word
|
||||
self.__world = World()
|
||||
|
||||
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)
|
||||
# render world
|
||||
self.__inputHandler.getMouseHover(self.__world)
|
||||
self.__window.drawWorld(self.__world)
|
||||
|
||||
# update sprite groups
|
||||
cards.update()
|
||||
@ -96,6 +62,10 @@ class App:
|
||||
for event in events:
|
||||
if event.type == pygame.QUIT:
|
||||
self.onCleanup()
|
||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||
pass
|
||||
if event.type == pygame.MOUSEBUTTONUP:
|
||||
pass
|
||||
|
||||
# sets the running state for the gameloop
|
||||
def setRunning(self, running:bool):
|
||||
|
@ -1,5 +1,8 @@
|
||||
import pygame
|
||||
|
||||
from Classes.Objects.World import World
|
||||
from Classes.Objects.BoardField import BoardField
|
||||
|
||||
class InputHandler:
|
||||
# returns pressed key
|
||||
def getPressed():
|
||||
@ -21,4 +24,22 @@ class InputHandler:
|
||||
yvel = 1
|
||||
|
||||
return tuple((xvel, yvel))
|
||||
|
||||
|
||||
def getMousePos(self) -> pygame.Vector2:
|
||||
return pygame.Vector2(pygame.mouse.get_pos())
|
||||
|
||||
# get field under mousbutton
|
||||
def getMouseHover(self, world:World) -> BoardField:
|
||||
mouse_pos = self.getMousePos()
|
||||
xPos = [int(v//world.getCardWidth()) for v in mouse_pos.x]
|
||||
yPos = [int(v//world.getCardHeifht()) for v in mouse_pos.y]
|
||||
|
||||
try:
|
||||
for field in world.getBoardFields():
|
||||
for x in xPos:
|
||||
for y in yPos:
|
||||
if x == field.getPos().x and y == field.getPos().y:
|
||||
return field
|
||||
except IndexError: pass
|
||||
|
||||
return None
|
@ -1,6 +1,9 @@
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
|
||||
from Classes.Objects.BoardField import BoardField
|
||||
from Classes.Objects.World import World
|
||||
|
||||
class Window:
|
||||
__width:int = 800
|
||||
__height:int = 600 # takes 80% of width which tranlates to 640
|
||||
@ -37,4 +40,9 @@ class Window:
|
||||
|
||||
# draws a passed sprite group to the screen
|
||||
def drawSpriteGroup(self, group:pygame.sprite.Group):
|
||||
group.draw(self.__screen)
|
||||
group.draw(self.__screen)
|
||||
|
||||
# draws a given group of rectangles onto the screen
|
||||
def drawWorld(self, world:World):
|
||||
for field in world.getBoardFields():
|
||||
pygame.draw.rect(self.__screen, field.getColor(), field.getRect())
|
@ -1,9 +0,0 @@
|
||||
import pygame
|
||||
|
||||
class World():
|
||||
|
||||
def __init__(self, mapImage):
|
||||
self.__map = mapImage
|
||||
|
||||
def draw(self, surface:pygame.Surface):
|
||||
surface.blit(self.__map, (0,0))
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Game_Client/Classes/System/__pycache__/World.cpython-312.pyc
Normal file
BIN
Game_Client/Classes/System/__pycache__/World.cpython-312.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user