Custom Terrain Editor in Java

Started by mopa42, April 02, 2011, 05:00:16 PM

Previous topic - Next topic

mopa42

Recently I was inspired (partly by this post: Upgrade the editor) to make my own map editor.
Why?
A reasonable question, especially since CW2 is coming soon. Mainly I just like the game a lot. Part of it is that I'm taking a java programming class this semester which has really gotten me excited about making GUIs. The other is I've been wanting to continue working on the custom map file format, which I began in my first post here (How to edit Creeper World custom map (.cwm) files by hand).

So what's wrong with the current custom map editor? The main things are that it is hard to draw continuous lines (the brush skips if moved quickly), and it is hard to draw circles and other curvey terrain. Nothing that makes it impossible to use the map editor, just a little painstaking.


Anyway, under the theory that some other people might find it useful, I'd like to share this terrain editor that I made.

I say terrain editor because all that my program can do is edit the 70x48 grid of elevations. It is possible (though highly unlikely) that I could extend it to modifying emitters or walls or the like, but I just don't see the need (the current map editor works well enough). Edit - by request, version 0.5 and higher can now edit emitters.
A side note on terminology: I use the terms cell, grid, square, and sometimes pixel to refer to the 70x48 elements of the map.

Basic features / use:

  • As expected, there are 5 distinct elevations represented by colors: 1=dark=low, 5=light=high. But as I found out, since the game will sort of display elevations 0 and 6, there are actually 7 distinct levels.

  • The basic interaction is using a particular brush (square, diamond, or circle of various sizes), the paintbrush tool, and the set elevation action. This is similar to how the current map editor works.

  • Tools other than the paintbrush will apply the same operation, just using using a different method to decide which portion of the map to apply the operation to. Using the rectangle tool will have the same effect as clicking individually on each of the cells in the same shape.

  • There are various actions besides just painting elevation values, such as raise/lower terrain and smooth terrain. Note that all the actions are applied once at the start of each brush stroke (repeatedly dragging the tool over the same area doesn't apply the tool multiple times in one brush stroke).

  • Finally, there is the selection tool. "Selectedness" can be painted using all of the brushes. To move the selection, use the Move Selection tool to drag the selected pixels around, sort of like copy and paste. Additionally there is an option to only paint inside the selection.

Random list of other comments:

  • There is a custom brush editor - if you want to define a stick-figure as your brush, you can.
  • There is a paintbucket tool, which applies the given operation to contiguous regions or to the entire map.
  • The program can read and write CWM, XML, and raw CSV files. You can even ignore the terrain editing bits, and just use the program to decompress the CWM files to XML, manually edit them, then compress the XML back to CWM.
  • You can open a CWM file, edit the terrain, save it again in CWM format, and the editor will have remembered all the non-terrain details (even though it doesn't display them).
  • You can export to an image, or to a series of layer masks (one per level) for making your own fancy backgrounds.
  • Shortcuts Ctrl + 0,1,2,3,4,5,6 jump to the paintbrush tool with that set elevation.
  • Scrolling the mouse wheel adjusts the size of the brush.

Here's a screenshot of the program in action, and then the game with the corresponding map.




Known limitations:
You can't [yet] set a custom image as a (temporary or permenant) background.
Very little documentation.
Can edit only terrain, which means you will still need to use the original custom map editor for the non-terrain elements.

On a technical note:
The program is a jar file, which means that for most people you can just double-click to run it. (you'll need java 6)
Jar files are zip files with a different name, so you can extract their contents. In particular, the source code (the raw .java files) is included. Feel free to look / modify / reuse for any purpose - I'm placing the code in the public domain, but that doesn't mean that it is well-organized or easily reusable.

Feedback I'd like:

  • Let me know if the program doesn't even run.
  • If you can, I'm interested in feedback on how easy the program is use, whether everything works correctly, and (most importantly) whether the program is helpful for making maps.


TL;DR:
Download and try my new java terrain editor! You can draw circles and stuff!

I've updated the editor! (the new version, in TerrainEdit-Latest.zip, is now v0.6).
See here for new features in 0.4, here for 0.5a (emitters), and here for 0.6 (random terrain).

Edit - minor formatting, added note about scroll wheel
Edit - Changed TerrainEdit-Latest.zip to 0.6

MadMag

#1
Wow...  Nice work!

Even a Custom brush choice.

Blaze

In the second shot, what is that glowing orb?

thepenguin

We have become the creeper...

Fisherck

Amazing. Great job! This could be very helpfull for lots of people...
My CW2 Maps
My CW1 Maps
Quote from: Sqaz on August 28, 2011, 02:49:35 PM
The comments are here to comment, dare to use them.

mopa42

Quote from: Blaze on April 02, 2011, 05:15:11 PM
In the second shot, what is that glowing orb?
It is the rift right as it opens. (I forgot to add a totem, so the map was almost over before I grabbed the screenshot).

UpperKEES

Very nice! I was actually done with CW1 map making, but I guess I'll have to try at least one more time.... :)
My CW1 maps: downloads - overview
My CW2 maps: downloads - overview

J


thepenguin

for reasons of security and paranoia, can I see the source code for the program?
We have become the creeper...

mopa42

Quote from: J on April 03, 2011, 07:12:18 AM
I can't save my maps
Can you tell me exactly what steps you are taking?
(my guess as to what the problem is: you have to type in the file extension yourself. The program's not smart enough to add one itself)

mopa42

#10
Quote from: thepenguin on April 03, 2011, 02:45:00 PM
for reasons of security and paranoia, can I see the source code for the program?
The source is included in the jar file, but you have to extract it yourself.
One way of doing that is to rename TerrainEdit.jar to contents.zip, then open the zip file. Inside you'll see a bunch of .class files (the compiled java files, the ones that get run), and a bunch of .java files (the source code). The images directory is also important - the program looks for /images/rock.jpg.
The main file is CreeperWorldTerrainEditor.java.

thepenguin

We have become the creeper...

Fisherck

It even has the elusive circle brush! Where were you when I was trying to that myself? ;)
My CW2 Maps
My CW1 Maps
Quote from: Sqaz on August 28, 2011, 02:49:35 PM
The comments are here to comment, dare to use them.

DarthVader12

#13
works fabulously
great job
you are going to update it right? ;)

thepenguin

Quote from: DarthVader12 on April 04, 2011, 02:37:28 PM
works fabulously
great job
you are going to update it right? ;)


what is there to update?
We have become the creeper...