merged broken branches client with master branch and added first statehandling for card placement
This commit is contained in:
98
Game_Client/Classes/Game/Cards/Card.py
Normal file
98
Game_Client/Classes/Game/Cards/Card.py
Normal file
@ -0,0 +1,98 @@
|
||||
import json
|
||||
import pygame
|
||||
|
||||
from Classes.System.Components.InputHandler import InputHandler
|
||||
from Classes.Game.Player import Player
|
||||
|
||||
class Card(pygame.sprite.Sprite):
|
||||
__name:str
|
||||
__id:int
|
||||
__description:str
|
||||
__attacks = []
|
||||
__type:str = "MonsterCard"
|
||||
__pos:pygame.Vector2
|
||||
__dragging:bool = False
|
||||
__offset:pygame.Vector2 = pygame.Vector2(0,0)
|
||||
__inputHandler: InputHandler
|
||||
__owner:Player
|
||||
__state:str
|
||||
image:pygame.image
|
||||
rect:pygame.rect
|
||||
|
||||
def __init__(self, pos: pygame.Vector2, assetDir: str, inputHandler: InputHandler, owner: Player):
|
||||
if assetDir == "":
|
||||
raise ValueError("Card: imagePath cannot be empty")
|
||||
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
|
||||
with open(assetDir + "/card.json", 'r') as file:
|
||||
data = json.load(file)
|
||||
|
||||
self.__owner = owner
|
||||
self.__id = int(data["id"])
|
||||
self.__pos = pos
|
||||
self.__name = data["name"]
|
||||
self.__type = data.get("type")
|
||||
self.image = pygame.image.load(assetDir + "/card.png").convert_alpha()
|
||||
self.rect = self.image.get_rect()
|
||||
self.__inputHandler = inputHandler
|
||||
self.rect.center = self.__pos
|
||||
self.__description = data["description"]
|
||||
self.original_size = self.image.get_size()
|
||||
self.original_position = self.rect.center
|
||||
self.__state = "onHand"
|
||||
|
||||
self.__attacks = []
|
||||
for attack in data.get("attacks", []):
|
||||
self.__attacks.append(attack)
|
||||
|
||||
def update(self):
|
||||
if self.__dragging:
|
||||
mouse_pos = self.__inputHandler.getMousePos()
|
||||
self.__pos = mouse_pos
|
||||
self.rect.center = self.__pos
|
||||
|
||||
def attacks(self):
|
||||
return self.__attacks
|
||||
|
||||
def getName(self) -> str:
|
||||
return self.__name
|
||||
|
||||
def getCardSprite(self) -> pygame.image:
|
||||
return self.__cardSprite
|
||||
|
||||
def getDescription(self):
|
||||
return self.__description
|
||||
|
||||
def getDragging(self):
|
||||
return self.__dragging
|
||||
|
||||
def getOffset(self):
|
||||
return self.__offset
|
||||
|
||||
def getPos(self):
|
||||
return self.__pos
|
||||
|
||||
def getType(self):
|
||||
return self.__type
|
||||
|
||||
def getID(self) -> int:
|
||||
return self.__id
|
||||
|
||||
def getOwner(self) -> Player:
|
||||
return self.__owner
|
||||
|
||||
def getState(self) -> str:
|
||||
return self.__state
|
||||
|
||||
def setDragging(self, dragging:bool):
|
||||
self.__dragging = dragging
|
||||
|
||||
def setOffset(self, offset:pygame.Vector2):
|
||||
self.__offset = offset
|
||||
|
||||
def setPos(self, pos:pygame.Vector2):
|
||||
self.__pos = pos
|
||||
|
||||
def setState(self, state:str):
|
||||
self.__state = state
|
BIN
Game_Client/Classes/Game/Cards/__pycache__/Card.cpython-311.pyc
Normal file
BIN
Game_Client/Classes/Game/Cards/__pycache__/Card.cpython-311.pyc
Normal file
Binary file not shown.
BIN
Game_Client/Classes/Game/Cards/__pycache__/Card.cpython-312.pyc
Normal file
BIN
Game_Client/Classes/Game/Cards/__pycache__/Card.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user