News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Reading joystick..how to?

Started by IndyUK, Yesterday at 19:40

Previous topic - Next topic

0 Members and 8 Guests are viewing this topic.

IndyUK

Hi folks,

Hope you're all doing well. I was hoping that someone could help me with programming the joystick in BASIC, in particular combo button presses. I'm not sure whether it's the PS4 controller that's the issue but, the 2 fire buttons don't don't appear to have any repeat. If I press either one, then left/right responses stop. Basically what I'm trying to achieve is left/right + jump combo. Using keys is absolutely fine but I'd like to have the joystick/joypad as an alternative input method.

I've got the typical game loop as below.

while 1
 IF INKEY(71)=0 THEN....Left
 IF INKEY(63)=0 THEN....Right
 IF INKEY(30)=0 THEN....Jump
wend

Of course a combo of left/right + jump makes the player jump in the respective direction. The following is what I've tried but not working as expected. Left/Right are fine but diagonal jumping doesn't work.

IF INKEY(71)=0 or joy(0)=4
 IF INKEY(63)=0 or joy(0)=8
 IF INKEY(30)=0 or joy(0)=32

As I mentioned earlier, the only difference is that neither fire button are repeating when held down.
I'd be grateful for any help.

Thanks




eto

JOY(0) returns a bit set of the joystick directions. (see e.g. here http://magic-cookie.co.uk/CPC/joy.html)

if you compare the result of JOY to 4 it will only be true if you move the joystick to the left, but it won't be true if the joystick is diagonal or if a button is also pressed. 

left+button would be 4+32 => JOY(0)=36

As this would give you a myriad of combinations you have to check for the actual bit being set instead. This can be done with AND

IF JOY(0) AND 4 THEN ... left
IF JOY(0) AND 32 THEN ... jump 


eto

Alternatively you can also use INKEY to test the directions and buttons of the joystick(s).

INKEY(74) will be left, INKEY(75) will be right.

Check the CPC 6128 manual for full details. (chapter 7, p 23)

ZorrO

Your first program is fine, just change numbers of keys.
Numbers keys for INKEY() as joystick are: 
F1 76, ^ 72, F2 77. 
< 74,  v 73,  > 75.
CPC+PSX 4ever

IndyUK

Quote from: eto on Yesterday at 20:16Alternatively you can also use INKEY to test the directions and buttons of the joystick(s).

INKEY(74) will be left, INKEY(75) will be right.

Check the CPC 6128 manual for full details. (chapter 7, p 23)
@eto

You my friend are a life saver. I used the INKEY(74), INKEY(75) & INKEY(76) and it worked like a charm. Many thanks for your prompt response.

Powered by SMFPacks Menu Editor Mod