Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Improve keyboard reading in main loop (BASIC)

Started by bluestar, 12:04, 14 October 23

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


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!!!


Maybe you need to use "clear input" when the time to draw enemies is too long.
CPC 6128, Whole 6128 and Only 6128, with .....
NewPAL v3 for use all 128kB RAM by CRTC as VRAM
TYPICAL :) TV Funai 22FL532/10 with VGA-RGB-in.


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.


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.


Powered by SMFPacks Menu Editor Mod