Board index » delphi » A Maze Game

A Maze Game

Ok i hope someone here can answer my question here.  Im fairly new to Pascal
but not to programming, and im trying to make a maze game in Pascal.
Now, i can get keyboard inputs of the arrow keys (no problem there) but i
need to know how to draw a maze on the screen, one that is actually a maze
and not just a load of blocks.
Also another problem i encountered, is that if im gonna let the lil
character move around the screen in anyway i want, how do i print him on a
certain line?

I.E if i was writing this program in qbasic, i would simply use the locate
command to print the character where i wanted, and use the SCREEN(x,y)
function to test whether the character is moving into a block.

To solve this i really do need some help from someone.  Preferably with
extreme knowledge of PASCAL and QBASIC... If you are such a person please
get back to me ( i really could use the help).

Ok i hope this whole message made some sense.

RearChud37

Please Reply to:
RearChu...@hotmail.com

 

Re:A Maze Game


On Mon, 1 Oct 2001 23:44:14 +0100, Rear Chud sez:

Quote
>Also another problem i encountered, is that if im gonna let the lil
>character move around the screen in anyway i want, how do i print him on a
>certain line?
>I.E if i was writing this program in qbasic, i would simply use the locate
>command to print the character where i wanted, and use the SCREEN(x,y)
>function to test whether the character is moving into a block.

When I did that assignment back in the stone age (hint: Turbo Pascal
2.0 was new!) I split the screen up into a grid of squares which could
contain either a chunk of wall, the critter, the goal, or nothing.
Then I wrote a generic "plot" routine that would let me specify
coordinates in my own universe (e.g., 5 grid spaces up, 3 grid spaces
over) and translate that into actual screen pixels.  Then I could fill
in the surrounding pixels with wall, a circular target, or my critter
as needed (taking care to save the screen under the critter so I could
redraw it without him after he moved).

Say each grid is 10 pixels on each side; to plot an object at (x,y) =
(3,5) I would first calculate out the center of the grid square at
3*10,5*10.  Then I would use that spot as the center of a rectangle,
circle, whatever that had a diameter/width of 10 pixels, 5 on each
side of that center pixel.

Once you can easily translate from your own 20x20 (or however many
grid squares) universe to screen pixels, you can write everything else
in your own coordinate system.  I read in the maze data as an ASCII
grid ("*" for walls, "X" for the target, and I can't remember what for
the start position) and stored the whole mess in a 2-D array of byte.
Say I'm starting at (1,1) and my goal is at (9,13).  I just compared
current position (in my 20x20 grid) with walls, target position, etc.
and left a bit set on each grid location I had already visited.  When
maze[ critterX, critterY ] = target, it's over.  When maze[ critterX,
critterY ] = wall, change direction.  That's a whole lot easier than
messing with screen memory comparisons for collision.

Does that make sense?  I'm treading a fine line here between giving
away too much (so you don't think for yourself) and not explaining
clearly enough.

Peter B. Steiger
Cheyenne, WY
----
If you reply by email, send it to pbs at com dot
canada (or vice-versa).  All adverti{*word*224}ts will be
returned to your postmaster, eh!

Re:A Maze Game


You might need GOTO(X, Y) but other than that you just need to look at the
graphic unit under Units.

Other Threads