-
Notifications
You must be signed in to change notification settings - Fork 1
/
Application.py
executable file
·130 lines (109 loc) · 5.74 KB
/
Application.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
# Panda3D imports
import direct.directbase.DirectStart
from direct.showbase import DirectObject
from direct.showbase.DirectObject import DirectObject
from direct.gui.OnscreenImage import OnscreenImage
# Crayon3d imports
from Crayon3DScene import *
from wiimote_handler import *
from Crayon3DGesture import *
# Project imports
from Game import *
from Menu import *
from Tutorial import *
# It manages the initial menu of the game
class Application (DirectObject):
def __init__(self):
#-----------------------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------VARIABLE DECLARATION------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------------------
self.menu = None
self.game = None
self.ins = None
self.creditsActivated = False
#-----------------------------------------------------------------------------------------------------------------------------------------------
#--------------------------------------------------------------APPLICATION INIT-----------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------------------
# Window configuration
props = WindowProperties( )
props.setTitle( 'Glooveth' )
props.setIconFilename("./icon.ico")
base.win.requestProperties( props )
# World configuration
base.disableMouse()
self.accept("escape", self.quit)
# Background
self.background = Image()
self.back = []
self.back.append(self.background.loadModel("./models/Background.egg", "./tex/back.png", 34, 0, 60 , 56))
self.back.append(self.background.loadModel("./models/Background.egg", "./tex/back2.png", 146, 0, 60 , 56))
#Init Crayon3D
self.wmHandler = WiimoteHandler()
if(not self.wmHandler.start([WIIMOTE_TRACKER, WIIMOTE_BUTTON])):
self.wmHandler = None
self.cursor = Cursor(['tex/alpha_cursor.png'], self.wmHandler, 0)
#Cursor init
self.pointer = Pointer()
#Events declaration
self.accept("WM_BUTTON_RELEASED", self.handleBtnRelease)
#Tasks
taskMgr.add(self.taskCursor, 'taskCursor')
self.menu = Menu(self.cursor)
#end __init__
#-----------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------FUNCTIONS----------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------------------
# WiiMote button released handler
def handleBtnRelease(self, btn, dev, index):
if(index == 1):
if(btn == wiiuse.BUTTON_A):
self.selection()
#end handleBtnRelease
# It manages the selection on the menu
def selection(self):
if( self.menu.selected == "CREDITS" ):
# Credits
if( self.creditsActivated == False ):
self.menu.hide()
self.creditsImage = OnscreenImage(image="./tex/credits.png", pos = (0, 0, 0),hpr=None, scale = (1.33,1.0,1.0), color=None, parent=None, sort=3)
self.creditsImage.setTransparency(TransparencyAttrib.MAlpha)
self.creditsActivated = True
else:
self.creditsImage.hide()
self.menu.show()
self.creditsActivated = False
if( self.menu.selected == "PLAY" ):
# Game
self.menu.hide()
self.game = Game(self.back, self.cursor, self.pointer)
self.menu.selected = "HIDE"
if( self.menu.selected == "INS" ):
# Tutorial
self.ins = Tutorial(self.back, self.cursor, self.pointer)
self.menu.hide()
self.menu.selected = "HIDE"
#end selection
# It prepares the application to be closed and quit the game
def quit(self):
# Stop the wiimote handler
if(self.wmHandler):
self.wmHandler.stop()
print "Bye-bye!"
sys.exit()
#end quit
#-----------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------TASKS,THREADS------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------------------
# It moves the sun pointer according to the mouse or glove.
def taskCursor(self, task):
# It sets the sun pointer in Crayon3D cursor coordinates
mpos = self.cursor.getCursorPos()
if( self.game != None ):
self.pointer.setPosX(mpos.getX()+self.game.distXPointDraw)
self.pointer.setPosY(mpos.getY()+self.game.distYPointDraw)
else:
self.pointer.setPosX(mpos.getX())
self.pointer.setPosY(mpos.getY())
return task.cont
#end taskCursor
#end class Application