Just wondering, about making 2D map using tiles.
Blitz3D Forums/Blitz3D Beginners Area/Just wondering, about making 2D map using tiles.
| ||
Well you know when you make levels with Blitz+, you do the read data thing when using tiles like, 0,1,22,15,1,1,1,1,0,0 0,0,0,1,1,21,11,22,0,0 If you make a very very very big level, doesnt it make your line very very very long? data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 isnt there a command like: data 0,0,0,0, + 0,0,0,0,0,0,0, ... Just wondering. :) |
| ||
datas are read in order so you can have multiple data line for the same datas data 1,2,3,4,5 is the same as data 1 data 2 data 3 data 4 data 5 or data 1,2 data 3,4 data 5 |
| ||
If your levels are getting to be huge, you might want to design a level editor so you don't have to type in all those data statements. |
| ||
dont know how to make a good lvl editor im still just a newb :) Hell since my virus i had to reformat i dont remember how to make the maps with the data >.< |
| ||
Eventually you'll use a map-editor, which saves a big bunch of mem. After that you load that map in BB in a bank (or a 2-dimensional array..), and there'll be no DATA commands at all. The simple map editor is made out of the following parts: - the map screen, where you can point 'n click to put a tile on a x/y coordinate - the tile-list, where you can pick a tile (or a macro) to draw with. Additionally you can add: - a data-layer on the map screen, to add triggers etc. - special walk/wall tiles (so that -for example- grass can act as a wall and vice versa) |
| ||
When Blitzcoder is back online, I highly recomend Krylar's tutorial on tilemaps, which can be found in the articles section over there. |
| ||
Sybixsus, Dont I know you from somewhere |
| ||
Hi Folks, Data is already plural; you don't need to add an 's'. Datum is the singular. Sorry ;0) Jes |
| ||
Hi Jes, P is already soggy. Very sorry, just having a little fun before I start a bit of coding. Actually, I never knew the little factoid. OW! I got a new wrinkle on my brain from learning something new. -DDT! |
| ||
or check out MAPPY, probably the best map editor + playback library you going to find. http://www.tilemap.co.uk/mappy.php Blitz Basic Play Back Library + it has examples, you can use that editor from above to make maps. http://www.tilemap.co.uk/zipfiles/mapbbr6.zip |
| ||
Kaisuo- To answer your original question, no... there is no native way to "compress" the DATA statements like you suggested. You need to put a number in the DATA statement for each tile. But- like was mentioned, you DON'T have to put all the DATA for each level on the same line. You can break the lines up to make them easier to handle, just keep the numbers in the same order. (As an aside, yes... you COULD write a routine to "compress" the data in the DATA statements, and then "uncompress" it when you READ the data, but it would be more trouble than it would be worth, and since it's not "native" to Blitz you'd have to write it yourself.) |
| ||
Sybixsus, Dont I know you from somewhere Do you? Neither your nick or your email address ring any bells. Where do you think you know me from? |
| ||
Mappy is really really really nice, but i cant understand mappybb.bb the source to read the files, and I dont wana use anything i dont understand fully in my little project :| |
| ||
I would highly suggest making your own map editor. It will help you a lot more. Mappy is awesome, don't get me wrong, but learning it on your own is much better. cb |
| ||
Kaisuo: If you want a little help getting started on your map editor, take a look here. This is my old editor (minus script inclusion) for 2D Shadow of Fear. It has a nice user interface (I think) but more importantly, should help you in designing your own. Full source and graphics supplied. |
| ||
Alternately use a .BMP file, just give each tiletype a colour, then your map is quite easy to edit. The only thing you need to know in order to load a .BMP file like a map is that the wideness of the map is stored as a SHORT on position 18, the height at position 22, and from position 54 and forwards the pixels are stored, 3 bytes make a pixel, where the first byte is blue, the second green, the third red. The first pixel is the lower left corner, and then the rest follows as horisontal lines. This code can be used to load a BMP file, up to 16777216 different tiles. ;this CANNOT be a function Themap=ReadFile("Mymap.bmp") SeekFile (Themap,18) xofmap=ReadShort(Themap) ReadShort(Themap) yofmap=ReadShort(Themap) SeekFile (Themap,54) Dim maparray(xofmap-1,yofmap-1) Thisworks=xofmap/4 Thisworks=xofmap-Thisworks*4 For Countervar1=0 To yofmap-1 For Countervar2=0 To xofmap-1 maparray(Countervar2,Countervar1)=ReadShort(Themap)+65536*ReadByte(Themap) Next For Countervar2=1 To Thisworks ReadByte(Themap) Next Next CloseFile(Themap) |
| ||
Even if you're only average with B+, then you can make an mapeditor with ampel functionality in a day.. |
| ||
Neo I cant access your file :( |
| ||
CS im not even average im sunk XD |
| ||
Then why do you try to do high-end things all the time? Why don't you build-up your skills easily and steady with small simple applications? It's only since half a year that I make sources between 500 and 4000 lines. For years and years the only things that I did was doing stupid small useless apps, like sine-plotters, simple menus, pictureloaders/scrollers etc. I don't know about the other coders here, but I can't imagine that they learnt coding a different way. It isn't B+ itself, once you get the grips on it -which should only take days- you can run all the way with it. |
| ||
Cause I have a super high IQ and this pisses me off that I'm having problems to grasp this stuff. |
| ||
Actually, I learnt most of my coding skills in Blitz by designing a map editor (which became a major kludge due to the extra features added to aid my learning). Anyway, back to the problem in hand. Kaisuo: The webserver seems to be having difficulties at the mo, as any new files uploaded seem to be protected. I am currently trying to resolve it. In the meantime, have a look at the code below. This uses 32x32 size tiles, loaded as an animation, stores map info in an array and displays it with offsets. Graphics 640, 480 SetBuffer BackBuffer() ; Width and height of map in TILES not pixels ; Remember, each tile is 32x32 pixel size Const max_width = 1024 Const max_height = 1024 ; The all important MAP setup Dim map(max_width, max_height) ; Replace these with your own graphics Global tiles = LoadAnimImage("bitmaps\tiles.bmp", 32, 32, 0, 1024) Global backdrop = LoadImage("bitmaps\mountains.bmp") LoadMap() Xoffset = 0 Yoffset = 0 Repeat ; The offset parameters allow you to scroll the screen DrawMap(Xoffset, Yoffset) Text 0, 0, "Scrolling map demo" ; Arrow keys scroll map If KeyDown(200) Yoffset = Yoffset - 4 If KeyDown(208) Yoffset = Yoffset + 4 If KeyDown(203) Xoffset = Xoffset - 4 If KeyDown(205) Xoffset = Xoffset + 4 If Xoffset < 0 Xoffset = 0 If Yoffset < 0 Yoffset = 0 If Xoffset > (32*(max_width-1)) Xoffset = (32*(max_width-1)) If Yoffset > (32*(max_height-1)) Yoffset = (32*(max_height-1)) Until KeyHit(1) ; Escape to exit Function DrawMap(Xoff, Yoff) startX = Floor(Xoff / 32) startY = Floor(Yoff / 32) endX = (GraphicsWidth() / 32) + startX endY = (GraphicsHeight() / 32) + startY For x = startX To endX For y = startY To endY ; Here we use the position in the array ; and the offset to calculate draw position Dx = (x * 32) - Xoff Dy = (y * 32) - Yoff ; And here we draw it. Map(x,y) refers to a ; frame of animation. DrawImage tiles, Dx, Dy, map(x,y) Next Next End Function |