-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathOnBoard.py
38 lines (30 loc) · 1.37 KB
/
OnBoard.py
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
__author__ = 'Batchu Vishal'
import pygame
'''
This class defines all inanimate objects that we need to display on our board.
Any object that is on the board and not a person, comes under this class (ex. Coins,Ladders,Walls etc)
Sets up the image and its position for all its child classes.
'''
class OnBoard(pygame.sprite.Sprite):
def __init__(self, raw_image, position):
super(OnBoard, self).__init__()
self.__position = position
self.image = raw_image
self.image = pygame.transform.scale(self.image,
(15, 15)) # Image and Rect required for the draw function on sprites
self.rect = self.image.get_rect()
self.rect.center = self.__position
# Getters and Setters
def setCenter(self, position):
self.rect.center = position
def getPosition(self):
return self.__position
def setPosition(self, position):
self.__position = position
# Update Image, this is an abstract method, needs to be implemented in the subclass with whatever size required
def updateImage(self, raw_image): # Abstract Method
raise NotImplementedError("Subclass must implement this")
# Modify the size of the image
def modifySize(self, raw_image, height, width):
self.image = raw_image
self.image = pygame.transform.scale(self.image, (width, height))