-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardSprite.py
More file actions
79 lines (68 loc) · 2.62 KB
/
Copy pathCardSprite.py
File metadata and controls
79 lines (68 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pygame
from Card import Card
# A CardSprite has all attributes of a Card and is a pygame sprite
class CardSprite(Card):
# GIF FILE SIZE CONSTANTS
XOFFSET = 75
YOFFSET = 99
# FILE PATH CONSTANTS
FRONTOFCARDFILEPATH = 'DECK_OF_CARDS/'
BACKOFCARDFILEPATH = 'DECK_OF_CARDS/back02.gif'
GIF = '.gif'
# Constructs a CardSprite object with a suit and value as a pygame sprite
# @param value (string) the value value
# @param suit (string) the suit value
#
def __init__(self, value='', suit='', x=0, y=0, flip=True):
super().__init__(value, suit)
self._images = [CardSprite.FRONTOFCARDFILEPATH + Card.FILEVALUES[value] + Card.FILESUITS[suit] + CardSprite.GIF,
CardSprite.BACKOFCARDFILEPATH]
self._flipped = flip
if self._flipped:
self._cardImage = pygame.image.load(self._images[0])
else:
self._cardImage = pygame.image.load(self._images[1])
self._cardSprite = pygame.sprite.Sprite()
self._cardSprite.image = self._cardImage.convert()
self._rect = self._cardSprite.image.get_rect()
self._rect.x = x
self._rect.y = y
self._cardSprite.rect = self._rect
## Accessor (Getter)
# @return self._cardSprite (pygame Sprite) the card pygame sprite
#
def getCardSprite(self):
return self._cardSprite
## Accessor (Getter)
# @return self._rect (Rect) the x- and y- coordinates of the sprite
#
def getRect(self):
return self._rect
# Moves the CardSprite object by an offset of x and y
# @param x (float) the x-offset
# @param y (float) the y-offset
#
def move(self, x, y):
self._rect.x += x
self._rect.y += y
# Moves the CardSprite object to a fixed position
# @param x (float) the x-coordinate on the grid
# @param y (float) the y-coordinate on the grid
#
def setPosition(self, x, y):
self._rect.x = x
self._rect.y = y
# Flips the CardSprite object (changes image from front to back gif)
# @return new CardSprite that is flipped with the same value, suit, position, but a different image
#
def flipCard(self):
temp = self._flipped
if temp:
self._flipped = False
else:
self._flipped = True
return CardSprite(self.getValue(), self.getSuit(), self._rect.x, self._rect.y, self._flipped)
# Draws the CardSprite object to the screen
# @param screen (pygame Surface) the window where the content is being displayed
def draw(self, screen):
screen.blit(self._cardSprite.image, self._rect)