added labels to ui
This commit is contained in:
parent
edba68bbe2
commit
f69f5d0e5f
@ -3,7 +3,7 @@ from typing import Any
|
|||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
from Classes.System.InputHandler import InputHandler
|
from Classes.System.Components.InputHandler import InputHandler
|
||||||
|
|
||||||
class MonsterCard(pygame.sprite.Sprite):
|
class MonsterCard(pygame.sprite.Sprite):
|
||||||
__attacks = []
|
__attacks = []
|
||||||
|
Binary file not shown.
@ -1,14 +1,19 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from Classes.Objects.BoardField import BoardField
|
from Classes.Objects.BoardField import BoardField
|
||||||
|
from Classes.System.Components.Label import Label
|
||||||
|
|
||||||
class World():
|
class World():
|
||||||
__boardFields:list
|
__boardFields:list
|
||||||
|
__labels:list
|
||||||
|
__screen:pygame.surface
|
||||||
__cardWidth:int = 150
|
__cardWidth:int = 150
|
||||||
__cardHeight:int = 200
|
__cardHeight:int = 200
|
||||||
__cardOffset:int = 400
|
__cardOffset:int = 400
|
||||||
|
|
||||||
def __init__(self, cardWidth:int=300, cardHeight:int=550, cardOffset:int=400):
|
def __init__(self, screen:pygame.surface, cardWidth:int=200, cardHeight:int=250, cardOffset:int=400):
|
||||||
self.__boardFields = []
|
self.__boardFields = []
|
||||||
|
self.__labels = []
|
||||||
|
self.__screen = screen
|
||||||
self.__cardWidth = cardWidth
|
self.__cardWidth = cardWidth
|
||||||
self.__cardHeight = cardHeight
|
self.__cardHeight = cardHeight
|
||||||
self.__cardOffset = cardOffset
|
self.__cardOffset = cardOffset
|
||||||
@ -17,26 +22,37 @@ class World():
|
|||||||
def buildGameWorld(self):
|
def buildGameWorld(self):
|
||||||
# construct elements arround the playerfield
|
# construct elements arround the playerfield
|
||||||
# Todo add lifepoint label for player and enemy and make them scriptable
|
# Todo add lifepoint label for player and enemy and make them scriptable
|
||||||
eRow1Height = 75
|
|
||||||
eRow2Height = (self.__cardHeight + 35)
|
# presets the y position later passed down to the vector2
|
||||||
|
eRow1Height = 85
|
||||||
|
eRow2Height = (self.__cardHeight + 45)
|
||||||
pRow1Height = ((2 * self.__cardHeight) + 75)
|
pRow1Height = ((2 * self.__cardHeight) + 75)
|
||||||
pRow2Height = ((2 * self.__cardHeight) + self.__cardHeight + 30)
|
pRow2Height = ((2 * self.__cardHeight) + self.__cardHeight + 30)
|
||||||
|
|
||||||
eDeckPos = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * 0)), eRow1Height)
|
eDeckPos = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * 0)), eRow1Height)
|
||||||
eGravePos = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * 0)), eRow2Height)
|
eGravePos = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * 0)), eRow2Height)
|
||||||
pGravePos = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * 5)), pRow1Height)
|
eNamePos = pygame.Vector2(15, 45)
|
||||||
pDeckPos = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * 5)), pRow2Height)
|
eHPPos = pygame.Vector2(15, 75)
|
||||||
|
|
||||||
|
pGravePos = pygame.Vector2((self.__cardOffset + (((self.__cardWidth + 10) - 30 ) * 5)), pRow1Height)
|
||||||
|
pDeckPos = pygame.Vector2((self.__cardOffset + (((self.__cardWidth + 10) - 30 ) * 5)), pRow2Height)
|
||||||
|
pNamePos = pygame.Vector2(20, pRow2Height + 195)
|
||||||
|
pHPPos = pygame.Vector2(20, pRow2Height + 225)
|
||||||
|
|
||||||
|
self.__labels.append(Label("PlayerHP", self.__screen, "1000 / 1000", pHPPos))
|
||||||
|
self.__labels.append(Label("PlayerName", self.__screen, "Player", pNamePos))
|
||||||
|
self.__labels.append(Label("EnemyHP", self.__screen, "1000 / 1000", eHPPos))
|
||||||
|
self.__labels.append(Label("EnemyName", self.__screen, "Enemy", eNamePos))
|
||||||
self.__boardFields.append(BoardField("EnemyDeck", "Enemy", "Deck", eDeckPos, "Assets/Cards/Arena/field.png"))
|
self.__boardFields.append(BoardField("EnemyDeck", "Enemy", "Deck", eDeckPos, "Assets/Cards/Arena/field.png"))
|
||||||
self.__boardFields.append(BoardField("EnemyGraveyard", "Enemy", "Grave", eGravePos, "Assets/Cards/Arena/field.png"))
|
self.__boardFields.append(BoardField("EnemyGraveyard", "Enemy", "Grave", eGravePos, "Assets/Cards/Arena/field.png"))
|
||||||
self.__boardFields.append(BoardField("PlayerDeck", "Player", "Deck", pDeckPos, "Assets/Cards/Arena/field.png"))
|
self.__boardFields.append(BoardField("PlayerDeck", "Player", "Deck", pDeckPos, "Assets/Cards/Arena/field.png"))
|
||||||
self.__boardFields.append(BoardField("PlayerGraveyard", "Player", "Grave", pGravePos, "Assets/Cards/Arena/field.png"))
|
self.__boardFields.append(BoardField("PlayerGraveyard", "Player", "Grave", pGravePos, "Assets/Cards/Arena/field.png"))
|
||||||
|
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
pMonsterPos = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * i)), pRow1Height)
|
pMonsterPos = pygame.Vector2((self.__cardOffset + (((self.__cardWidth + 10) - 30) * i)), pRow1Height)
|
||||||
pEffectPos = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * i)), pRow2Height)
|
pEffectPos = pygame.Vector2((self.__cardOffset + (((self.__cardWidth + 10) - 30) * i)), pRow2Height)
|
||||||
eMonsterPos = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * (i+1)), eRow1Height))
|
eMonsterPos = pygame.Vector2((self.__cardOffset + (((self.__cardWidth + 10) - 30) * (i+1)), eRow1Height))
|
||||||
eEffectPos = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * (i+1))), eRow2Height)
|
eEffectPos = pygame.Vector2((self.__cardOffset + (((self.__cardWidth + 10) - 30) * (i+1))), eRow2Height)
|
||||||
|
|
||||||
self.__boardFields.append(BoardField("PlayerMonsterField-"+str(i), "Player", "MonsterField", pMonsterPos, "Assets/Cards/Arena/field.png"))
|
self.__boardFields.append(BoardField("PlayerMonsterField-"+str(i), "Player", "MonsterField", pMonsterPos, "Assets/Cards/Arena/field.png"))
|
||||||
self.__boardFields.append(BoardField("PlayerEffectField-"+str(i), "Player", "EffectField", pEffectPos, "Assets/Cards/Arena/field.png"))
|
self.__boardFields.append(BoardField("PlayerEffectField-"+str(i), "Player", "EffectField", pEffectPos, "Assets/Cards/Arena/field.png"))
|
||||||
@ -46,6 +62,9 @@ class World():
|
|||||||
def getBoardFields(self) -> list:
|
def getBoardFields(self) -> list:
|
||||||
return self.__boardFields
|
return self.__boardFields
|
||||||
|
|
||||||
|
def getLabels(self) -> list:
|
||||||
|
return self.__labels
|
||||||
|
|
||||||
def getCardWidth(self) -> int:
|
def getCardWidth(self) -> int:
|
||||||
return self.__cardWidth
|
return self.__cardWidth
|
||||||
|
|
||||||
|
Binary file not shown.
@ -2,8 +2,8 @@ import pygame
|
|||||||
from pygame.locals import *
|
from pygame.locals import *
|
||||||
|
|
||||||
from Classes.Objects.Cards.MonsterCard import MonsterCard
|
from Classes.Objects.Cards.MonsterCard import MonsterCard
|
||||||
from Classes.System.Window import Window
|
from Classes.System.Components.Window import Window
|
||||||
from Classes.System.InputHandler import InputHandler
|
from Classes.System.Components.InputHandler import InputHandler
|
||||||
from Classes.Objects.World import World
|
from Classes.Objects.World import World
|
||||||
|
|
||||||
class App:
|
class App:
|
||||||
@ -23,7 +23,7 @@ class App:
|
|||||||
self.__inputHandler = InputHandler()
|
self.__inputHandler = InputHandler()
|
||||||
|
|
||||||
# game word
|
# game word
|
||||||
self.__world = World()
|
self.__world = World(self.__window.getScreen())
|
||||||
|
|
||||||
self.startGameLoop()
|
self.startGameLoop()
|
||||||
self.onCleanup()
|
self.onCleanup()
|
||||||
@ -33,8 +33,19 @@ class App:
|
|||||||
# create sprite groups
|
# create sprite groups
|
||||||
self.cards = pygame.sprite.Group()
|
self.cards = pygame.sprite.Group()
|
||||||
|
|
||||||
testMonsterCard = MonsterCard(pygame.Vector2(500, 850), "Assets/Cards/MonsterCards/testmonstercard/", self.__inputHandler)
|
# ui trial assets
|
||||||
|
testMonsterCard = MonsterCard(pygame.Vector2(500, 1050), "Assets/Cards/MonsterCards/testmonstercard/", self.__inputHandler)
|
||||||
|
testMonsterCard1 = MonsterCard(pygame.Vector2(600, 1050), "Assets/Cards/MonsterCards/testmonstercard/", self.__inputHandler)
|
||||||
|
testMonsterCard2 = MonsterCard(pygame.Vector2(700, 1050), "Assets/Cards/MonsterCards/testmonstercard/", self.__inputHandler)
|
||||||
|
testMonsterCard3 = MonsterCard(pygame.Vector2(800, 1050), "Assets/Cards/MonsterCards/testmonstercard/", self.__inputHandler)
|
||||||
|
testMonsterCard4 = MonsterCard(pygame.Vector2(900, 1050), "Assets/Cards/MonsterCards/testmonstercard/", self.__inputHandler)
|
||||||
|
testMonsterCard5 = MonsterCard(pygame.Vector2(1000, 1050), "Assets/Cards/MonsterCards/testmonstercard/", self.__inputHandler)
|
||||||
self.cards.add(testMonsterCard)
|
self.cards.add(testMonsterCard)
|
||||||
|
self.cards.add(testMonsterCard1)
|
||||||
|
self.cards.add(testMonsterCard2)
|
||||||
|
self.cards.add(testMonsterCard3)
|
||||||
|
self.cards.add(testMonsterCard4)
|
||||||
|
self.cards.add(testMonsterCard5)
|
||||||
|
|
||||||
while self.__running:
|
while self.__running:
|
||||||
self.__clock.tick(self.__FPS)
|
self.__clock.tick(self.__FPS)
|
||||||
@ -44,7 +55,7 @@ class App:
|
|||||||
# render world
|
# render world
|
||||||
self.__window.drawWorld(self.__world)
|
self.__window.drawWorld(self.__world)
|
||||||
|
|
||||||
# update sprite groups
|
# updates all cards inside the cards Spritegroup at each step the gameloops does
|
||||||
self.cards.update()
|
self.cards.update()
|
||||||
|
|
||||||
# draw groups
|
# draw groups
|
||||||
@ -58,6 +69,8 @@ class App:
|
|||||||
|
|
||||||
# handles incoming event queue
|
# handles incoming event queue
|
||||||
def handleEvent(self, events):
|
def handleEvent(self, events):
|
||||||
|
# TODO: fix bug that stacks cards when dragging them around
|
||||||
|
selectedCard = None
|
||||||
for event in events:
|
for event in events:
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
self.onCleanup()
|
self.onCleanup()
|
||||||
@ -65,9 +78,9 @@ class App:
|
|||||||
mouse_x, mouse_y = pygame.mouse.get_pos()
|
mouse_x, mouse_y = pygame.mouse.get_pos()
|
||||||
mouse_pos = pygame.Vector2(mouse_x, mouse_y)
|
mouse_pos = pygame.Vector2(mouse_x, mouse_y)
|
||||||
for card in self.cards:
|
for card in self.cards:
|
||||||
if card.rect.collidepoint(mouse_pos):
|
if card.rect.collidepoint(mouse_pos) and selectedCard == None:
|
||||||
card.setDragging(True)
|
card.setDragging(True)
|
||||||
|
selectedCard = card
|
||||||
# card.setOffset(mouse_pos - card.getPos())
|
# card.setOffset(mouse_pos - card.getPos())
|
||||||
for field in self.__world.getBoardFields():
|
for field in self.__world.getBoardFields():
|
||||||
if field.getRect().collidepoint(mouse_pos):
|
if field.getRect().collidepoint(mouse_pos):
|
||||||
@ -87,6 +100,8 @@ class App:
|
|||||||
if event.button == 1: # Wenn linke Maustaste losgelassen wird
|
if event.button == 1: # Wenn linke Maustaste losgelassen wird
|
||||||
for card in self.cards:
|
for card in self.cards:
|
||||||
card.setDragging(False)
|
card.setDragging(False)
|
||||||
|
if not card == None:
|
||||||
|
card = None
|
||||||
|
|
||||||
# sets the running state for the gameloop
|
# sets the running state for the gameloop
|
||||||
def setRunning(self, running:bool):
|
def setRunning(self, running:bool):
|
||||||
|
46
Game_Client/Classes/System/Components/Label.py
Normal file
46
Game_Client/Classes/System/Components/Label.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
class Label:
|
||||||
|
rect:pygame.rect
|
||||||
|
image:pygame.image
|
||||||
|
__screen:pygame.surface
|
||||||
|
__text:str
|
||||||
|
__pos:pygame.Vector2
|
||||||
|
__font:pygame.font
|
||||||
|
font:pygame.font
|
||||||
|
__name:str
|
||||||
|
|
||||||
|
def __init__(self, name:str, screen:pygame.surface, text:str, pos:pygame.Vector2, size:float=20, color:str="white"):
|
||||||
|
self.__font = pygame.font.SysFont("Arial", size)
|
||||||
|
self.font = pygame.font.SysFont("Arial", size)
|
||||||
|
self.image = self.font.render(text, 1, color)
|
||||||
|
_, _, w, h = self.image.get_rect()
|
||||||
|
self.__pos = pos
|
||||||
|
self.rect = pygame.Rect(self.__pos.x, self.__pos.y, w, h)
|
||||||
|
self.__screen = screen
|
||||||
|
self.__text = text
|
||||||
|
|
||||||
|
def getText(self) -> str:
|
||||||
|
return self.__text
|
||||||
|
|
||||||
|
def getFont(self) -> pygame.font:
|
||||||
|
return self.__font
|
||||||
|
|
||||||
|
def getPos(self) -> pygame.Vector2:
|
||||||
|
return self.__pos
|
||||||
|
|
||||||
|
def getName(self) -> str:
|
||||||
|
return self.__name
|
||||||
|
|
||||||
|
def setText(self, newtext:str, color:str="white"):
|
||||||
|
self.image = self.font.render(newtext, 1, color)
|
||||||
|
|
||||||
|
def setFont(self, font:pygame.font, size:float, color:str="white"):
|
||||||
|
self.__font = pygame.font.SysFont(font, size)
|
||||||
|
self.change_text(self.text, color)
|
||||||
|
|
||||||
|
def setPos(self, pos:pygame.Vector2):
|
||||||
|
self.__pos = pos
|
||||||
|
|
||||||
|
def draw(self):
|
||||||
|
self.__screen.blit(self.image, (self.rect))
|
@ -21,9 +21,9 @@ class Window:
|
|||||||
|
|
||||||
pygame.display.set_caption = self.__title
|
pygame.display.set_caption = self.__title
|
||||||
|
|
||||||
# set framerate
|
# set framerate (where the fuck is it?)
|
||||||
|
|
||||||
def Render(self):
|
def Render(self):
|
||||||
|
# dear future me figure out what past me did!
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def setWidth(self, width:int):
|
def setWidth(self, width:int):
|
||||||
@ -45,4 +45,6 @@ class Window:
|
|||||||
# draws a given group of rectangles onto the screen
|
# draws a given group of rectangles onto the screen
|
||||||
def drawWorld(self, world:World):
|
def drawWorld(self, world:World):
|
||||||
for field in world.getBoardFields():
|
for field in world.getBoardFields():
|
||||||
pygame.draw.rect(self.__screen, field.getColor(), field.getRect())
|
pygame.draw.rect(self.__screen, field.getColor(), field.getRect())
|
||||||
|
for label in world.getLabels():
|
||||||
|
label.draw()
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user