-
Notifications
You must be signed in to change notification settings - Fork 1
/
Level.py
executable file
·118 lines (102 loc) · 4.88 KB
/
Level.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
# Python imports
import math
# Panda3D imports
from direct.gui.OnscreenImage import OnscreenImage
from pandac.PandaModules import Point3
# Project imports
from IStrawberry import *
from IFish import *
from IMilk import *
from ILetuce import *
from IRice import *
from IBanana import *
from ICereal import *
from ICheese import *
from IEgg import *
from ITomato import *
from CHamburger import *
from CCan import *
from CDonu import *
from CPotatoes import *
# Generic Level
class Level:
def __init__(self, background):
#-----------------------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------VARIABLE DECLARATION------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------------------
# Background
self.back = background
self.back[0].setX(34)
self.back[1].setX(146)
# Arrow
self.arrow = OnscreenImage(image="./tex/fletxa.png", pos = (1.1, 0, 0.60),hpr=None, scale = (0.20,0,0.20), color=None, parent=None, sort=5)
self.arrow.setTransparency(TransparencyAttrib.MAlpha)
self.arrow.hide()
self.arrowSound = base.loadSfx('./sound/fletxa.wav')
self.arrowSound.setVolume(.5)
# Items, enemies list
self.items = []
self.enemies = []
# Others
self.numMoveIt = 0
self.movingBackground = False
self.state = 0
self.win = None
#-----------------------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------LEVEL CONFIGURATION-------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------------------
# Start tasks
taskMgr.add(self.taskLevel, 'taskLevel')
#end __init__
#-----------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------FUNCTIONS----------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------------------
# It moves the background on screen.
def moveBackground(self,x,y):
if( math.fabs(self.numMoveIt-self.back[0].getX()) >= 30.0 ):
self.movingBackground = False
self.arrow.hide()
#end moveBackground
# It hides the level.
def hideLevel(self):
self.win.hide()
#end hideLevel
# It configures the level for a level transition.
def moveOn(self):
self.numMoveIt = 0
self.movingBackground = True
self.interval = self.back[0].posInterval(5.0, Point3(self.back[0].getX()-30,self.back[0].getY(),self.back[0].getZ()))
self.interval.start()
self.interval2 = self.back[1].posInterval(5.0, Point3(self.back[1].getX()-30,self.back[1].getY(),self.back[1].getZ()))
self.interval2.start()
self.numMoveIt = self.back[0].getX()
self.arrow.show()
self.arrowSound.play()
#end moveOn
# It removes all items from screen.
def removeItems(self):
while self.items != []:
for x in self.items:
x.model.setX(-100)
self.items.remove(x)
#end removeItems
# It removes all the items and enemies from screen.
def removeAll(self):
while self.items != []:
for x in self.items:
x.model.setX(-100)
self.items.remove(x)
while self.enemies != []:
for x in self.enemies:
x.model.setX(-100)
x.life = x.life - 1
self.enemies.remove(x)
#end removeAll
#-----------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------TASKS,THREADS------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------------------
# It manages the level on every scene.
def taskLevel(self, task):
return task.cont
#end taskLevel
#end class Level