Joystick Input

[ LiB ]

As you know, mice and keyboards are the most common input devices for games. However, there are many other devices that are used, just not as commonly. Game pads and joysticks are used for many flying and racing video games .

Blitz Basic provides support for joysticks, much like its support for keyboards and mice. However, I do not want to go over joysticks entirely, because the subject is large and rarely used. However, if you want to learn about joysticks, I have compiled a list (see Table 10.3) of the most useful functions, their parameters, and their return values.

Table 10.3. Joystick Functions

Function

Description

JoyType ([port])

This function tests to see if a joystick is currently connected to the given port. The function returns 0 if there is no joystick, 1 if the joystick is digital, and 2 if the joystick is analog.

JoyDown (button,[port])

This function returns 1 if the specified button is being held down.

JoyHit (button, [port])

This function returns the number of times the specified joystick button has been hit.

GetJoy ([port])

This function returns the number of the button that was pressed.

WaitJoy ([port])

This function stops the program's execution until a joystick button is pressed.

JoyX# ([port])

This function returns the x coordinate of the joystick. The return value can range from -1 (far left) to 1 (far right), with 0 being directly in the center.

JoyY# ([port])

This function returns the y coordinate of the joystick. The return value can range from -1 (far up) to 1 (far down), with 0 being directly in the center.

JoyZ# ([port])

This function returns the z axis of the joystick. Usually, the z axis is a button. The value can range from 0 to 1 (none to max).

JoyU# ([port])

Depending on the joystick, this function can be used to detect a slider, a throttle , or a button; this is referred to as the u axis. This function returns a value between -1 and 1.

JoyV# ([port])

Depending on the joystick, this function can be used to detect a slider, a throttle, or a button; this is referred to as the v axis. This function returns a value between -1 and 1.

FlushJoy

This function flushes all of the commands in the joystick's queue, much like FlushKeys() .


You probably noticed that only two parameters are used in all of the functions. The parameter [port] is used only when there is more than one joystick connected to the computer. A port is a number that refers to the place on your computer when the joystick is plugged in. Almost always, just leave [port] blank.

The parameter button refers to the buttons on your joystick. The first mouse button begins at 1, and the last button depends on the make of the controller. Usually, there are at least 3 buttons total.

You can call JoyX# (and also JoyY# , Z# , U# , and V# ) like this:

returnvalue = JoyX#()

Returnvalue will now contain a value between -1 and 1.

[ LiB ]


Game Programming for Teens
Game Programming for Teens
ISBN: 1598635182
EAN: 2147483647
Year: 2004
Pages: 94
Authors: Maneesh Sethi

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net