
-----------------------------------
Nick
Mon Jan 28, 2008 7:56 pm

[tutorial] joysticks/joypads (finally)
-----------------------------------
Introduction

Hello welcome to my tutorial on using joysticks/joypads.  I personally have a joypad with 2 analog sticks, 12 buttons, and a D-PAD/POV which has been tested.  This tutorial will require two things: Firstly, you have atleast one joystick/joypad. 2)you grab my revised module at the bottom as the Turing default is not the best.  Now for some Q and A.

FAQS
q)So what do you plan to accomplish in this tutorial?

a)Well I'm planning to tackle the four main parts of the joystick module, breaking it down into parts, and ultimatly sharing this method of input with the world!

q)So what's so great about joysticks/joypads?

a)Well the mouse has upto 3 buttons and a cursor, a keyboard has keys, however a joypad (depending on the model) will have upto 32 buttons, upto 3 analog sticks, and a D-PAD/POV! that equals a ton more input and functionallity.

q)What if I don't have a joypad/joystick?

a)Not to worry just follow along and post/PM me with the questions (I'm sometimes busy so results not will be immediate).

Well now to get started!

Body

The body will contain of four main parts, Setup, Button input, Analog input, and D-PAD/POV input.  The tutorial will use an example program included at the bottom and will break down the code to show what exactly is happening (grab that now and the module too).

Setup

First things first, since the module is not pervasive it needs to be imported, also make sure the module is in the same folder as the program using it.

import joystick

Now that that is done varibles need to be initalized just as though mouse input or keyboard input were being used
.
type joypad : % create a joypad type
    record
        button : array 1 .. 32 of boolean %create 32 instances of buttons
        pos : joystick.PosRecord /*used to find all joypad intake with
         the exception of buttons*/
        caps : joystick.CapsRecord %used to find the max on joypad analog
    end record

var joy : array 1 .. 2 of joypad %create an array of joypad

What just happened?  Well now to break that down.

First an instance of the joypad type containing a set of varibles was created.  The first varible is an array of 32 boolean the number can be any number 1