Game Help

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
mEEKs
Newbie
Posts: 2
Joined: Sat Dec 16, 2006 2:19 pm
Location: In front of my computer

Game Help

Post by mEEKs »

Hello, I am programming a game in Qbasic and there are a few things I need help with. I would appreciate any help that could be given :)

I am programming a maze-like game where a character moves around an area with blocks. I want to be able to create a maze that randomly generates blocks. At the moment, I CAN make something like this:

XXXXXXXXXXX
X..................X
X.....XX.........X
X.....XXXX.....X
X....X....XX....X
X...XX.XX......X
X..................X
XXXXXXXXXXX

To do that I use this code:

CLS
RANDOMIZE TIMER
FOR i = 1 TO 1
FOR p = 1 TO 10
LOCATE i, p
PRINT "X"
NEXT
NEXT
FOR i = 1 TO 1
FOR p = 1 TO 10
LOCATE p, i
PRINT "X"
NEXT
NEXT
FOR i = 11 TO 11
FOR p = 1 TO 10
LOCATE i, p
PRINT "X"
NEXT
NEXT
FOR i = 11 TO 11
FOR p = 1 TO 11
LOCATE p, i
PRINT "X"
NEXT
NEXT
FOR i = 3 TO 9
FOR p = 3 TO 9
IF RND < .5 THEN
LOCATE i, p
PRINT " "
ELSE
LOCATE i, p
PRINT "D"
END IF
NEXT
NEXT

The problem is, I want to be able to read the maze using the MID$ command. To do that, the maze I created has to be saved to a string or array. As it is, the maze isn't saved in anything. I need to find a way to either take that maze up there and save it to a string or array, OR find a way to randomize a maze within an array or string already.

My next problem is how to make moveable blocks. I want blocks to move up, down, left and right depending on which way you push them. The only way I can think of that would make them do this would be:

LOCATE playerx, playery
IF playerx, playery = "D"
AND oldplayerx = (playerx-1)
AND (playerx+1), playery = " "
THEN LOCATE (playerx+1), playery
PRINT "D"
ELSE
playerx=(playerx-1)
END IF

That would check if the player collides with a block. It would then check which way he came from, and to check if there is anything in front of the block. If that is all true, then it will move the block forward one. I would then have to repeat that for every direction. Would that work, and if not, are there are other ways of doing this? Thanks for any help.
Nothing to say >_>
seaBiscuit$
Coder
Posts: 45
Joined: Sun Nov 26, 2006 2:00 pm
Location: Champaign, Illinois

Post by seaBiscuit$ »

You could create a maze like this:

Code: Select all

mazewidth = 11
mazeheight = 11
dim shared maze$
'fill the maze with spaces to start with
maze$ = string$(mazewidth * mazeheight, " ")
Then to write to it, instead of using locate y,x you could do something like this:

Code: Select all

index = ((y - 1) * mazewidth) + x
mid$(maze$, index, 1) = "D"
then use the same thing with the index to read from it at a certain x,y point.

I hope to see this game when it's done!
mEEKs
Newbie
Posts: 2
Joined: Sat Dec 16, 2006 2:19 pm
Location: In front of my computer

Post by mEEKs »

Thanks for the reply :) I'll try out what you showed me. I'm guessing that you would have to make either x or y a RND number to make it randomly generate the blocks? Or would it do it automatically? Anyways, thanks for the help, I didn't know that you could place characters using MID$, I thought it just read them. This will help out a lot.

I'll be sure to show you it when I finish!
Nothing to say >_>
Post Reply