Qbasicnews.com

Full Version: Using line commands for maze game
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there.
I am currently making a game that involves directing a car to pick up passengers in a maze in a time limit.

I made the maze using line commands and am not sure of how to manipulate my graphics data such that my car cannot pass through the lines. Can you guys please help me?
Smile You need to create a barrier code that matches your LINE codes..

Lets say you got LINEs going up 2 X cords 150 & 170 on SCREEN 13:

Code:
SCREEN 13
'x = 155 if the car is 10 pixels wide..
'it will center in the screen
y = 180: x = 155

DO
LINE (150, 0)-(150, 200), 10
LINE (170, 0)-(170, 200), 10
'## Main prog structure ##

'Barrier codes
IF y <= 150 THEN y = 150
'check for right side. Subtract 10
'to get the right barrier stop..
IF y => 160 THEN y = 160

Oh, when you set up a barrier, you need to look at, if you are useing PUT, the (x, y) on PUT is the top left corner.. so when you check for barriers, on the front and left side of the car, car's PUT (x, y) can check to the barrier's (x, y), but on the back and the right of the car,. barries (x,y) has to be subtracted by the car's pixal length or width to properly check.. :wink:

If you need more help, I'll be glad to clear it up any miss-understandings.. Smile
well actually, i don't have a clue on how im going to use your barrier code.
i have the maze and the data set for the sprite but i still don't have the code on how to manipulate the sprite using directional buttons. the entire code including the barriers.

what will i do?
Arrow key codes are easy.. here is how its done..

Code:
press$ = INKEY$
'Up Arrow
IF press$ = CHR$(0) + "H" THEN ...

'Down Arrow
IF press$ = CHR$(0) + "P" THEN ...

'Left Arrow
IF press$ = CHR$(0) + "K" THEN ...

'Right Arrow
IF press$ = CHR$(0) + "M" THEN ..

That should do it for ya,.. I get left and right messed up sometimes, so if you spite goes the wrong way, swap the M for the K.. :wink: But I think thats it. :roll:
I see. After the then, i'll put all the for next stuff for the data right? But what's the CHR$(0) for?
Quote:I see. After the then, i'll put all the for next stuff for the data right? But what's the CHR$(0) for?

QB recives special keys as \0*
If you are not the C type: All special keys first return a byte that holds nothing, a so called null-byte.
After that comes the key that is pressed.
I assume the intention was that special keys dont interfer with normal keys and are easily recognizable for programms.
Inkey$ returns a string that can have 0, 1 or 2 characters inside.

If the string returned has 0 characters, no key was pressed.

If the string returned has 1 character, it will be an ascii representation of the key pressed, i.e. if you press "A" you get character "A". This gets affected by SHIFT keys (LSHIFT, RSHIFT, ALT GR, etc.). Obviously, keys which don't translate to numbers, letters or symbols don't produce 1 character strings.

If the string returned has 2 characters, they will be CHR$(0) followed by the key scancode. For scancodes you can check the QB help. The scancode for cursor left is 75, for example, so if you want to use INKEY$ to detect if the user presses the left cursor you have to check if its value equals CHR$(0) + CHR$(75), or, what's the same: CHR$(0) + "K".
Ok. I made this code to contain my little 20x7 sprite within the confines of the (40,10)-(575,365) maze.

case chr$(0) + chr$(77) 'right
if x < 575 then
locate 20,20
'print " "
put (x,y), fire, xor
x=x+10
put (x,y), fire
else
locate 20,20
print "cant move right"
end if

how can i use this code for the coordinates of my maze?
for example, two columns on my maze is on (200,20)-(200,40) and (200, 60)-(200,100).
how will i integrate this such that my sprite can still pass through the empty space from 200,40 - 200, 60 while limiting passage through the two columns?

i tried doing "if x =200 and y < 20" but it blocks the entire sprite from passing through anything. i also tried "20 < y > 40" but that didn't work.

im sure this is easy, im actually seeing the flaw in my problem like i think, if im talking about columns, i should be looking at x instead of y but i can't quite see my mistake. im not good at converting images into numbers and languages. sorry if im a bit slow. please help.
well my deadline is tomorow so im hoping someone'll help my poor little ass real soon.
im pretty sure the maze program will be the longest so im gonna skip that first for the easier stuff.

i made a timer for 160 seconds with something like this
1
do
n = 160
for n = n -1
sleep 1
print n
next n
loop until n =0
if n = 0 then end sub
else
goto 1

the timer works but somehow, i can't get the "end sub" to work and halt the game when the timer stops. and the timer speeds up with the press if directional buttons.
also, the entire program dosn't work ever since i put the manipulation code after it.

i also don't have the passengers yet. how do i do them that 1) they disappear when you get to them and 2) when you get to them all within the required time, you win and your time is kept as your score?

thank you
END SUB has to be at the end of the sub, if you are ending the sub early you use EXIT SUB (i think)