Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / i cannot get two things to move at once!

Author
Message
Feugsy
20
Years of Service
User Offline
Joined: 1st Nov 2004
Location: Australia
Posted: 3rd Nov 2004 17:25
if i use the following code i cannot get two things to move at once!!! its frustrating!!! this program is in a loop
do
if inkey$()="w" then x = x+1
if inkey$()="s" then y = y+1
position object 1,x,1,1
position object 2,y,5,5
loop
this is in basic what i am putting in. could someone please help me move two things at once without one stopping!

cheers
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Nov 2004 21:10
The problem is that you using inkey$() - which is really only for basic keyboard interfacing, like a little menu or something like that. For a game, your better using the keystate() command to check the status of a key, or alternatively the cursor keys are nice and neat.

E.g... Cursor Keys
do
if upkey()=1 then x = x+1
if downkey()=1 then y = y+1
position object 1,x,1,1
position object 2,y,5,5
loop

Keystate will let you check the status of any keyboard button, however you must first find out the keys ID number. Personally I have a picture of a keyboard (like maybe an old keyboard box or something) - and in red I have the id numbers for each key - this saves tons of time, it's worth doing.

This bit of code would tell you the ID number of the key your pressing:

SYNC ON
DO
CLS
TEXT 0,0,str$(scancode())
SYNC
LOOP

Now say you pressed W and the code said 33 for the ID number (it's not 33, I don't have DBPro handy, at work). You could check the state of key 33 (W) using:

IF KEYSTATE(33)=1 then x = x+1

It is quite easy to use, just a bit of a pain to figure out the ID numbers.


Van-B


It's c**p being the only coder in the village.
Feugsy
20
Years of Service
User Offline
Joined: 1st Nov 2004
Location: Australia
Posted: 4th Nov 2004 17:58
thanx you are a ledgend!!!!!!!!!!!!!!

i really appreciate it

cheers

Login to post a reply

Server time is: 2024-11-27 15:36:03
Your offset time is: 2024-11-27 15:36:03