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
Drutt
Posts: 17
Joined: Thu May 31, 2018 3:14 pm

Using the "IN" command for WASD game control

Post by KayBee »

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
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

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

Post by djnzx48 »

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)
KayBee
Drutt
Posts: 17
Joined: Thu May 31, 2018 3:14 pm

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

Post by KayBee »

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
User avatar
Einar Saukas
Bugaboo
Posts: 3070
Joined: Wed Nov 15, 2017 2:48 pm

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

Post by Einar Saukas »

The difference is, using "IN" can read multiple keys pressed simultaneously (unlike "INKEY$") so it's possible to move diagonally for instance.
User avatar
Morkin
Bugaboo
Posts: 3250
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

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

Post by Morkin »

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
My Speccy site: thirdharmoniser.com
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

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

Post by djnzx48 »

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.
hikoki
Manic Miner
Posts: 576
Joined: Thu Nov 16, 2017 10:54 am

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

Post by hikoki »

Use this [mention]Dr beep[/mention]'s trick to forget about keyboard issues when reading IN
https://www.worldofspectrum.org/forums/ ... ent_683051
User avatar
IvanBasic
Drutt
Posts: 48
Joined: Mon May 13, 2019 1:24 pm

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

Post by IvanBasic »

About the issue of "no-press" values of 255 or 191, depending on emulators, I wrote this solution in WoS thread, and I believe it can help here as well:

Dealing with 191 or 255 "no key press" values, since the bit 7 depends on EAR, I used OUT 254,255 inside a program (the exercise of IN for key rows in the User's Manual) and the result is that it puts all values (the 8 rows) up to 255, when the normal value in my computer and my emulator is always 191.

It returns to 191 if the program stops (with message in the bottom row), or if Border is changed during the program (OUT 254 and BORDER are mutually connected).

So, if in a program OUT 254 is set to 255, and there are no border changes, values of 255 can be assured, so the solutions of checking both values simultaneously (255 OR 191), or LET K=IN 63486-C, I guess are not needed, because it is set to 255 in all rows, simplifying the IN key checking.

If the program needs a differnet border color (OUT 254,255 set border to white), other value for OUT will work, by example, for setting BORDER 0, OUT 254,248 will do it, 249 for blue, 250 for red, and so son.

I am going to test it in deep in my next game, meanwhile comments to this solution I brought are welcome.
User avatar
IvanBasic
Drutt
Posts: 48
Joined: Mon May 13, 2019 1:24 pm

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

Post by IvanBasic »

Sorry, I meant bit 6 (value 64) when refering to EAR.

By the way, using BEEP in the program restores this bit 6 to zero, so for checking the IN values refered to 255, include OUT 254, 247 just before reading IN. I did it and it works.
User avatar
MatGubbins
Dynamite Dan
Posts: 1237
Joined: Mon Nov 13, 2017 11:45 am
Location: Kent, UK

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

Post by MatGubbins »

When using WASD key layout on a Spectrum +/128/+2/+3 keyboard, the player will sometimes relax their thumb onto the cursor keys below the X key.
Pressing D and the right cursor key will activate the X key.
Post Reply