-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCoin.py
53 lines (45 loc) · 1.76 KB
/
Coin.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
__author__ = 'Batchu Vishal'
import pygame
from OnBoard import OnBoard
from pygame import mixer
'''
This class defines all our coins.
Each coin will increase our score by an amount of 'value'
We animate each coin with 5 images
A coin inherits from the OnBoard class since we will use it as an inanimate object on our board.
'''
class Coin(OnBoard):
def __init__(self, raw_image, position):
super(Coin, self).__init__(raw_image, position)
self.__value = 5
self.__coinAnimState = 0 # Initialize animation state to 0
# Getters and Setters
def setValue(self, value):
self.__value = value
def getValue(self):
return self.__value
# Update the image of the coin
def updateImage(self, raw_image):
self.image = raw_image
self.image = pygame.transform.scale(self.image, (15, 15))
# Animate the coin
def animateCoin(self):
self.__coinAnimState = (self.__coinAnimState + 1) % 25
if self.__coinAnimState / 5 == 0:
self.updateImage(pygame.image.load('Assets/coin1.png'))
if self.__coinAnimState / 5 == 1:
self.updateImage(pygame.image.load('Assets/coin2.png'))
if self.__coinAnimState / 5 == 2:
self.updateImage(pygame.image.load('Assets/coin3.png'))
if self.__coinAnimState / 5 == 3:
self.updateImage(pygame.image.load('Assets/coin4.png'))
if self.__coinAnimState / 5 == 4:
self.updateImage(pygame.image.load('Assets/coin5.png'))
def collectCoin(self):
# Play coin sound when you collect a coin
mixer.init()
mixer.music.load('Assets/coin.wav')
mixer.music.set_volume(1)
pygame.mixer.music.play()
print "You have picked up a coin!"
return self.__value