Page 1 of 1

Using the "IN" command for WASD game control

Posted: Mon Jan 28, 2019 3:06 am
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

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

Posted: Mon Jan 28, 2019 6:18 am
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)

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

Posted: Mon Jan 28, 2019 2:16 pm
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

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

Posted: Mon Jan 28, 2019 2:47 pm
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.

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

Posted: Mon Jan 28, 2019 7:03 pm
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

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

Posted: Mon Jan 28, 2019 11:16 pm
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.

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

Posted: Tue Jan 29, 2019 10:42 am
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

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

Posted: Tue Feb 25, 2020 9:52 pm
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.

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

Posted: Tue Feb 25, 2020 11:18 pm
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.

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

Posted: Wed Feb 26, 2020 12:36 pm
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.