Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Level Maps

Status
Not open for further replies.

RedOktober

Programmer
Jul 16, 2001
2
US
Hey,
How can I create a map of a level so that I can use it to scroll through a level when the man moves? Thanks.
 
This is a very vague question. Answering it directly, how you create the level is up to you, and the guidelines are dictated by the way that your game works. What I think you really mean, however, is how can you STORE that map (in memory). Arrays would be the tool of choice for this. Imagine a regular variable as a single mailslot on a wall full of them. Empirically speaking, it can hold one "value" at a time. Now imagine a grid of these mailslots, all under the same variable name. It can hold as many values as there are slots. You select which slot by using the column & row numbers, starting at (1,1) for the upper-left corner of the grid. This is what an array variable is. The following code demonstrates putting the times table from 1 to 10 into an array and then displaying it on the screen:
[tt]
DIM timesTable%(1 TO 10, 1 TO 10)
' First, calculate the times table, storing the results in the array:
FOR i% = 1 TO 10
FOR j% = 1 TO 10
array%(i%, j%) = i% * j%
NEXT j%
NEXT i%
' Then, output the times table from the array:
FOR i% = 1 TO 10
FOR j% = 1 TO 10
PRINT USING "### "; array%(i%, j%);
NEXT j%
PRINT ' Move to the start of the next line
NEXT i%[/tt]

If you have more questions about arrays, feel free to post them.
 
Yeah, you dimension something like intRow and intCol into an array like aContents(intRow, intCol). My question is how do you move the map when the man moves.
 
The most common way to do this is to store an upperleft set of coordinates. When you move the player, you change the value of these coordinates, and whenever you draw the map, you start at the top-left of the screen, but at the specified coordinate (instead of the absolute top-left) of the map.
 
Use text maps
EX:
y$=
XXXXXXXXXXXX
X0000000000X
X00000X0000X
X00000X0000X
X0000000000X
XXXXXXXXXXXX
and use MID$ to find the letter and use SELECT CASE to take action
 
@RedOktober
You don't move the map, you change the start-of-reading point within the map. Something like this :

'-- MAP(?,?) is the stored Map-data
'-- Guess what MapWidth & MapHeight are :)
'-- Where do I draw my map on the screen ?
BoxX=3:BoxY=2
'-- What's the width & height of the drawn map
BoxW=15:BoxH=15
'-- What's the Top-left of my map's viewpoint ?
MapX=7:MapY=5
'-- Show a portion of BoxW+1 * BoxH+1 of the map
for Y=0 to BoxH
for X=0 to BoxW
if MapX+X<0 or MapX+X>MapWidth or _
MapY+Y<0 or MapY+Y>MapHeight then
Code={Outside-of-map symbol})
else
Code=Map(MapXOffs+X,MapYOffs+Y)
endif
locate BoxY+Y,BoxX+X
Print chr$(Code);
next X
next Y

Change MapX and/or MapY and you will see other portions of your map appear. Draw a few lines outlining the box, and it will look quite nice too.

 
Heh... looks like my non-monospaced font format:

A
9
11
000000000000010000000101000000101000000101000001000100001000100011111110010000010100000001100000001

That list of numbers is all one big string. By doing my font this way, I could easly load the entire thing into a few array variables:

Do
Input #Filenum, CurChr$
CurChr = asc(CurChr$)
Input #Filenum, Temp$
FontX(CurChr) = Temp$
Input #Filenum, Temp$
FontY(CurChr) = Temp$
Input #Filenum, Temp$
Font(CurChr) = Temp$
Loop until EOF(Filenum)

I make three arrays with 255 indexes. This way the font file can even be out of order and still work because I use the ASC value as the array index.
 
Letter A:

000000000
000010000
000101000
000101000
000101000
001000100
001000100
011111110
010000010
100000001
100000001
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top