Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Making a map editor

Author
Message
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 3rd Feb 2013 11:30 Edited at: 5th Feb 2013 20:38
Well not so much of a map editor or creator but i want to create something that will allow me to create a grid of data over a picture.

Basically i want to draw a huge picture of a top down map in something like gimp, then texture a plane with it. Then i want the editor to break the picture up into squares (possibly 8x8 pxls) to overlay a grid onto the picture. From here i want to "Paint" numbers in each of the grid squares to represent data that will be fed into an array (using DATA and READ) after it is saved into a text file. So grid (or tile) 0,0 may be numbered 0 for impassable AND unbuildable terrain because its water.

So i draw a map like this (bare with me folks i am not a graphics man )



Then texture a plane of the correct size in my "editor" and it produces a grid.



Then i can select a number 0 for buildable (you can build on it) passable (you can walk on it) or 1 for passable but not buildable or 2 for cant build or walk on it. Then paint those numbers in the grid on the map.



Once you were satisfied it saves the information in a text file with DATA at the beginning of each "Row" and you can simply copy paste that info into your code and populate an array with that info.

Sorry if this makes little sense as to what im trying to achieve im not very good at explaining myself nor do i know the best way to do things.
Kezzla
15
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 5th Feb 2013 01:02
Hi Somarl, I have been working on this very idea myself lately.

The way that I approach it is to use very distinct and different colors for your various zones I save the image as a bmp(no data loss through compression). I then load the image into my program and through an x-y for loop check the pixel color(you could also save the data to txt file in this loop). if the color matches my zone color then my array value is set to the desired flag and the value is written to you text file.

at the end of it all, the 2d array who's size matches the resolution of the image holds all the data to populate the map which would be used somewhat like...
repeat
position object rnd(mapsize),groundheight,rnd(mapsize)
until array address corresponding to map position = desired flag

you could also take the angle of making a separate array to hold zones of specific types to cut down on repeats via the previous example, you would just randomize the zonetotal number and select an array address then place object using relevant co-ordinates.

I have been using this to designate forest zones on my map and it is working quite well, as my project grows in complexity I will be adding more zones in to the images, and there is no reason you cannot use more than one image to hold data(initially or ongoing.)

Hope this was helpful.

I'm not a complete idiot -- Some parts are just missing.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Feb 2013 09:13
This is an interesting way of doing it i agree. But i think i would like more control via the option of "painting" the numbers just in case whatever was drawn was perhaps too complex to accurately work out what was what. I know this would take longer but perhaps a mix would work. Auto first then you look over the map and paint in what numbers might be out of place. Mind you I have no idea how to do this

How would you write it to a text file with DATA at the beginning of every line.
Im thinking a for loop which says for every row write whatever number is in the array after putting the string "DATA" first but i dont know.
Also im not 100% sure how to feed the numbers into the array when painting them. I think i have a rough idea but its too rough to code. Any ideas?
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 5th Feb 2013 09:47
If you use a two-dimensional array to store the data, whenever the user clicks the mouse, you can just divide the mousex and mousey coordinates by the width and height of your grid squares, respectively (8 pixels in your case). This will give you the indices in your data array where the value should be written.

Your idea for how to write the data to data statements is exactly right. You will probably also need to write the number of tiles wide and tall the grid is overall, since you can't tell this from a one-dimensional stream of numbers (which is what data is).

Life advice: be sure to try to divide your problem into small steps you can code up separately. If you try to tackle a large project all at once, it's hard to see what you're doing and to find help. For example, for this project you need to: store the data somewhere, take user input to change the data, display the data on the screen, and save out the data on a certain key press.

I'm not sure how much DB experience you have, let us know if you need more details on any of this.

http://brianmacintosh.com
"'Who's that primitive entity accessing sliding collision data from my bridge?!', the troll roared." - TheComet
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Feb 2013 12:06
Thanks BMacZero. As for my programming skills they are almost none existant. And beyond DBpro they are totally none existant.
So far i have been trying to break up my problems into small chunks as i know i cant create a decent project yet. This is what i have been doing for a while now and its a nice way to do it i agree.

I was thinking of making the array know how big it should be by counting the picture size (that the plane will be textured with) then using those x and y co-ordinates to
1) Create a plane of that size
2) Texture it
3) Make an array by dividing the numbers by 8 (as long as i make a picture divisable by 8 pixels this should be ok)
4) Draw lines over it to represent that grid pysically to the user.

Then a small user interface on the left will have a button for each number 0, 1, and 2 (possibly more)which i can do.

It can paste a 0 automatically into everything to start with and that will match what the array has but i just cant think how to go over it with new numbers AND populate that array with the number of the button i clicked. I want it to be able to "paint" rather than single click each box i want to change, so i can be presise and do just one box at a time with one click or just paint round the map doing a large bit by whizzing the mouse all over the place (with possibly a right click to return to previous value if you make a mistake).

Then im a bit stuck on the exporting it as a text file in perfect copy paste format ready to be dropped into code.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 5th Feb 2013 19:47
Have you checked out any tutorials? There's a nice thread of them here. There are a few general introduction to DBP ones at the bottom of the list. They will really help get you up to speed on programming concepts.

As far as your specific questions, I wrote up some pseudocode you might use for the number painting part of the program:

See if you can fill in the missing parts I've commented on.

I couldn't find a good file i/o tutorial quickly, so I wrote some code that should save out the array for you - read the comments, hopefully they will help you understand how it's all working.


I didn't run any of this code, so apologies if there are errors.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Feb 2013 20:37
Thanks very much for this, i am going to have a good play with it, and add it all into a mini learning project i am currently doing.
I have seen all of tdk's tutorials, daniels video ones too and i have the books plus ive read a lot of stuf in the codebase. I have a reasonable understanding of all things 'blue' in the code so to speak, what i lack is algorithms for working out things i want to get and also intuition on how to make all these things come together. Hence why i still rank myself as beginner. All these small blocks though are helping as i am slowly building up blocks of code that i know i can either use or alter for the purpose of solving a specific problem so its all helping.

Thank you.
zeroSlave
14
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 5th Feb 2013 21:30
You needn't write "DATA" to all the lines in the file.

You also don't necessarily have to read/write strings. You can also read/write floats, bytes, etc.

If you wanted to crawl through the file and grab lines beginning with "DATA" or if you wanted to create a config file that didn't have to be in any specific order:



Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Nytus Sermus
11
Years of Service
User Offline
Joined: 17th Jan 2013
Location:
Posted: 7th Feb 2013 12:55
@ ZeroSlave: AWESOME advice with that 2nd code snippet.you have no idea how much gleening that method has just grown me in POWER !!!!


@ Somarl: one question, after you've completed your map editor based on the image with the grid, and you've exported the save data, then you import it into your game, does it have any connection with the visual representation of the landscape; is the data for the tiles directly connected in any way to the landscape that is created; or do you do that seperately? If not what do you use to represent the water/landscape in the actual game and is it 2d only or 3d? i ask because i thought it was 3d but just now was thinking that maybe the look of your editor might resemble your game map (a 2d game)...just trying to clarify

You could be done already.....stop trying to re-invent the wheel.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 7th Feb 2013 19:27
Im not 100% sure yet Nytus. It depends on what level of support and help i get with what im going to end up with i think.
What i think i am going for first is just a way to quickly place down buildings with the array either allowing or not allowing so everything will pretty much be 2d and very very very basic. Then i think i might like to try and move up to 3d starting with a proper 3d map editor in which after a few parameters are set initially then everything else is just a case of using a brush to lower or higher terrain, paint it with whatever textures that will then hopefully blend into one another, and have the computer work out what is passable and what is not by recognising water or terrain that is too steep to walk certain units up etc etc. I honestly dont know just yet im just playing and coding and learning. Taking it one step at a time!
Agent
19
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 11th Feb 2013 00:21 Edited at: 11th Feb 2013 00:27
Hi Somarl,

It's been a long time since I've haunted these forums (more than a year?) but I decided to come back and check in to see what was happening.

You've made a lot of progress! I remember helping you with sheer basics once upon a time.

I took interest in this thread because I use a similar method in my map editors. I use four paintable layers like so:

Layer 1: The ground. This layer is always drawn first.
Layer 2: Decorations. This layer is drawn second, so that it overlays the ground. I use this one to draw trees onto my ground, or tufts of grass, or bits of rock or wood, or pieces of furniture. This way, they overlay the floor tiles, creating a composite image. It means I don't have to have one tile for a rock on grass, then another for a rock on dirt, and another tile for a rock on sand. I just have a grass tile, a rock tile, and a sand tile, then one transparent tile with just a rock on it, and I just draw that on layer 2 so it overlays whatever ground I've got beneath it.
Layer3: Overhead. This layer draws after the first two, and *also* after I've drawn my characters, particles, etc, so they it obscures everything. You can use this layer for things like a canopy of leaves over a forest, or pieces of roof that hide other stuff from view, etc.
Layer4: Passability. This layer isn't drawn in the main game engine, but in the map editor I draw it after the overhead layer using transparent colored boxes. I draw green boxes over everything to show that this is a walkable tile (open ground), yellow boxes for not walkable but not solid either (used for things like tables - so gunshots, arrows, fireballs, etc as well as line of sight can pass across the table, but a player can't walk through it) and red for solid (blocks movement as well as projectiles and line of sight).

Using this method I can make secret paths, too - you can draw walls that look solid, and draw a roof above them on layer 3, but make just one of those wall tiles passable, along with a hidden corridor of passable tiles beyond it. That way a player will run into the walls and stop, unless he moves against it in exactly the right place - then it will admit him into the wall/secret passage, and he can move deep into the wall through this hidden passage and emerge somewhere else!

Good to see you're still around, Somarl!

EDIT: One other thought - when you save your map, consider writing just the values contained in the array, rather than prefixing the values with the word DATA to make actual copy+pastable code. Leave it in a raw numbers format - this might be more difficult for a human to read, but it's easier for a machine to read; once you have this file (consider it an export, a map data file), you can have your main game engine load the same file (instead of writing the values, read them!) and populate your array with those values. That way the map can be edited on the fly, and you don't need to recompile your whole game every time you make a change to a map.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 11th Feb 2013 17:06
Hello again Agent. I remember your help from a while back and im glad youve returned Good to see you again. I myself have been on and off here and there as i tend to find im best programming in small intensive blocks then taking a month or two out. This way i am slowly building up my skills without burning out. Some day ill be able to just get on with a project with minimal fuss i hope

Im not going to spend too much time on this map editor as i have learned a heck of a lot from it and now i am thinking of doing perhaps a 3d one but if i do i think i will start a completely new thread for that one but keep it based around the same theme 'a map editor for an RTS'.

Login to post a reply

Server time is: 2024-03-28 15:08:55
Your offset time is: 2024-03-28 15:08:55