stabilized login, first successfull stream of cards accross clients
This commit is contained in:
@ -16,10 +16,11 @@ class Card(pygame.sprite.Sprite):
|
||||
__inputHandler: InputHandler
|
||||
__owner:Player
|
||||
__state:str
|
||||
__dragable:bool = True
|
||||
image:pygame.image
|
||||
rect:pygame.rect
|
||||
|
||||
def __init__(self, pos: pygame.Vector2, assetDir: str, inputHandler: InputHandler, owner: Player):
|
||||
def __init__(self, pos: pygame.Vector2, assetDir: str, inputHandler: InputHandler, owner: Player, dragable:bool=True):
|
||||
if assetDir == "":
|
||||
raise ValueError("Card: imagePath cannot be empty")
|
||||
|
||||
@ -49,9 +50,10 @@ class Card(pygame.sprite.Sprite):
|
||||
|
||||
def update(self):
|
||||
if self.__dragging:
|
||||
mouse_pos = self.__inputHandler.getMousePos()
|
||||
self.__pos = mouse_pos
|
||||
self.rect.center = self.__pos
|
||||
if self.__dragable:
|
||||
mouse_pos = self.__inputHandler.getMousePos()
|
||||
self.__pos = mouse_pos
|
||||
self.rect.center = self.__pos
|
||||
|
||||
def attacks(self):
|
||||
return self.__attacks
|
||||
@ -68,6 +70,9 @@ class Card(pygame.sprite.Sprite):
|
||||
def getDragging(self):
|
||||
return self.__dragging
|
||||
|
||||
def getDragable(self):
|
||||
return self.__dragable
|
||||
|
||||
def getOffset(self):
|
||||
return self.__offset
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -8,10 +8,10 @@ from Classes.System.Utils.Path import PathUtil
|
||||
|
||||
# send from the server to tell the player the game starts
|
||||
# gives the client its and the opponents stats (not cards!!)
|
||||
def GameStart(world: World, handCards:list, inputHandler:InputHandler, owner:Player, opponent:Player):
|
||||
def GameStart(world: World, handCards:list, inputHandler:InputHandler, owner:Player):
|
||||
index:int = 0
|
||||
world.setEnemy(opponent)
|
||||
|
||||
for card in handCards:
|
||||
world.AddToPlayerHand(Card(pygame.Vector2(500 + (index + 100), 1050), PathUtil.getAbsolutePathTo(f"Assets/Cards/{card}/"), inputHandler, owner))
|
||||
|
||||
#world.AddToPlayerHand(Card(pygame.Vector2(500 + (index * 100), 1050), PathUtil.getAbsolutePathTo(f"Assets/Cards/{card}/"), inputHandler, Player(1000, 0, "test"), dragable=True))
|
||||
world.spawnCard(PathUtil.getAbsolutePathTo(f"Assets/Cards/{card}"), pygame.Vector2(500 + (index * 100), 1050), inputHandler, world.getPlayer())
|
||||
index=index+1
|
@ -2,6 +2,7 @@ import pygame
|
||||
from Classes.Game.World import World
|
||||
from Classes.System.Components.InputHandler import InputHandler
|
||||
from Classes.Game.Cards.Card import Card
|
||||
from Classes.System.Utils.Path import PathUtil
|
||||
|
||||
# the event the client sends to the server when it places a card
|
||||
def PlaceCard(tcpClient, card:Card, player):
|
||||
@ -22,9 +23,10 @@ def PlaceCard(tcpClient, card:Card, player):
|
||||
tcpClient.send(payload)
|
||||
|
||||
# the event send from the server to display a card on the field
|
||||
def CardPlaced(world:World, card:int, type:str, owner:str, pos:pygame.Vector2, inputHandler:InputHandler):
|
||||
def CardPlaced(world:World, card:int, owner:str, pos:pygame.Vector2, inputHandler:InputHandler):
|
||||
# todo: make this work with all cardtypes
|
||||
world.spawnCard(f"Assets/Cards/{card}/", pos, inputHandler, owner)
|
||||
print("placing enemy card")
|
||||
world.spawnEnemyCard(PathUtil.getAbsolutePathTo(f"Assets/Cards/{card}"), pos, inputHandler, owner)
|
||||
|
||||
def MovedCard(world:World, card:int, type:str, owner:str, oldPos:pygame.Vector2, newPos:pygame.Vector2, inputHandler:InputHandler):
|
||||
pass
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -16,7 +16,7 @@ class World():
|
||||
__labels:list
|
||||
__cards:pygame.sprite.Group()
|
||||
__PlayerHandCards:pygame.sprite.Group()
|
||||
__screen:pygame.surface
|
||||
screen:pygame.surface
|
||||
__cardWidth:int = 150
|
||||
__cardHeight:int = 200
|
||||
__cardOffset:int = 400
|
||||
@ -57,10 +57,10 @@ class World():
|
||||
|
||||
# labeling
|
||||
self.__labels.append(Label("PlayerHP", self.__screen, "1000 / 1000", pHPPos))
|
||||
self.__labels.append(Label("PlayerName", self.__screen, "Player", pNamePos))
|
||||
self.__labels.append(Label("PlayerName", self.__screen, "Not Connected", pNamePos))
|
||||
self.__labels.append(Label("PlayerName", self.__screen, "0", pManaPos))
|
||||
self.__labels.append(Label("EnemyHP", self.__screen, "1000 / 1000", eHPPos))
|
||||
self.__labels.append(Label("EnemyName", self.__screen, "Enemy", eNamePos))
|
||||
self.__labels.append(Label("EnemyName", self.__screen, "Not Connected", eNamePos))
|
||||
|
||||
self.__boardFields.append(BoardField("EnemyDeck", "Enemy", "Deck", eDeckPos, PathUtil.getAbsolutePathTo("Assets/Cards/0/field.png"), "e-deck"))
|
||||
self.__boardFields.append(BoardField("EnemyGraveyard", "Enemy", "Grave", eGravePos, PathUtil.getAbsolutePathTo("Assets/Cards/0/field.png"), "e-grave"))
|
||||
@ -121,6 +121,15 @@ class World():
|
||||
self.__cards.add(card)
|
||||
return card
|
||||
|
||||
def spawnEnemyCard(self, asset:str, pos:pygame.Vector2, inputHandler:InputHandler, owner:str) -> Card:
|
||||
pos.y = (self.__cardHeight + 45)
|
||||
|
||||
card = Card(pos, asset, inputHandler, self.enemy, dragable=False)
|
||||
self.__cards.add(card)
|
||||
|
||||
print(f"new card collection {self.__cards}")
|
||||
return card
|
||||
|
||||
def spawnCards(self, cards:pygame.sprite.Group):
|
||||
for card in cards:
|
||||
self.__cards.add(card)
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user