def MainTask(): """Top level task that controls the game""" # Display instructions and wait for key press to continue yield DisplayInstructionsTask() # Create panel to display trial results resultPanel = vizinfo.InfoPanel("", align=viz.ALIGN_CENTER, fontSize=25, icon=False, key=None) resultPanel.visible(False) viztask.waitDirector(getData) while True: num_trials += 1 # Randomly choose hiding spots from list locations = random.sample(HIDING_SPOTS, TRIAL_COUNT) # Reset score score = 0 UpdateScore(score) # Go through each position for pos in locations: # Perform a trial found = yield TrialTask(pos) # Update score and display status text if found: viz.playSound("sounds/pigeon_catch.wav") score += 1 total_score += 1 UpdateScore(score) tracker.runAction(vizact.spinTo(point=pos, time=0.8, interpolate=vizact.easeOutStrong)) resultPanel.setText(TRIAL_SUCCESS) else: viz.playSound("sounds/pigeon_fly.wav") viztask.schedule(FadeToGrayTask()) resultPanel.setText(TRIAL_FAIL) # Display success/failure message resultPanel.visible(True) # Add delay before starting next trial yield viztask.waitTime(TRIAL_DELAY) resultPanel.visible(False) # Disable gray effect gray_effect.setEnabled(False) viztask.waitDirector(writeScore, score) # Display results and ask to quit or play again resultPanel.setText(RESULTS.format(score, TRIAL_COUNT)) resultPanel.visible(True) yield viztask.waitKeyDown(" ") resultPanel.visible(False)
def CycleAlertsTask (self): self._cycler = None #the next item in the list to display (starts with last) fade_out = vizact.fadeTo(0, 1, time=0.5, interpolate=vizact.easeOutStrong) fade_in = vizact.fadeTo(1, 0, time=0.5, interpolate=vizact.easeOutStrong) #set all alerts on map to 100% opaque so that they don't stay semi-transparent for i in [a for m, a in self._alerts.iteritems() if m != 'info']: a.alpha(1) while True: data = yield viztask.waitDirector(self.GetNextMessage) nextKey = data.returnValue if nextKey == 'info': #not verified anymore because info not in _messages self._infoPanel.setText(self._messages[nextKey]) else: self.DisplayAlert(self._messages[nextKey]) if nextKey != 'info': alertObj = self._alerts[nextKey] yield viztask.addAction(alertObj, fade_out) yield viztask.addAction(alertObj, fade_in) yield viztask.addAction(alertObj, fade_out) yield viztask.addAction(alertObj, fade_in) yield viztask.addAction(alertObj, fade_out) yield viztask.addAction(alertObj, fade_in) yield viztask.addAction(alertObj, fade_out) yield viztask.addAction(alertObj, fade_in) else: yield viztask.waitTime(5)
def fileTask(): yield viztask.waitKeyDown(' ') viz.logNotice('Started file operation') #Execute the getLast function in a separate thread #and wait for it to complete and return some data data = yield viztask.waitDirector(getLast) viz.logNotice('Finished file operation, last line is: ',data.returnValue)
def TrialTask(pos): """Task for individual trial. Returns whether pigeon was found.""" #Reset tracker to origin tracker.setPosition([0,1.8,0]) tracker.setEuler([0,0,0]) # Flash screen FlashScreen() # Place pigeon at new location pigeon_root.setPosition(pos) pigeon_root.visible(True) hooting.play(loop=True) # Create proximity sensor for pigeon using main view as target manager = vizproximity.Manager() #manager.setDebug(True) manager.addTarget( vizproximity.Target(viz.MainView) ) sensor = vizproximity.Sensor(vizproximity.Sphere(PROXIMITY_RADIUS),pigeon_root) manager.addSensor(sensor) # Wait until pigeon is found or time runs out wait_time = viztask.waitTask( TrialCountDownTask() ) wait_find = vizproximity.waitEnter(sensor) data = yield viztask.waitAny([wait_time,wait_find]) # Hide pigeon and remove proximity sensor pigeon_root.visible(False) hooting.pause() manager.remove() # Return whether pigeon was found condition = data.condition is wait_find yield viztask.waitDirector(getData, condition) viztask.returnValue(condition)
def runtrials(): global trialtype, trialtype_signed, groundplane, radiiPool, out #yield viztask.waitTime(5.0) #allow me to get into the seat. setStage() # texture setting. #likely to have to be expanded. driver.reset() # initialization of driver [leftbends, rightbends] = BendMaker(radiiPool) viz.MainScene.visible(viz.ON, viz.WORLD) #add text to denote conditons. txtCondt = viz.addText("Condition", parent=viz.SCREEN) txtCondt.setPosition(.7, .2) txtCondt.fontSize(36) out = "" def updatePositionLabel(): global driver, trialtype_signed, trialtype ##WHAT DO I NEED TO SAVE? # get head position(x, y, z) pos = viz.get(viz.HEAD_POS) pos[1] = 0.0 # (x, 0, z) # get body orientation ori = viz.get(viz.BODY_ORI) steeringWheel = driver.getPos() #what data do we want? RoadVisibility Flag. SWA. Time, TrialType. x,z of that trial These can be reset in processing by subtracting the initial position and reorienting. SaveData(pos[0], pos[2], ori, steeringWheel) ##. vizact.ontimer((1.0 / 60.0), updatePositionLabel) for j in range(0, TotalN): #import vizjoy trialtype = abs(TRIALSEQ_signed[j]) trialtype_signed = TRIALSEQ_signed[j] txtDir = "" # Define a function that saves data def SaveData(pos_x, pos_z, ori, steer): global out #what data do we want? RoadVisibility Flag. SWA. Time, TrialType. x,z of that trial These can be reset in processing by subtracting the initial position and reorienting. if out != '-1': # Create the output string currTime = viz.tick() out = out + str(float( (currTime))) + '\t' + str(trialtype_signed) + '\t' + str( pos_x) + '\t' + str(pos_z) + '\t' + str( ori) + '\t' + str(steer) + '\t' + str( radius) + '\t' + str(occlusion) + '\t' + str( int(trialbend.getVisible())) + '\n' radiipick = 1 occlpick = 1 L = len(radiiPool) L2 = L * 2 print trialtype, L, L2 if trialtype > L and trialtype <= L2: print 'here' radiipick = trialtype - L #reset trialtype and occl index occlpick = 2 elif trialtype > L2: print 'here too' radiipick = trialtype - L2 occlpick = 3 print radiipick #pick correct object if trialtype_signed > 0: #right bend trialbend = rightbends[radiipick - 1] txtDir = "R" else: trialbend = leftbends[radiipick - 1] txtDir = "L" radius = radiiPool[radiipick - 1] occlusion = occlPool[occlpick - 1] if radius > 0: msg = "Radius: " + str(radius) + txtDir + '_' + str(occlusion) else: msg = "Radius: Straight" + txtDir + '_' + str(occlusion) txtCondt.message(msg) #translate bend to driver position. driverpos = viz.MainView.getPosition() print driverpos trialbend.setPosition(driverpos[0], 0, driverpos[2]) #now need to set orientation driverEuler = viz.MainView.getEuler() trialbend.setEuler(driverEuler, viz.ABS_GLOBAL) #will need to save initial vertex for line origin, and Euler. Is there a nifty way to save the relative position to the road? driver.setSWA_invisible() yield viztask.waitTime(occlusion) #wait an occlusion period trialbend.visible(1) yield viztask.waitTime( 2.5 - occlusion ) #after the occlusion add the road again. 2.5s to avoid ceiling effects. trialbend.visible(0) #driver.setSWA_visible() def checkCentred(): centred = False while not centred: x = driver.getPos() if abs(x) < .5: centred = True break # centred = False # while not centred: # x = driver.getPos() # print x ##wait a while print "waiting" yield viztask.waitDirector(checkCentred) print "waited" driver.setSWA_visible() yield viztask.waitTime(2) #wait for input . else: #print file after looped through all trials. fileproper = ('Pilot_CDM.dat') # Opens nominated file in write mode path = viz.getOption('viz.publish.path/') file = open(path + fileproper, 'w') file.write(out) # Makes sure the file data is really written to the harddrive file.flush() #print out file.close() #exit vizard viz.quit() ##otherwise keeps writting data onto last file untill ESC
def MainTask(): """Top level task that controls the game""" global won global manChase # Display instructions and wait for key press to continue yield DisplayInstructionsTask() yield manKicksBall() # Create panel to display trial results resultPanel = vizinfo.InfoPanel('',align=viz.ALIGN_CENTER,fontSize=25,icon=False,key=None) resultPanel.visible(False) resetManChase = False if manChase == True: resetManChase = True while True: # Randomly choose hiding spots from list locations = random.sample(HIDING_SPOTS,TRIAL_COUNT) # Reset score score = 0 UpdateScore(score) # Go through each position for pos in locations: # Perform a trial found = yield TrialTask(pos) # Update score and display status text if found: viz.playSound('sounds/pigeon_catch.wav') score += 1 UpdateScore(score) tracker.runAction(vizact.spinTo(point=pos,time=0.8,interpolate=vizact.easeOutStrong)) resultPanel.setText(TRIAL_SUCCESS) won = True data = yield viztask.waitDirector(writeData) else: viz.playSound('sounds/pigeon_fly.wav') viztask.schedule(FadeToGrayTask()) resultPanel.setText(TRIAL_FAIL) data = yield viztask.waitDirector(writeData) #allow for other animations for male2 while also ensuring #he chases the pigeon each round if resetManChase: manChase = True #Display success/failure message resultPanel.visible(True) # Add delay before starting next trial yield viztask.waitTime(TRIAL_DELAY) resultPanel.visible(False) # Disable gray effect gray_effect.setEnabled(False) #Display results and ask to quit or play again resultPanel.setText(RESULTS.format(score,TRIAL_COUNT)) resultPanel.visible(True) yield viztask.waitKeyDown(' ') resultPanel.visible(False)