Qbasicnews.com

Full Version: Moving at same time?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a program with two paddles...
You push "z" and one goes down
You push "m" and the other goes down

But how do you make it so you can push both "z" and "m" at the same time and both paddles move at the same time?

Code:
CLS
SCREEN 13
y = 1
y2 = 11
y3 = 1
y4 = 11
DO

LINE (5, y)-(7, y2), , BF
LINE (105, y3)-(107, y4), , BF
GOSUB delay
LINE (5, y)-(7, y2), 0, BF
LINE (105, y3)-(107, y4), 0, BF

IF y2 >= 200 THEN
y2 = 200: y = 189
END IF
IF y <= 1 THEN
y = 1: y2 = 11
END IF
IF y4 >= 200 THEN
y3 = 200: y4 = 189
END IF
IF y3 <= 1 THEN
y3 = 1: y4 = 11
END IF

GOSUB adsb
LOOP

delay:
FOR delay% = 1 TO 7
FOR delay2% = 1 TO 32000: NEXT delay2%
NEXT delay%
RETURN

adsb:
SELECT CASE INKEY$
CASE "a"
y = y - 7: y2 = y2 - 7
CASE "z"
y = y + 7: y2 = y2 + 7
CASE "k"
y3 = y3 - 7: y4 = y4 - 7
CASE "m"
y3 = y3 + 7: y4 = y4 + 7
CASE "q"
END
CASE "p"
GOSUB Pause
END SELECT
RETURN

Pause:
DO
LOCATE 12, 15
c = c + 1
IF c = 15 THEN c = 0
COLOR c
PRINT "Pause"
SELECT CASE INKEY$
CASE "q"
COLOR 15
END
CASE "p"
LOCATE 12, 15: COLOR 0: PRINT "Pause": COLOR 15
RETURN
END SELECT
LOOP
RETURN

I know it's kind of messy and all but... can you not make comments... Please just tell me how to push the buttons at the same time and have the paddles move at the same time?[/quote]
You need a keyboard handler. The default one which is provided by MSDOS just doesn't support more than a key at the same time, so you have to replace it by yours. They are usually short assembly programs embedded in a nice SUB, just like Milo Sedlacek's. Make a google search for it, but I'm quite sure someone will come with a useful link or just a code post (I don't have it).

When you have it and find problems, feel free to ask us for some tips.
That doesn't really help... Sry
Look at ON KEY in QB help. I believe you can set up to 5 keys, and can both check to see if the key is initially pressed or help down. That may help you.

*peace*

Meg.
Wow that helped me, I don't know why I opened this thread up but it will become useful in my fighting game. Both the keyboard handler, and the ON KEY thing.
Custom keyboard handle = good. ON KEY = bad. Keep in mind that little comment, Kofman.
thank you
BIG words, NO code. :*)
So you want code?

http://forum.qbasicnews.com/viewtopic.ph...23&start=7

One of the best available, courtesy of the legend. 8)