JOYSTICK TEST PROGRAM for QBasic

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

User avatar
Kiyotewolf
Veteran
Posts: 96
Joined: Tue Apr 01, 2008 11:38 pm
Contact:

JOYSTICK TEST PROGRAM for QBasic

Postby Kiyotewolf » Thu Apr 07, 2011 6:29 am

[joystick]
# joysticktype -- Type of joystick to emulate: auto (default), none,
# 2axis (supports two joysticks,
# 4axis (supports one joystick, first joystick used),
# 4axis_2 (supports one joystick, second joystick used),
# fcs (Thrustmaster), ch (CH Flightstick).
# none disables joystick emulation.
# auto chooses emulation depending on real joystick(s).
# timed -- enable timed intervals for axis. (false is old style behaviour).
# autofire -- continuously fires as long as you keep the button pressed.
# swap34 -- swap the 3rd and the 4th axis. can be useful for certain joysticks
# buttonwrap -- enable button wrapping at the number of emulated buttons.

joysticktype=2axis
timed=true
autofire=false
swap34=false
buttonwrap=true


Code: Select all

DIM JoyX(8)
DIM JoyY(8)
DIM JoyOldX(2)
DIM JoyOldY(2)
DIM Bttn(7)

SCREEN 0
WIDTH 80, 50
COLOR 7, 0
CLS

JoyX(4) = 160
JoyY(4) = 100
JoyX(5) = 160
JoyY(5) = 100

DO
  COLOR 15, 7
  LOCATE 49, INT((80 - LEN("JOYSTICK TEST")) / 2)
  PRINT "JOYSTICK TEST";
 
  JoyX(0) = STICK(0)
  JoyY(0) = STICK(1)
  JoyX(1) = STICK(2)
  JoyY(1) = STICK(3)
  FOR z = 0 TO 7
    Bttn(z) = STRIG(z)
  NEXT z
  'range 1 to 200
  JoyX(2) = JoyX(0) - 100
  JoyY(2) = JoyY(0) - 100
  IF JoyX(2) <1> 200 THEN JoyX(2) = 200
  IF JoyY(2) <1> 200 THEN JoyY(2) = 200
  JoyX(3) = JoyX(1) - 100
  JoyY(3) = JoyY(1) - 100
  IF JoyX(3) <1> 200 THEN JoyX(3) = 200
  IF JoyY(3) <1> 200 THEN JoyY(3) = 200
'do our centering now.
'() JOYSTICK DEMO PROGRAM
'[] measure joysticks normally.
'[] use centering algo.
ScaleX = 40
ScaleY = 40



TempX = INT((JoyX(2) - 100) * (ScaleX / 100))
TempY = INT((JoyY(2) - 100) * (ScaleY / 100))
JoyX(4) = JoyX(4) + TempX
JoyY(4) = JoyY(4) + TempY

TempX = INT((JoyX(3) - 100) * (ScaleX / 100))
TempY = INT((JoyY(3) - 100) * (ScaleY / 100))
JoyX(5) = JoyX(5) + TempX
JoyY(5) = JoyY(5) + TempY

'JoyX(2), JoyY(2), JoyX(3), JoyY(3) = absolute coordinates
'JoyX(4), JoyY(4), JoyX(5), JoyY(5) = relative centering coordinates
 
  IF JoyX(4) <0> 320 THEN JoyX(4) = 320
  IF JoyY(4) <0> 200 THEN JoyY(4) = 200
 
  IF JoyX(5) <1> 320 THEN JoyX(5) = 320
  IF JoyY(5) <1> 200 THEN JoyY(5) = 200



'[] display graphics
'{} loop until done.
  LOCATE 5, 1
  FOR z = 0 TO 7
    IF Bttn(z) THEN
      COLOR 14, 8
        ELSE
      COLOR 0, 8
    END IF
    PRINT "#:"; LTRIM$(STR$(z)); " ";
  NEXT z
  LOCATE INT(JoyY(4) / 200 * 50) MOD 50 + 1, INT(JoyX(4) / 320 * 80) MOD 80 + 1
  COLOR 9, 0
  PRINT "*";
  LOCATE INT(JoyY(5) / 200 * 50) MOD 50 + 1, INT(JoyX(5) / 320 * 80) MOD 80 + 1
  COLOR 10, 0
  PRINT "*";
  LOCATE INT(JoyY(2) / 200 * 50) MOD 50 + 1, INT(JoyX(2) / 200 * 80) MOD 80 + 1
  COLOR 11, 0
  PRINT "*";
  LOCATE INT(JoyY(3) / 200 * 50) MOD 50 + 1, INT(JoyX(3) / 200 * 80) MOD 80 + 1
  COLOR 12, 0
  PRINT "*";

  n = n + 1
  n = n MOD 50
  IF n = 0 THEN CLS
  JoyOldX(0) = JoyX(2)
  JoyOldY(0) = JoyY(2)
  JoyOldX(1) = JoyX(3)
  JoyOldY(1) = JoyY(3)
  WHILE TIMER - t < .1: WEND
LOOP UNTIL INKEY$ = CHR$(27)

   



First part is what you need to add to your *.conf file in DOSBOX to handle USB joysticks.

Second, the source.



~Kiyote!

Let me know what you think.
Banana phone! We need more lemon pledge. * exploding fist of iced tea! * I see your psycho cat and counter with a duck that has a broken leg, in a cast.

Return to “QBASIC and QB64 Questions & Answers”

Who is online

Users browsing this forum: No registered users and 8 guests