[CODE] Tilemap generation based on images

Posted By: Helghast

[CODE] Tilemap generation based on images - 12/05/12 16:20

Hi Guys,

I came across this code I had once written, figured someone might wanna make use of it. (tested and works with A7 and A8)

It's very crude, it reads all images from a folder, and based on that creates blocks (per pixel) that are colored with the image's pixel color. To make any use of it, you'd have to spawn certain tiles based on the RGB values (commented in there too), but it's a start.

It stores all the images in an array too, you can load "levels" that way. by default it loads the first image in the array (and will probably crash if there is none, but hey, I told you it was rough code!).

Hope someone finds use of it, if I come across more stuff I'll upload it for you all to enjoy laugh

Download link: TileCreationImageBased.rar

regards,
Posted By: 3run

Re: [CODE] Tilemap generation based on images - 12/05/12 16:42

Nice, thanks for sharing man! laugh
Posted By: 3run

Re: [CODE] Tilemap generation based on images - 12/16/12 13:03

Helghast@ I wanted to know, have you worked on something that could save tiles on image, and load them back if needed? I would try to create a simple tile editor laugh
Posted By: Helghast

Re: [CODE] Tilemap generation based on images - 12/17/12 11:14

Turned out this was rather easy!

I have re-uploaded the source (same link as before), it contains 2 new functions.
One generates a random level, and the other stores that to an array.

Check my comments for more info laugh

regards,
(PS: loading images was ofcourse already available, but wrapped in a quick function, you'll have to write your own pieces of code based on this to expand it)
Posted By: 3run

Re: [CODE] Tilemap generation based on images - 12/17/12 11:29

Thank you man! laugh This is very useful!
Posted By: Helghast

Re: [CODE] Tilemap generation based on images - 12/17/12 13:48

I found an issue, where the BMAP that is being saved, is not compatible to be loaded again. I will investigate, and if needed file a bug-report.

Once I've got it fixed, I'll upload the new files again laugh

regards,
Posted By: Helghast

Re: [CODE] Tilemap generation based on images - 12/17/12 15:54

Same link again,

I expanded the code slightly, changed saving (and loading) of BMP files to PNG files (as I was having issues reading the directX BMP format).

You can save and load from a dialog file.

Hope this helps you!
regards,
Posted By: 3run

Re: [CODE] Tilemap generation based on images - 12/17/12 15:58

Thank you for your time man!
Posted By: 3run

Re: [CODE] Tilemap generation based on images - 03/18/13 08:30

Helghast@ I've noticed something strange (or maybe I just don't get it). In the example, I create random map (100x30) and save in into .png.. And I can see on the screen, that there are 3000 entities. But when I load it back, it creates only 2875? Why that happens?
Posted By: Helghast

Re: [CODE] Tilemap generation based on images - 03/19/13 08:41

very good question, haven't noticed that yet. Lemme take a look, I'll get back to you on this laugh
Posted By: Helghast

Re: [CODE] Tilemap generation based on images - 03/19/13 08:46

oh, that was easy, found it already tongue

in the function:
Code:
void load_bmap_load(STRING* levelname)


look for these 2 variables:
Code:
var level_width = bmap_width(level)-1;
var level_height = bmap_height(level)-1;



remove both the -1 from it, so it becomes:
Code:
var level_width = bmap_width(level);
var level_height = bmap_height(level);



And it works again then laugh

Sorry about that!
regards, D.
© 2024 lite-C Forums