CPCWiki forum

General Category => Programming => Topic started by: bluestar on 12:04, 14 October 23

Title: Improve keyboard reading in main loop (BASIC)
Post by: bluestar on 12:04, 14 October 23
Hi,
I'm developing a BASIC game with a player and enemies that appears in waves.

Enemies are stored into an array.

In each iteration of the main loop:
- Player character is printed in the screen
- Keyboard is reading in order to make a movement 
- The array of enemies is read and updated and enemie's are printed

In addition a timer is displayed and updated each second (interruption)

Characters are very simple (CHR$(143) squares). No background.

With 2-3 enemies player's movement goes fluidly but with more there is an important delay reading the keyboard.

I want to improve this in BASIC (I know). Any trick to improve keyboard reading? Maybe using interruptions?

Thanks in advance!!!
Title: Re: Improve keyboard reading in main loop (BASIC)
Post by: McArti0 on 13:35, 14 October 23
Maybe you need to use "clear input" when the time to draw enemies is too long.
Title: Re: Improve keyboard reading in main loop (BASIC)
Post by: andycadley on 14:26, 14 October 23
Probably worth posting your current code. The usual trick with BASIC is to avoid reading the keyboard too many times, i.e. assign the result of INKEY$ to a variable and do all comparisons against that. That avoids the keyboard feeling like you need to hold keys down too much.
Title: Re: Improve keyboard reading in main loop (BASIC)
Post by: bluestar on 22:55, 14 October 23
Thanks to all. I did some changes with great sucess:

1. Add an additional call to keyboard reading inside the array of enemies
2. Change my current subrutine wich uses INKEY and a loop to a simple one with INKEY$ and four conditions
3. Call INKEY$ just once, and do the comparisions againsts a variable

Of course as much enemies I got slower they go (gotta iterate the whole array for update each enemie's position), but player movement goes fine.

I'll show you the code for improvements as soon as I fix one thing with collisions.

Thanks!
Powered by SMFPacks Menu Editor Mod