-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
213 lines (160 loc) · 5.05 KB
/
app.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
from operator import indexOf
import viz
import vizact
import vizcam
import vizinfo
import viztask
import vizproximity
import vizfx.postprocess
from vizfx.postprocess.color import GrayscaleEffect
from vizfx.postprocess.composite import BlendEffect
# from src.pick import *
from src.utils.randomiseTrash import get_random_trash
from src.utils.getBinFromIndex import bin_from_index
from src.apearance import set_appearance
from src.text import *
import math
import random
import datetime
import time
from src.constants import *
viz.setMultiSample(4)
viz.fov(80)
viz.go(viz.FULLSCREEN)
viz.collision(viz.ON)
player_picks = []
# Setup keyboard/mouse tracker
tracker = vizcam.addWalkNavigate(moveScale=2.0)
tracker.setPosition([0,1.8,0])
viz.link(tracker,viz.MainView)
viz.mouse.setVisible(True)
# Load piazza environment
piazza = viz.addChild('CityPark.osgb')
# viz.addChild('piazza_animations.osgb')
mylight = viz.addLight()
#Set the light parameters
mylight.position(0,10,0)
mylight.direction(0,0,90)
mylight.spread(180)
mylight.intensity(20)
mylight.spotexponent(2)
mylight.setPosition(0,10,0)
mylight2 = viz.addLight()
#Set the light parameters
mylight2.position(0,1000,0)
mylight2.direction(0,0,90)
mylight2.spread(180)
mylight2.intensity(20)
mylight2.spotexponent(2)
mylight2.setPosition(0,1000,0)
#fn for setting game appearance
(flash_quad, status_bar, time_text, score_text, gray_effect, inventory, resultPanel) = set_appearance()
# List of hiding spots for trash_pile
trash_pile = []
recicle_bins = []
glass_trash = []
plastic_trash = []
paper_trash = []
collected_trash = []
bin_object = {}
for i in range(13):
#Generate random values for position and orientation
x = random.randint(-2, 2)
z = random.randint(-5, 19)
yaw = random.randint(0,360)
#Load a trash
random_trash_peace = get_random_trash()
trash = viz.add(random_trash_peace)
trash.setPosition([x,0,z])
trash.setEuler([yaw,0,0])
trash.visible(False)
if random_trash_peace == "Bottle.osgb":
plastic_trash.append(trash)
elif random_trash_peace == "GlassBottle.osgb":
glass_trash.append(trash)
elif random_trash_peace == "CardboardBox.osgb":
paper_trash.append(trash)
trash_pile.append(trash)
for i in range(3):
xer = i + 1
x = xer * -2 - 2
z = 3
yaw = random.randint(0, 20)
bin_type = bin_from_index(i)
recycle_bin = viz.add(bin_type)
recycle_bin.setPosition([x,0,z])
recycle_bin.setEuler([yaw,0,0])
recycle_bin.visible(False)
if i == 0:
bin_object["glass"] = recycle_bin
elif i == 1:
bin_object["paper"] = recycle_bin
elif i == 2:
bin_object["plastic"] = recycle_bin
recicle_bins.append(recycle_bin)
def DisplayInstructionsTask():
panel = vizinfo.InfoPanel(INSTRUCTIONS,align=viz.ALIGN_CENTER,fontSize=22,icon=False,key=None)
trashClone = trash.clone(scale=[200]*3)
trashClone.addAction(vizact.spin(0,1,0,45))
trashClone.enable(viz.DEPTH_TEST,op=viz.OP_ROOT)
panel.addItem(trashClone,align=viz.ALIGN_CENTER)
yield viztask.waitKeyDown(' ')
panel.remove()
def removeObjects():
for trash in trash_pile:
trash.visible(False)
for recycle_bin in recicle_bins:
recycle_bin.visible(False)
def showResults():
if len(collected_trash) >= 13:
resultPanel.setText(RESULTS)
resultPanel.visible(True)
removeObjects()
def DisplayInventory():
if len(player_picks) < 1:
inventory.message("")
else:
item = player_picks[0]
item_type = ""
if item in plastic_trash:
item_type = "plastmasas"
elif item in glass_trash:
item_type = "stikla"
elif item in paper_trash:
item_type = "papīra"
inventory.message(PICKED_TRASH.format(item_type))
if len(collected_trash) >= 13:
showResults()
def dropTrash(object):
player_picks.pop()
collected_trash.append(object)
DisplayInventory()
def pickTrash():
object = viz.pick()
if object == viz.VizChild(5) or not object.valid():
return
if object in recicle_bins and len(player_picks) == 1:
glass_bin = bin_object['glass']
plastic_bin = bin_object['plastic']
paper_bin = bin_object['paper']
player_pic = player_picks[0]
if player_pic in glass_trash and object == glass_bin:
dropTrash(object)
elif player_pic in plastic_trash and object == plastic_bin:
dropTrash(object)
elif player_pic in paper_trash and object == paper_bin:
dropTrash(object)
elif object in trash_pile and len(player_picks) < 1:
player_picks.append(object)
object.visible(False)
DisplayInventory()
vizact.onmousedown(viz.MOUSEBUTTON_LEFT, func=pickTrash)
def MainTask():
# Display instructions and wait for key press to continue
yield DisplayInstructionsTask()
# Go through each position
for trash in trash_pile:
trash.visible(True)
for recycle_bin in recicle_bins:
recycle_bin.visible(True)
viztask.schedule( MainTask() )