for now removed card class from hirarchy and added possibillity to render sprites on screen

This commit is contained in:
steev 2023-12-07 22:39:34 +01:00
parent 0d89b1ce84
commit 8d7a67a454
20 changed files with 95 additions and 56 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

@ -1,14 +1,17 @@
{
"name": "testmonster",
"image":"Assets/Cards/testmonstercard/artwork.png",
"name": "Test Monster",
"image": "Assets/Cards/testmonstercard/cards.png",
"description": "can attack other monsters",
"costs": 30,
"defence": 40,
"defense": 40,
"attacks":[
{
"id":1,
"name":"test attack",
"damage":80
},
{
"id":2,
"name":"test attack",
"damage":80
}

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -0,0 +1,14 @@
import json
import pygame
class Card(pygame.sprite.Sprite):
def __init__(self, pos:tuple, assetDir:str):
if assetDir == "":
return ValueError.add_note("Card: imagePath cannot be empty")

View File

@ -0,0 +1,43 @@
import json
from typing import Any
import pygame
class MonsterCard(pygame.sprite.Sprite):
__attacks = []
__name:str
__description:str
image:pygame.image
rect:pygame.rect
def __init__(self, pos:tuple, assetDir:str):
if assetDir == "":
return ValueError.add_note("Card: imagePath cannot be empty")
pygame.sprite.Sprite.__init__(self)
data = json.load(open(assetDir + "/testmonstercard.json"))
self.__name = data["name"]
self.image = pygame.image.load(assetDir + "/card.png").convert_alpha()
self.rect = self.image.get_rect()
self.rect.center = pos
self.__description = data["description"]
for attack in data["attacks"]:
self.__attacks.append(attack)
def update(self):
pass
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

View File

@ -1,7 +1,5 @@
import json
from Game_Client.Classes.System.Objects.Cards.Card import Card
from Classes.Objects.Cards.Card import Card
class SpellCard(Card):
@ -10,8 +8,11 @@ class SpellCard(Card):
def __init__(self, asset:str):
data = json.load(open(asset))
super.__init__(data["name"], data["image"])
Card.__init__(data["name"], data["image"])
self.__description = data["description"]
def update(self):
pass
def getDescription(self):
return self.__description

View File

@ -1,6 +1,6 @@
from Game_Client.Classes.System.Objects.Cards.Card import Card
from Classes.Objects.Cards.Card import Card
import json
class SpellCard(Card):
@ -10,8 +10,11 @@ class SpellCard(Card):
data = json.load(open(asset))
super.__init__(data["name"], data["image"])
Card.__init__(data["name"], data["image"])
self.__description = data["description"]
def update(self):
pass
def getDescription(self):
return self.__description

View File

@ -1,6 +1,7 @@
import pygame
from pygame.locals import *
from Classes.Objects.Cards.MonsterCard import MonsterCard
from Classes.System.Window import Window
from Classes.System.InputHandler import InputHandler
@ -9,35 +10,41 @@ class App:
__window:Window
__running:bool = True
__player = pygame.Rect((300,250, 50,50))
# __player = pygame.Rect((300,250, 50,50))
__FPS = 60
__speed = 5
__clock = pygame.time.Clock()
def __init__(self, width:int=800, height:int=600, title:str="default title"):
def __init__(self, width:int=1280, height:int=720, title:str="default title"):
self.__window = Window(width=width, height=height, title=title)
self.startGameLoop()
self.onCleanup()
def startGameLoop(self):
# create sprite groups
cards = pygame.sprite.Group()
testMonsterCard = MonsterCard((500,500), "Assets/Cards/MonsterCards/testmonstercard/")
cards.add(testMonsterCard)
while self.__running:
self.__clock.tick(self.__FPS)
#temporary refresh
self.__window.getScreen().fill((0,0,0))
pygame.draw.rect(self.__window.getScreen(), (255,0,0), self.__player)
# update sprite groups
cards.update()
self.__player.move_ip((InputHandler.getInputAxis()[0]*self.__speed),(InputHandler.getInputAxis()[1]*self.__speed))
# draw groups
self.__window.drawSpriteGroup(cards)
# event handler
self.handleEvent(pygame.event.get())
# emits update to the game
pygame.display.update()
# handles incoming eventqueue
# handles incoming event queue
def handleEvent(self, events):
for event in events:
if event.type == pygame.QUIT:

View File

@ -1,22 +0,0 @@
import pygame
class Card:
__name:str
__artwork:pygame.image
def __init__(self, name:str, imagePath:str):
if name == "":
return ValueError.add_note("Card: name cannot be empty")
if imagePath == "":
return ValueError.add_note("Card: imagePath cannot be empty")
self.__name = name
self.__image = pygame.image.load(imagePath)
def getName(self) -> str:
return self.__name
def getArtwork(self) -> pygame.image:
return self.__image

View File

@ -1,14 +0,0 @@
import json
from Game_Client.Classes.System.Objects.Cards.Card import Card
class MonsterCard(Card):
__attacks:[]
def __init__(self, asset:str):
data = json.load(open(asset))
for attack in range(data["attacks"]):
self.__attacks.add(attack)
def attacks(self):
return self.__attacks

View File

@ -20,7 +20,6 @@ class Window:
# set framerate
def Render(self):
pass
@ -35,3 +34,8 @@ class Window:
def getScreen(self) -> pygame.surface:
return self.__screen
# draws a passed sprite group to the screen
def drawSpriteGroup(self, group:pygame.sprite.Group):
self.__screen.fill("grey100")
group.draw(self.__screen)