View Single Post
  #4  
Old 02-20-2004, 03:24 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi Karthi,

Here's a script I just wrote that does what you want. It displays a question with two choices. Use the joystick pad to select an option. The selected option will be colored red. Use the trigger button to make your choice.
Code:
import viz
import sid

CHECK_JOYSTICK_MOVE = 0
CHECK_JOYSTICK_CLICK = 1

HIGHLIGHT_COLOR = [1,0,0]
NONHIGHLIGHT_COLOR = [1,1,1]

viz.go()

Question = viz.add(viz.TEXT3D,'Is Vizard Awesome?',viz.SCREEN)
Question.translate(0.5,0.8)
Question.alignment(viz.TEXT_CENTER_CENTER)

Choices = ['Yes','No']
TextList = []
for x in range(0,len(Choices)):
	text = viz.add(viz.TEXT3D,Choices[x],viz.SCREEN)
	text.translate(0.3,0.6-(0.1*x))
	if x == 0:
		text.color(HIGHLIGHT_COLOR)
	else:
		text.color(NONHIGHLIGHT_COLOR)
	TextList.append(text)

SelectedChoice = 0

def mytimer(num):
	global SelectedChoice
	if num == CHECK_JOYSTICK_MOVE:
		y = sid.get()[1]
		if y < -0.3:
			TextList[SelectedChoice].color(NONHIGHLIGHT_COLOR)
			SelectedChoice = (SelectedChoice + 1) % len(Choices)
			TextList[SelectedChoice].color(HIGHLIGHT_COLOR)
			viz.starttimer(CHECK_JOYSTICK_MOVE,0.5)
		elif y > 0.3:
			TextList[SelectedChoice].color(NONHIGHLIGHT_COLOR)
			SelectedChoice = (SelectedChoice - 1) % len(Choices)
			TextList[SelectedChoice].color(HIGHLIGHT_COLOR)
			viz.starttimer(CHECK_JOYSTICK_MOVE,0.5)
		else:
			viz.starttimer(CHECK_JOYSTICK_MOVE,0.01)
	elif num == CHECK_JOYSTICK_CLICK:
		if sid.buttons() & 1:
			if SelectedChoice == 0:
				print "You have good taste"
			else:
				print "I just plain don't like you"
			viz.starttimer(CHECK_JOYSTICK_CLICK,0.5)
		else:
			viz.starttimer(CHECK_JOYSTICK_CLICK,0.01)
	
viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(CHECK_JOYSTICK_MOVE,0.01)
viz.starttimer(CHECK_JOYSTICK_CLICK,0.01)
Reply With Quote