Hello,
I'd like to make simple game, when an Object (starship, car, rocket etc.) is controlled by LEFT and RIGHT buttons. When you hold LEFT it strafe left, when you hold RIGHT, it strafe right, when you release buttons - it stops moving. Like any common shooter.
<------ /[]\ ------>
I tried something like this:
repeat;
drawimage(ship,x,0);
repaint;
delay(10);
key:=getkeypressed;
if (keyToAction(key)=GA_LEFT) then x:=x-10;
if (keyToAction(key)=GA_RIGHT) then x:=x+10;
until false;
It WORKS when I'm pressing ONE button only. But doesn't when I press both at same time. I'll try to explain this:
1. When I press (and hold) LEFT: CPU thinks i'm holding LEFT, and is doing his job.
[left]
<----/[]\
2. Then, when I press (and hold) RIGHT, while still holding LEFT pressed: CPU now thinks i'm holding RIGHT.
[left][right]
/[]\---->
3a. When I release RIGHT button, while still holding LEFT pressed: CPU thinks RIGHT has been released, so in his opinion
all buttons has been released and so he does nothing.
[left]
/[]\
3b. Also when I release LEFT button, while still holding RIGHT pressed: CPU thinks that all buttons has been released and so he does nothing.
[right]
/[]\
I hope i made myself clear
My questions:
1. How to fix it?
2. Does anybody could give me working "spacecraft movement" procedure, please?
Thanks