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 / Movement keys

Author
Message
Ashir
18
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Caracas, Venezuela
Posted: 19th Sep 2007 22:39
Hi again guys, I decided to make a pong remake (yeah, another one) to practice. I made the table, the pads and the ball, but I stoped when I try to move the pads.

What I need to do is push a button to launch the ball, but I want to choose the direction of the ball to shoot, so if I press left and the shoot button the ball goes left and if I press right and the shoot button the ball goes rigth. Simple.

I was reading Beguinner's guide to DarkBasic game programming and I thought that inkey$() was the perfect command to make the ball launch. The problem is that the W key used to move left in my pong game has to be pressed until the ball is shoot, and that only happends when press the shoot button (space key). The inkey$() can scan a key to know it's state, up, down or pressed (equal to key code, not equal to key code and equal to and then not equal to key code), so I think "if I use inkey$() to know if the W key is being pressed and then I press the space key, the ball should be launch to the left, or the right if I use the S key instead of the W".

i thought it was a good theory... in the practice it doesn't work. So, can you guys help me a bit with the ball launch and the keys used to?.
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 20th Sep 2007 00:00
As far as I know, inkey$ only works on one key at a time, a better way is to use the keystate() command. All you need to know for this is the number of a key (do a search on the forum for images that show this), and use it like

if keystate(keyno)=1

This works on multiple keys, and is suitable for what you're trying to do.

Login to post a reply

Server time is: 2024-11-25 11:48:09
Your offset time is: 2024-11-25 11:48:09