Large (2D) levels
Blitz3D Forums/Blitz3D Programming/Large (2D) levels
| ||
So I've gotten a basic tile-based map working, with the help of FastImage. I wanted to put this question to you guys: How would you create a huge level map? (á la Sonic, or Kid Chameleon) I've thought of two possible methods (I'm leaning more towards the second): Create a large map Pro(s) - easiest method to implement. Cons - increasingly difficult to edit very large maps; potentially lots of wasted space (and memory) from blank tiles. Piece several same-sized maps using an array Pro(s) - relatively easy to implement; good for "room-based" scrolling (á la Zelda); easy to "lock" screen to a single map. Cons - trickier to edit maps; potentially same size maps only. |
| ||
First. |
| ||
I would suggest the second. It will make it much easier to add more rooms. It depends on the size of the game, though. For a very small game, use the first. For a larger game, use the second option. |
| ||
second. |
| ||
If its a scrolling map then first. if its flick screen with 100's of rooms then either is fine. |
| ||
The first for simplicities sake. All this data will be stored in the main RAM anyway, so size shouldn't be much of an issue. 10,000 x 10,000 = 358 MB odd and that's HUGE! If your RPG has rooms, you can easily use up the blank spaces by packing the rooms in correctly. If you like a good challenge, you could split each 32 bit int used for storing the image index of the tile image used for each array square, into 2 16 bit ints in code. This would half your memory requirements, and still give you 65535 different images to use for your tiles. |
| ||
Well, this is from an abandoned project. Please take the code "as is" There are a lot of interesting things there: 1. Map editor 2. Code to build huge maps with a minimum amount of memory needed 3. A* path finding algorithm The link is here: http://www.moraldigames.com/Temp/Map.zip and it will be available for a few days Enjoy! |
| ||
Headdy, Plan, plan, plan, then develop. Develop an editor which allows you to manage and edit smaller chunks of the overall bigger map. So you can add to the larger map at any time and edit any small section. In effect a clever version of two. Don't limit yourself to creating a basic map editor, think about what your game needs and work out a way to include these options in your editor, and how you will manage all that data. It will take a while but I bet you can develop a really brilliant fully funcitonal editor as long as you plan out ahead what you may like in your game. IPete2. |
| ||
DIM MAP[5000,5000] DIM ICON[255] this is what i whold use :D |
| ||
Dim ?????????? Create a bank and use that. I know it's basic, but a BANK will be much more interesting for a SAVE / LOAD, BACKUP, COPY / MOVE. |
| ||
A bank would be alot more memory efficient, but slightly harder to handle. Don't see it being much different for saving/loading... etc |
| ||
Well, say your tiles are based on a 256 char tileset (much like a font), when you write ints, you write 4 tiles at a time on to / from files. WriteInt( fileout, value% ) But there might be another way to dump a bank or memory zone to a file which is faster than this. EDIT: WriteBytes bnkTest,fileBank,0,50 |
| ||
TBH I would simply have the entire thing in a bank For example say your map is 12000 by 12000 thats 144,000,000 bytes of ram but it would be easier to access that than to have an array. For example 20,5 would be accessable via ( 5 * 12000 )+20 the 5*12000 as y is 5 and the map is 12000 wide, finally we add the X part that is 20 would give the location in the bank that we need to look at. |
| ||
but it would be easier to access that than to have an array How is that easier than accessing an array? would be accessable via ( 5 * 12000 )+20 the 5*12000 as y is 5 and the map is 12000 wide Or, if your using an array: map(20,5) |
| ||
If you want to use banks like arrays , do somthing like this. Example mybankarray=MakeBank(100,100) thisvalue=125 Putbank(10,5,100,thisvalue) newvalue=getbank(10,5,100) runtimeerror newvalue Function MakeBank(Xlen,Ylen) ;makes an integer/float bank with the 2 dimensions you specify Mybank=CreateBank((xlen*4)*(ylen*4)) Return Mybank End Function Function GetBank(Bank,Xindex,Yindex,AXlen) ;will return the value in the bank. Lets you use it ;like a 2 dimensional array though. AXLEN is the first ;arrays max length.. so in b=CREATEBANK(10,20) ;you would call Getbank(b,x,y,10) Return PeekInt(bank,((Yindex-1)*(AXlen*4)+((Xindex-1)*4)-1)) End Function Function PutBank(Bank,Xindex,Yindex,AXlen,VALUE) ;same as getbank but you insert a value PokeInt(bank,((Yindex-1)*(AXlen*4)+((Xindex-1)*4)-1),value) End Function Reminds me of back in the day of screen mode 13h(320x200 & 320x240), when you poked screen coords with (Yposition*ScreenWidth)+Xposition You could make this a type system and store the X length on creation, then you would not have to pass it each time, but I didnt bother. |
| ||
How is that easier than accessing an array? Sorry Ross C, I'm more used playing with banks. If you prefer using a dimension table for managing a 2D playfield, it's your choice really. |
| ||
Yeah, but it's not easier for a beginner :o) Plus array are probably not much slower than banks either. I use them for the ability to use bytes, instead of 32 bit ints. |
| ||
Thanks for the advice, everybody. * begins thinking about making a map editor... * |