/
BAbility.py
executable file
·143 lines (125 loc) · 5.93 KB
/
BAbility.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Panda3D imports
from direct.gui.OnscreenImage import OnscreenImage
from pandac.PandaModules import TransparencyAttrib
# Project imports
from Bar import *
# Ability bar, it manages the amount of power of the specific ability
class BAbility (Bar):
def __init__(self, power):
Bar.__init__(self)
#-----------------------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------VARIABLE DECLARATION------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------------------
self.amount = 0
self.power = []
#-----------------------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------BAR INIT------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------------------
if power == "GRAIN":
self.path = "./tex/ability_cereal_bar.png"
self.path2 = "./tex/rice.png"
self.path3 = "./tex/ability_cereal_amount.png"
self.posX = -1.20
self.posY = -0.85
if power == "FRUIT":
self.path = "./tex/ability_fruit_bar.png"
self.path2 = "./tex/straw.png"
self.path3 = "./tex/ability_fruit_amount.png"
self.posX = -1.08
self.posY = -0.85
if power == "MILK":
self.path = "./tex/ability_milk_bar.png"
self.path2 = "./tex/milk.png"
self.path3 = "./tex/ability_milk_amount.png"
self.posX = -0.96
self.posY = -0.85
if power == "VEGETABLE":
self.path = "./tex/ability_vegetable_bar.png"
self.path2 = "./tex/letuce.png"
self.path3 = "./tex/ability_vegetable_amount.png"
self.posX = -0.84
self.posY = -0.85
if power == "FISH":
self.path = "./tex/ability_fish_bar.png"
self.path2 = "./tex/fish.png"
self.path3 = "./tex/ability_fish_amount.png"
self.posX = -0.72
self.posY = -0.85
# Initial sprite bar
self.bar = OnscreenImage(image=self.path, pos = (self.posX, 0, self.posY),hpr=None, scale = (0.05,1.0,0.035), color=None, parent=None, sort=1)
self.bar.setTransparency(TransparencyAttrib.MAlpha)
# Shape ability bar
self.item = OnscreenImage(image=self.path2, pos = (self.posX, 0, -0.90),hpr=None, scale = 0.06, color=None, parent=None, sort=2)
self.item.setTransparency(TransparencyAttrib.MAlpha)
# It prepares sprites amount bar
i=0
while i<5:
self.power.append(OnscreenImage(image=self.path3, pos = (self.posX, 0, self.posY+((i+1)*0.055)),hpr=None, scale = (0.05,1.0,0.025), color=None, parent=None, sort=1))
self.power[i].setTransparency(TransparencyAttrib.MAlpha)
self.power[i].hide()
i=i+1
#end __init__
#-----------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------FUNCTIONS----------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------------------
# It increases the amount of the bar
def itemCollected(self,amnt):
if self.amount > 4: self.amount = 5
else:
self.power[self.amount].show()
self.amount = self.amount + amnt
#end itemCollected
# It decreases the amount of the bar
def powerUsed(self,amnt):
self.amount = self.amount - 1
self.power[self.amount].hide();
#end powerUsed
# It makes empty the bar
def setEmpty(self):
while self.amount > 0:
self.amount = self.amount - 1
self.power[self.amount].hide()
#end setEmpty
# It makes disappear the bar
def hide(self):
self.bar.hide()
self.item.hide()
i=0
while i<5:
self.power[i].hide()
i=i+1
#end hide
# It makes that sprite have an intermitent alpha effect for 2 seconds
def taskGlowing(self, task):
if task.time > 2:
self.bar.show()
self.item.show()
i=0
while i<self.amount:
self.power[i].show()
i=i+1
self.isVisible = True
self.lastTime = 0.0
return task.done
else:
if (task.time - self.lastTime) > 0.15:
self.lastTime = task.time
if self.isVisible == True:
self.bar.hide()
self.item.hide()
i=0
while i<self.amount:
self.power[i].hide()
i=i+1
self.isVisible = False
else:
self.bar.show()
self.item.show()
i=0
while i<self.amount:
self.power[i].show()
i=i+1
self.isVisible = True
return task.cont
#end taskInvincible
#end class BAbility