PDA

View Full Version : assigning the mouse functionality to Keyboard events


jaffaaswami
10-06-2010, 06:42 AM
Hi all,

I am beginner to game development and 3D environment. Recently I have gone through some tutorials(world demos) in viz and found the "duck court" demo interesting. I want to make a change to the existing code. Instead of using a mouse to target the ducks, I want the keyboard arrow keys to take care of that..

The code for the mouse looks like this:

#Add a crosshair that is linked to the mouse
viz.link(viz.Mouse , viz.addTexQuad(viz.SCREEN,texture=viz.add('crossha ir.png')) )

How should I assign the same to keyboard arrow keys. So that the crosshair moves all around the screen. Thanks in advance. You all have a great day ahead.

Thank & Regards,
Swami

Jeff
10-07-2010, 05:56 PM
You could update the crosshair position when a key event occurs:
import viz
viz.go()

court = viz.add('court.ive')
target = viz.addTexQuad(viz.SCREEN,texture=viz.add('crossha ir.png'))
target.setPosition(0.5,0.5)

vizact.whilekeydown( viz.KEY_UP, target.setPosition, [0, vizact.elapsed(0.2),0], viz.REL_PARENT )
vizact.whilekeydown( viz.KEY_DOWN, target.setPosition, [0, vizact.elapsed(-0.2), 0], viz.REL_PARENT )
vizact.whilekeydown( viz.KEY_RIGHT, target.setPosition, [vizact.elapsed(0.2), 0, 0], viz.REL_PARENT )
vizact.whilekeydown( viz.KEY_LEFT, target.setPosition, [vizact.elapsed(-0.2), 0, 0], viz.REL_PARENT )

jaffaaswami
10-07-2010, 10:58 PM
Hey Jeff,

Thanks a lot for the suggestion. It works awesome... I really appreciate your help. Beginners like me need this type of encouragement for showing further interest in the field.
Thanks again.