diff --git a/Game_Client/Classes/Objects/BoardField.py b/Game_Client/Classes/Objects/BoardField.py index c4d8270..fb336bd 100644 --- a/Game_Client/Classes/Objects/BoardField.py +++ b/Game_Client/Classes/Objects/BoardField.py @@ -2,14 +2,16 @@ import pygame class BoardField(): __name:str + __side:str __type:str __pos:pygame.Vector2 __size:tuple __color:tuple = (255,255,255) _rect:pygame.Rect - def __init__(self, name:str, type:str, pos:pygame.Vector2, size:tuple, color:tuple): + def __init__(self, name:str, side:str, type:str, pos:pygame.Vector2, size:tuple, color:tuple): self.__name = name + self.__side = side self.__type = type self.__pos = pos self.__size = size @@ -19,6 +21,9 @@ class BoardField(): def getName(self) -> str: return self.__name + def getSide(self) -> str: + return self.__side + def getType(self) -> str: return self.__type diff --git a/Game_Client/Classes/Objects/Cards/MonsterCard.py b/Game_Client/Classes/Objects/Cards/MonsterCard.py index ff85836..42a05db 100644 --- a/Game_Client/Classes/Objects/Cards/MonsterCard.py +++ b/Game_Client/Classes/Objects/Cards/MonsterCard.py @@ -13,6 +13,7 @@ class MonsterCard(pygame.sprite.Sprite): __dragging:bool = False __offset:pygame.Vector2 = pygame.Vector2(0,0) __inputHandler: InputHandler + __type:str = "MonsterCard" image:pygame.image rect:pygame.rect @@ -37,8 +38,6 @@ class MonsterCard(pygame.sprite.Sprite): self.__attacks.append(attack) def update(self): - print("card update") - print(self.getDragging()) if self.getDragging(): mouse_pos = self.__inputHandler.getMousePos() self.__pos = mouse_pos @@ -65,8 +64,14 @@ class MonsterCard(pygame.sprite.Sprite): def getPos(self): return self.__pos + def getType(self): + return self.__type + def setDragging(self, dragging:bool): self.__dragging = dragging def setOffset(self, offset:pygame.Vector2): - self.__offset = offset \ No newline at end of file + self.__offset = offset + + def setPos(self, pos:pygame.Vector2): + self.__pos = pos \ No newline at end of file diff --git a/Game_Client/Classes/Objects/Cards/__pycache__/MonsterCard.cpython-311.pyc b/Game_Client/Classes/Objects/Cards/__pycache__/MonsterCard.cpython-311.pyc index 8716d37..0cdb2d2 100644 Binary files a/Game_Client/Classes/Objects/Cards/__pycache__/MonsterCard.cpython-311.pyc and b/Game_Client/Classes/Objects/Cards/__pycache__/MonsterCard.cpython-311.pyc differ diff --git a/Game_Client/Classes/Objects/World.py b/Game_Client/Classes/Objects/World.py index 37c5b77..a1f3a58 100644 --- a/Game_Client/Classes/Objects/World.py +++ b/Game_Client/Classes/Objects/World.py @@ -19,29 +19,29 @@ class World(): # construct elements arround the playerfield # Todo add lifepoint label for player and enemy and make them scriptable pVector = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * 0)), 15) - self.__boardFields.append(BoardField("EnemyDeck", "Deck", pVector, (self.__cardWidth, self.__cardHeight), (0,255,0))) + self.__boardFields.append(BoardField("EnemyDeck", "Enemy", "Deck", pVector, (self.__cardWidth, self.__cardHeight), (0,255,0))) pVector = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * 0)), (self.__cardHeight + 25)) - self.__boardFields.append(BoardField("EnemyGraveyard", "Grave", pVector, (self.__cardWidth, self.__cardHeight), (0,255,0))) + self.__boardFields.append(BoardField("EnemyGraveyard", "Enemy", "Grave", pVector, (self.__cardWidth, self.__cardHeight), (0,255,0))) pVector = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * 5)), ((2 * self.__cardHeight) + 60)) - self.__boardFields.append(BoardField("PlayerDeck", "Deck", pVector, (self.__cardWidth, self.__cardHeight), (255,0,0))) + self.__boardFields.append(BoardField("PlayerDeck", "Player", "Deck", pVector, (self.__cardWidth, self.__cardHeight), (255,0,0))) pVector = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * 5)), ((2 * self.__cardHeight) + self.__cardHeight + 70)) - self.__boardFields.append(BoardField("PlayerGraveyard", "Grave", pVector, (self.__cardWidth, self.__cardHeight), (255,0,0))) + self.__boardFields.append(BoardField("PlayerGraveyard", "Player", "Grave", pVector, (self.__cardWidth, self.__cardHeight), (255,0,0))) for i in range(5): pVector = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * i)), ((2 * self.__cardHeight) + 60)) - self.__boardFields.append(BoardField("PlayerMonsterField-"+str(i),"MonsterField",pVector,(self.__cardWidth, self.__cardHeight),(255,255,255))) + self.__boardFields.append(BoardField("PlayerMonsterField-"+str(i), "Player", "MonsterField",pVector,(self.__cardWidth, self.__cardHeight),(255,255,255))) pVector = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * i)), ((2 * self.__cardHeight) + self.__cardHeight + 70)) - self.__boardFields.append(BoardField("PlayerMonsterField-"+str(i), "EffectField", pVector, (self.__cardWidth, self.__cardHeight), (255,255,255))) + self.__boardFields.append(BoardField("PlayerMonsterField-"+str(i), "Player", "EffectField", pVector, (self.__cardWidth, self.__cardHeight), (255,255,255))) pVector = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * (i+1)), 15), (self.__cardWidth, self.__cardHeight)) - self.__boardFields.append(BoardField("EnemyMonsterField-"+str(i), "MonsterField", pVector, (self.__cardWidth, self.__cardHeight), (255,255,255))) + self.__boardFields.append(BoardField("EnemyMonsterField-"+str(i), "Enemy", "MonsterField", pVector, (self.__cardWidth, self.__cardHeight), (255,255,255))) pVector = pygame.Vector2((self.__cardOffset + ((self.__cardWidth + 10) * (i+1))), (self.__cardHeight + 25)) - self.__boardFields.append(BoardField("EnemySpellTrapField-"+str(i), "EffectField", pVector, (self.__cardWidth, self.__cardHeight), (255,255,255))) + self.__boardFields.append(BoardField("EnemySpellTrapField-"+str(i), "Enemy", "EffectField", pVector, (self.__cardWidth, self.__cardHeight), (255,255,255))) def getBoardFields(self) -> list: return self.__boardFields diff --git a/Game_Client/Classes/Objects/__pycache__/BoardField.cpython-311.pyc b/Game_Client/Classes/Objects/__pycache__/BoardField.cpython-311.pyc index aeeb3ec..1481fa3 100644 Binary files a/Game_Client/Classes/Objects/__pycache__/BoardField.cpython-311.pyc and b/Game_Client/Classes/Objects/__pycache__/BoardField.cpython-311.pyc differ diff --git a/Game_Client/Classes/Objects/__pycache__/World.cpython-311.pyc b/Game_Client/Classes/Objects/__pycache__/World.cpython-311.pyc index c7b425c..e0a6152 100644 Binary files a/Game_Client/Classes/Objects/__pycache__/World.cpython-311.pyc and b/Game_Client/Classes/Objects/__pycache__/World.cpython-311.pyc differ diff --git a/Game_Client/Classes/System/App.py b/Game_Client/Classes/System/App.py index 075704d..8e83619 100644 --- a/Game_Client/Classes/System/App.py +++ b/Game_Client/Classes/System/App.py @@ -62,15 +62,22 @@ class App: if event.type == pygame.QUIT: self.onCleanup() elif pygame.mouse.get_pressed()[0]: # Wenn linke Maustaste gedrückt wird - print("mousebutton down") mouse_x, mouse_y = pygame.mouse.get_pos() mouse_pos = pygame.Vector2(mouse_x, mouse_y) for card in self.cards: if card.rect.collidepoint(mouse_pos): card.setDragging(True) - print(card.getDragging()) - # Berechnung des Offset zwischen der Karte und der Mausposition - card.setOffset(mouse_pos - card.getPos()) + + # card.setOffset(mouse_pos - card.getPos()) + for field in self.__world.getBoardFields(): + if field.getRect().collidepoint(mouse_pos): + if field.getSide() == "Player": + if field.getType() == "MonsterField" and card.getType() == "MonsterCard": + # todo: resize card so that it fits into the card field + pygame.transform.scale(card.image,(int((field.getRect().width - 10)),int((field.getRect().height - 10)))) + card.rect.center = field.getRect().center + card.setDragging(False) + self.__window.getScreen().blit(card.image, field.getRect().center) elif event.type == pygame.MOUSEBUTTONUP: if event.button == 1: # Wenn linke Maustaste losgelassen wird diff --git a/Game_Client/Classes/System/__pycache__/App.cpython-311.pyc b/Game_Client/Classes/System/__pycache__/App.cpython-311.pyc index d826af9..355ac30 100644 Binary files a/Game_Client/Classes/System/__pycache__/App.cpython-311.pyc and b/Game_Client/Classes/System/__pycache__/App.cpython-311.pyc differ