0

I want to make a game with cards, something like Heartstone, but a lot simplier (coz I am not pro programmer). This is just part of program

import pygame 
class Card:
def AdCard(self, AdCard):
    self.AdCard = AdCard
def HpCard(self, HpCard):
    self.HpCard = HpCard
def Picture(self, Picture):
    self.Picture = Picture
def Special(self, Special):
    if Special == "Heal":
        pass

pygame.init()
display = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)


swordsman = Card()
swordsman_picture = pygame.image.load("Swordsman.png").convert()
swordsman.Picture(swordsman_picture)
print(type(swordsman.Picture))

Now the problem is that it prints that type of Picture is class 'pygame.Surface' but I want for this picture to be sprite. How to do that. Tnx.

flebas
  • 99
  • 8
  • `Sprite` is a class which use `Surface` to keep image and `Rect` to keep positon and size. – furas Jan 07 '16 at 14:25

1 Answers1

0

Sprite is a class which use Surface to keep image and Rect to keep positon and size.

class Card(pygame.sprite.Sprite):

    def __init__(self, surface):
        pygame.sprite.Sprite.__init__(self)

        self.image = surface

        self.rect = self.image.get_rect() # size and position

# and then

one_card = Card(swordsman_picture)

(see Pygame documentation: pygame.sprite.Sprite )

or probably but I did't see this before

one_card = pygame.sprite.Sprite()
one_card.image = swordsman_picture
one_card.rect = one_card.image.get_rect() # size and position

BTW: Use "CamelCase" names only for classes names - to make code more readable - even StackOveflor editor treads Picture, AdCard, etc as class name and use blue color. For functions and variables use lower_case names.


This seems useless

def Picture(self, Picture):
    self.Picture = Picture

swordsman.Picture(swordsman_picture)

you can do the same in one line - and make it more readable.

swordsman.Picture = swordsman_picture
furas
  • 134,197
  • 12
  • 106
  • 148