I've been working on this tile engine for one of my games. Seeing as I couldn't find much help in the codebase on how to go about scripting one of these. They are so common you'd think our community would have a basic template sitting around, but I couldn't find one, so here's one for you all.
Features:
- tile width and height can be any size, 32 by 32, 128 by 64(the current settings), 16 by 16, should all work in theory.
- Runs entirely on external bmp files, allowing easy editing of new tiles.
- Level Format is String Array based, allowing other info to be stored on a "phantom row" of data. For example, the in game name of the Level file.
- Scrolls the tiles smoothly, using a simple offset based on pixel distance.
- Only draws/creates sprites that are actually in range of the screen, allowing nearly endless level sizes. If one screen of level tile sprites can be drawn, the whole level should work without the huge overhead of making the entire level at once.
- Get tile function, based on actual tile x,y instead of pixels, allows for easy editing/grabbing of tile data. Example: To change the second tile in the first row of the level, simply pass the numbers 1,2 instead of having to figure out where the actual sprite/physical location of the tile is.
- Comes with a really crappy programmer's editor as an example(it's actually the editor in progress for my game, but it's generic enough to be used for anything at the moment.)
- Won't draw the tile sprite if the data is out of range, preventing crashes from scrolling out of the level. (Instead, it'll just appear that there is a "void" outside of the level.)
Bugs:
- It has absolutely no safety against invalid tile ids or missing graphics, and will simply crash on you if you try funny stuff like that. (this is mostly due to my lack of programming skill in DBPro.)
- Setting tiles to odd dimensions does weird things to the engine, mostly crashes and math errors.
- Probably a ton that I haven't caught yet.
NOTES:
- This does NOT contain a sprite engine for badguys/characters/non tile based objects. I'm working on one now that will handle a seperate array and offset them based on the level's scrolling, but don't be expecting it anytime soon with my skill level. :p
Feel free to hack it to pieces, I'd love to see what someone more skilled in DBpro can do with it. Actually, I'd love to see the community toss together a tile engine script that we can all use as a base for most of our editors/games, but that's probably just wishful thinking since everyone likes to sell their engines. (not that I blame them, I'm sure the money is nice.)
I have no idea if this code will work in other versions of DB, as I'm a newb when it comes to that sort of thing. :p
Oh yeah, basic licensing stuff. Umm, all this mess was written by me, so you can credit/blame me for everything. Feel free to use this in commercial products(good luck...it'll need some work first.) or homemade freeware stuff. All I ask is you give credit to Gawain for the initial base of the tile engine, and maybe send me an email letting me know of your wonderful creation so I can be all like, ooh, and stuff.
Anyway, here you go. Attached in zip format, contains the whole project with engine and basic ugly, but functional, editor.
Controls for the editor:
Enter - Panic Scroll back to 0,0, case you get lost in space.
S - saves the file, type a name and hit enter.
L - loads a file. Make sure to enter a valid name, as it doesn't check if it exists. :o
T - Changes the tileset directory. Default is "Steel", an included alternate is "Test". Typeing Steel or Test will swap instantly between them. Beware of crashes if tilesets have different amounts of stuff.
Arrow Keys - scroll tiles around. Ooh. Ah. Pretty colors.
Right click - Change current tool ID(id of the tile you're drawing) Based on a delay that probably goes too fast on some computers, edit the control code delay to change it. Cycles to the max value(default 3) and then back to 0.
Left click - Draws stuff. More specifically, gets the tile based on the mouse position and current scroll values, and sets it to the value of Tool.
Esc - Quits the madness and returns to the sane world of reality.
I'm sure there's some features/bugs I've forgotten to list, but I can't remember them. :p I may fix things, I may not, can't promise anything as other issues are taking over my time at random. Enjoy, and let me know how it goes(or doesn't go, as the case may be).