This small program I wrote demonstrates one way of making 3Dish looking terrain in 2D. It uses vertex arrays and OpenGL to render the land. It's quite fast even with larger maps. It's of course made with python but the same thing can be done with C/C++ or any other language.
Click here to download the demo source. You will need python, PyOpenGL, pygame and Rabbyt to run. Unzip the download and run run.py for the "game" and editor.py for a rather cool editor. You can read on for the docs on using the editor (also included in README.txt)
Editor
Using the editor is pretty strait forward. There are three modes:
- Border mode (default)
Pressing the "b" key will get you into this mode. When in this mode you can move points in already made regions by holding down on the CTRL key and left clicking on a point (then drag it around). While holding down on the CTRL key you can press the RMB (right mouse button) to delete the point. Middle clicking with the CTRL key pressed will delete the entire region.
You can then create new regions by left clicking anywhere (without CTRL). Keep left clicking to create new points for the region and then right click to finish.
- Terrain mode
You get into terrain mode by pressing the "t" key. While in the terrain mode let click to raise the terrain and right click to lower it. You can also drag your cursor around while clicking to repeatedly perform your terrain deformation.
There aren't any hot keys to change the brush but on line 91 in editor.py you can change it from NORMAL to any of the other brushes defined above it (HILL, GENTLE and STEEP).
- Region mode
Pressing "r" will get you into this mode. Region mode is for connecting the regions (This is, for example, useful a risk like game; the connections would tell your game which regions you can move armies between).
If you don't have a region selected clicking will select one. If a region is selected and you left click on another one it will connect the two. Right clicking on a region will delete all connection to that region (both ways).
And finally you can save any modifications to the map by pressing CTRL+s
That's it! Have fun and feel free to use the code in your own game (as long as your game is compatible with the GPL license (included, see GPL.txt)).
Also if you have any feedback be sure to send it to me at web(@)joey101(.)net
