Using the "IN" command for WASD game control

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
KayBee
Berk
Posts: 17
Joined: Thu May 31, 2018 2:14 pm

Using the "IN" command for WASD game control

Post by KayBee » Mon Jan 28, 2019 3:06 am

Hi Smart People,

I have typed in a spectrum game into FUSE, checked the listing a couple of times, and the game does not respond to keyboard input. This is the only time I have seen the "IN" command to be used for keyboard input. This is the line featuring the command .The Spectrum BASIC manual indicates that 64510 represents Q through T.

20 PRINT AT x,y,s$: LET x=x-(I
N 64510=253)+(IN 65278=251): LET
y=y-(IN 65022=254 AND y>1)+(IN
65022=251 AND y<20)

Has anyone a successful sample program, that works for sure, that they would share so I could debug this?

Thank you for your time.

KB
0 x

User avatar
djnzx48
Manic Miner
Posts: 556
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Using the "IN" command for WASD game control

Post by djnzx48 » Mon Jan 28, 2019 6:18 am

I think the line you have there is for WAXD controls - if you want WASD then you should change (IN 65278=251) to (IN 65022=253). You should also select "Issue 2 keyboard" in the options to get them to work. If you don't want to use IN then an easier way to do keyboard controls is to use INKEY$, for example:

20 PRINT AT x,y;s$: LET x=x-(INKEY$="w")+(INKEY$="s"): LET y=y-(INKEY$="a" AND y>1)+(INKEY$="d" AND y<20)
0 x

KayBee
Berk
Posts: 17
Joined: Thu May 31, 2018 2:14 pm

Re: Using the "IN" command for WASD game control

Post by KayBee » Mon Jan 28, 2019 2:16 pm

Fixed! Man, I never would have guessed that the issue was a preference setting, since I was using the emulated keyboard to type in the program. Excellent dj, thank you for taking the time to share your knowledge.

KB
0 x

User avatar
Einar Saukas
Manic Miner
Posts: 949
Joined: Wed Nov 15, 2017 2:48 pm

Re: Using the "IN" command for WASD game control

Post by Einar Saukas » Mon Jan 28, 2019 2:47 pm

The difference is, using "IN" can read multiple keys pressed simultaneously (unlike "INKEY$") so it's possible to move diagonally for instance.
0 x

User avatar
Morkin
Manic Miner
Posts: 633
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: Using the "IN" command for WASD game control

Post by Morkin » Mon Jan 28, 2019 7:03 pm

djnzx48 wrote:
Mon Jan 28, 2019 6:18 am
20 PRINT AT x,y;s$: LET x=x-(INKEY$="q")+(INKEY$="a"): LET y=y-(INKEY$="o" AND y>1)+(INKEY$="p" AND y<20)
FTFY. :D
1 x

User avatar
djnzx48
Manic Miner
Posts: 556
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Using the "IN" command for WASD game control

Post by djnzx48 » Mon Jan 28, 2019 11:16 pm

Einar Saukas wrote:
Mon Jan 28, 2019 2:47 pm
The difference is, using "IN" can read multiple keys pressed simultaneously (unlike "INKEY$") so it's possible to move diagonally for instance.
Not in this case since '=' is being used to check for keys and there are multiple keys from a single row. With a simple DEF FN to check the bits then it works:

1 DEF FN b(x)=(INT x)=(2*INT (x/2))
20 LET a=IN 65022: LET b=IN 64510: PRINT AT x,y;s$: LET x=x-FN b(a/2)+FN b(b/2): LET y=y-(FN b(a) AND y>1)+(FN b(a/4) AND y<20)

This should also work on both issue 2 and 3 keyboards.
0 x

hikoki
Manic Miner
Posts: 400
Joined: Thu Nov 16, 2017 10:54 am

Re: Using the "IN" command for WASD game control

Post by hikoki » Tue Jan 29, 2019 10:42 am

Use this @Dr beep's trick to forget about keyboard issues when reading IN
https://www.worldofspectrum.org/forums/ ... ent_683051
0 x

Post Reply