qbasic hit collison

Started by
34 comments, last by Xerxes 19 years, 6 months ago
thx so much man i got it
Advertisement
No problem.
Aww, QBasic, the language I was programming in since I was six... I hope I can still remember after the years...

Try this, it's a simple line that you control with ASDW and that wraps around the screen, but it should give you the idea.

SCREEN 13CLSX = 160Y = 100DX = 0DY = 0DO PLAY "MFT255P63"  'Wait a while X = (X + DX + 320) MOD 320 Y = (Y + DY + 200) MOD 200 PSET (X, Y), 15 Key$ = INKEY$ SELECT CASE UCASE$(Key$) CASE "A"  DX = -1: DY = 0 CASE "D"  DX = 1: DY = 0 CASE "W"  DX = 0: DY = -1 CASE "S"  DX = 0: DY = 1 CASE CHR$(27)     'ESC key  EXIT DO END SELECTLOOP
EDIT: Corrected to work with Copy&Paste

[Edited by - Xerxes on October 8, 2004 2:44:12 PM]
Society's never gonna make any progress until we all learn to pretend to like each other.
any idea on how to get it so when i press w it keeps going up and doesnt stop till i press another key?
That's exactly what my example should do... if I'm right...
Society's never gonna make any progress until we all learn to pretend to like each other.
I just want to point out something about libraries in QB. First, QB 4.5 is the way to go for game/graphics libraries, which there are alot of because QB has a very strong game community. QB 7.1 isn't compatible with most libs that I've tried. QB 1.0 & 1.1, which is what came free with Dos/windows can not access libraries, and furthermore, only interprets: it doesn't produce a stand-alone EXE.
Theres also a QB 2 & 3 I believe, but I haven't used either.

If you have access to 4.5 I recomend the following libs:

DirectQB - A really nice, easy mode 13(320x200 256 color) games lib with additional support for sound effects and input.

Cosmox - An extended version of DirectQB, Its supposed to be faster in many instances, although I've never tried it.

FutureLib - A high-res high-color game lib with sound and input support.

DS4QB - The best option for sound in QB. It uses a 'slave' windows application to provide extensive sound support. It can play and mix music and sound effects including wave, mod, mp3 and others.

You should be able to find any of them on nearly any QB-site with downloads.

throw table_exception("(? ???)? ? ???");

Quote:Original post by PnP Bios
use a 3rd party support library. inkey$ is slow.


I'm sure it's fast enough for a snake program ... Sometimes we have to settle for "good enough" and get to the things that are truely important. Nobody cares if their snake program is using the most efficient method of polling the keyboard.
Quote:Original post by smr
Quote:Original post by PnP Bios
use a 3rd party support library. inkey$ is slow.


I'm sure it's fast enough for a snake program ... Sometimes we have to settle for "good enough" and get to the things that are truely important. Nobody cares if their snake program is using the most efficient method of polling the keyboard.

Only the anal-retentive, like me - but it seems like it would be fast enough for the OP's game, at least in it's current state. It would not be hard to convert it later if need be.
it moves really slow and if i can get itto move with onke key press it would be more easier then i can set a delay to make it faster or slower and xerxes ur example is sorto of complicated could u redo it so it looks more like mine??
u dont have to
the main reason it needs to move wit one key press is cause in 2 player both players cant move at once only one key can be pressed at a time so if one layer holds the key down when the other player preses a key player 1 would stop
this is my code as of right now

CLS
SCREEN 9
INPUT " press s to start"; s$
IF s$ = "s" THEN
END IF
CLS
LINE (20, 1)-(630, 330), 3, B
x = 50
y = 50
xl = 220
yl = 220
DO
c = 14
press$ = INKEY$
PSET (x, y), c
IF y > 1 THEN IF press$ = "w" THEN y = y - 1
IF y < 330 THEN IF press$ = "s" THEN y = y + 1
IF x > 20 THEN IF press$ = "a" THEN x = x - 1
IF x < 630 THEN IF press$ = "d" THEN x = x + 1
PSET (xl, yl), 9
IF yl > 1 THEN IF press$ = "p" THEN yl = yl - 1
IF yl < 330 THEN IF press$ = ";" THEN yl = yl + 1
IF xl > 20 THEN IF press$ = "l" THEN xl = xl - 1
IF xl < 630 THEN IF press$ = "'" THEN xl = xl + 1

COLOR 9
IF POINT(x, y) = 3 THEN : LOCATE 12, 32: PRINT " player 1 looses"
IF POINT(x, y) = 3 THEN : LOCATE 13, 32: INPUT "enter q to quit"; q$
IF POINT(x, y) = 9 THEN : LOCATE 12, 32: PRINT "player 1 looses"
IF POINT(x, y) = 9 THEN : LOCATE 13, 32: INPUT "enter q to quit"; q$
IF q$ = "q" THEN END
IF POINT(xl, yl) = 3 THEN : LOCATE 12, 32: PRINT "player 2 looses"
IF POINT(xl, yl) = 3 THEN : LOCATE 13, 32: INPUT "enter q to quit"; s$
IF POINT(xl, yl) = 14 THEN : LOCATE 12, 32: PRINT "player 2 looses"
IF POINT(xl, yl) = 14 THEN : LOCATE 13, 32: INPUT "enter q to quit"; s$

IF s$ = "q" THEN END
LOOP UNTIL press$ = CHR$(27)






This topic is closed to new replies.

Advertisement