-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
198 lines (128 loc) · 4.46 KB
/
utils.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# Authors: ep0s TurBoss
# Models: ep0s TurBoss
# Just sandboxing
from time import *
from panda3d.core import TextNode
from direct.task import Task
from direct.gui.OnscreenImage import OnscreenImage
from direct.gui.OnscreenText import OnscreenText
"""
def drawGui(self):
# Load the pictures.
self.hp = OnscreenImage(image = 'hp.png',
pos = (-1.185, 0, -0.85),
scale = (0.15, 0.15, 0.15)
)
self.hp.setTransparency(TransparencyAttrib.MAlpha)
self.mana = OnscreenImage(image = 'mana.png',
pos = (1.185, 0, -0.85),
scale = (0.15, 0.15, 0.15)
)
self.mana.setTransparency(TransparencyAttrib.MAlpha)
"""
class Crono():
def __init__(self, app):
self.app = app
self.countRunning = False
self.count = 0
self.counttime = 0.5
self.countMax = 30
self.windowGui = self.app.loader.loadModel("models/window")
self.windowGui.setDepthTest(True)
self.windowGui.setDepthWrite(True)
def draw(self, x, y):
self.windowGui.setScale(0.06, 0.06, 0.06)
self.windowGui.setPos(x, 0, y)
self.windowGui.reparentTo(self.app.render2d)
clockStr = "00:00:%s" % self.countMax
self.clockMsg = OnscreenText(text=clockStr, style=1, fg=(1,1,1,1), pos=(x+0.1, y-0.01), align=TextNode.ALeft, scale = .05)
def task(self, Task):
#print strftime("%H:%M:%S", localtime())
horas = int(strftime("%H", localtime()))
minutos = int(strftime("%M", localtime()))
segundos = int(strftime("%S", localtime()))
sec = minutos*60
minute = horas*60
segundosTotales = segundos+sec+minute
#print segundosTotales
countStart = 0
if self.countRunning:
if ( (segundosTotales - self.count) > self.counttime ):
self.count = segundosTotales
self.countMax -= 1
if self.countMax >= 0:
clockStr = "00:00:%s" % self.countMax
self.clockMsg.setText(clockStr)
else:
self.countRunning = False
self.countMax = 30
return Task.cont
def start(self):
self.countRunning = True
print "countdown starts"
class CursorPos():
def __init__(self, app):
self.app = app
self.windowGui = self.app.loader.loadModel("models/window")
self.windowGui.setDepthTest(True)
self.windowGui.setDepthWrite(True)
def draw(self,x ,y):
self.windowGui.setScale(0.06, 0.06, 0.06)
self.windowGui.setPos(x, 0, y)
self.windowGui.reparentTo(self.app.render2d)
msg = ['']*2
self.coord = ['']*2
msg[0] = ("Mouse X: 0")
msg[1] = ("Mouse Y: 0")
self.coord[0] = OnscreenText(text=msg[0], style=1, fg=(1,1,1,1), pos=(x-0.2, y+0.01), align=TextNode.ALeft, scale = .05)
self.coord[1] = OnscreenText(text=msg[1], style=1, fg=(1,1,1,1), pos=(x-0.2, y-0.03), align=TextNode.ALeft, scale = .05)
def task(self, task):
x = 0
y = 0
if self.app.mouseWatcherNode.hasMouse():
mpos = self.app.mouseWatcherNode.getMouse()
x = mpos.getX()
y = mpos.getY()
msg = ['']*2
pos = ['']*2
msg[0] = ("Mouse X: %.2f" % x)
msg[1] = ("Mouse Y: %.2f" % y)
for i in range(len(msg)):
self.coord[i].setText(msg[i])
return Task.cont
class PlayerPos():
def __init__(self, app):
self.app = app
self.lastPos = 0
self.windowGui = self.app.loader.loadModel("models/window")
self.windowGui.setDepthTest(True)
self.windowGui.setDepthWrite(True)
self.posx = 0
self.posy = 0
self.posz = 0
def draw(self,x ,y):
self.windowGui.setScale(0.06, 0.06, 0.06)
self.windowGui.setPos(x, 0, y)
self.windowGui.reparentTo(self.app.render2d)
msg = ['']*3
self.coord = ['']*3
msg[0] = ("Player X: 0")
msg[1] = ("Player Y: 0")
msg[2] = ("Player Z: 0")
self.coord[0] = OnscreenText(text=msg[0], style=1, fg=(1,1,1,1), pos=(x-0.5, y+0.01), align=TextNode.ALeft, scale = .05)
self.coord[1] = OnscreenText(text=msg[1], style=1, fg=(1,1,1,1), pos=(x-0.5, y-0.03), align=TextNode.ALeft, scale = .05)
self.coord[2] = OnscreenText(text=msg[2], style=1, fg=(1,1,1,1), pos=(x-0.5, y-0.07), align=TextNode.ALeft, scale = .05)
def task(self, task):
pos = self.app.dt6.playerNP.getPos()
msg = ['']*3
if self.lastPos != pos:
self.posx = pos[0]
self.posy = pos[1]
self.posz = pos[2]
self.lastPos = pos
msg[0] = ("Player X: %.2f" % self.posx)
msg[1] = ("Player Y: %.2f" % self.posy)
msg[2] = ("Player Z: %.2f" % self.posz)
for i in range(len(msg)):
self.coord[i].setText(msg[i])
return Task.cont