Level editor programming

Discuss classic and favorite computer or console games here.
Post Reply
User avatar
entropicdecay
Mad Mushroom
Posts: 576
Joined: Thu Nov 01, 2007 15:00
Contact:

Level editor programming

Post by entropicdecay »

Not sure if this is the right board for this, but it is about game modding...

Would anybody happen to know any resources about, or have any advice/general information about, programming level editors for existing games? How difficult, in a general sense, of a programming task is a level editor? Are any particular programming languages more or less ideal than others for it? (I assume it could be done with any general purpose programming language, though how file input/output is handled in a given language seems like it may become relevant in terms of it being easier or harder in a given language)
User avatar
KeenRush
Android Dummy
Posts: 2560
Joined: Sat Oct 27, 2007 20:57
Location: KEEN1.EXE
Contact:

Re: Level editor programming

Post by KeenRush »

I think a lot depends on what the target game is; the more complex the game, the more complex the level editor needs to be. For a tile-based game of Keen's type, with a simple tile layer and a sprite layer, the task isn't all too difficult. (Although that depends on whether you know any programming basics at all.) Not to mention that if you're targeting any modern pc (even those 10 years back) you practically don't have to worry about the memory usage. I myself have programmed my Keen 1-3 level editor "akeen" in C using the SDL library -- it's a combination that's fairly easy to use and since it's (or at least was at some point) a popular library, answers can be found to most questions about it.
My newest mod - Commander Keen: Sunset: viewtopic.php?t=8568 | codename H.Y.E.N.A.
User avatar
entropicdecay
Mad Mushroom
Posts: 576
Joined: Thu Nov 01, 2007 15:00
Contact:

Re: Level editor programming

Post by entropicdecay »

KeenRush wrote: Tue Oct 23, 2018 5:39 I think a lot depends on what the target game is; the more complex the game, the more complex the level editor needs to be. For a tile-based game of Keen's type, with a simple tile layer and a sprite layer, the task isn't all too difficult. (Although that depends on whether you know any programming basics at all.)
Makes sense. It is indeed a tile-based game I'm thinking of, specifically Jill of the Jungle. I know it already has a built in level editor, but I would find a mouse-based editor that could show more of the level at once easier to use. I do know some programming basics, but I don't think I know enough yet to make a level editor. However, since I'm recently trying to get back into learning programming, hopefully I could eventually learn enough to do so.

It would be reasonable, though, to think that using the built-in editor would be easier than making a whole new one, so I will likely experiment with using that and see if I can put some levels together that way. Making my own editor if I could learn how to do so could be helpful in terms of programming knowledge, though.
User avatar
Roobar
Vorticon Elite
Posts: 3263
Joined: Tue Jan 08, 2008 16:12
Contact:

Re: Level editor programming

Post by Roobar »

Dude, if you manage to make a windows based editor that would be awesome! I surely would like to make a few Jill levels! I'm not sure, but Camoto may be able to edit Jill levels. Be sure to check that out or contact Malvenious for assistance, though his editor is hard to learn (I tried to edit Secret Agent and almost nothing worked as intended and I gave up) and he's hard to find since he's not visiting this forum often.
User avatar
Commander Spleen
Lord of the Foobs
Posts: 2384
Joined: Wed Oct 31, 2007 22:54
Location: Border Village
Contact:

Re: Level editor programming

Post by Commander Spleen »

Once you have the level format, the hard part is the GUI and some advanced features like automagic adjacency and undo. I use C++ with the cross-platform Qt toolkit for my Levelderp editor, which made things pretty simple, though some of it has become a bit spaghettified and in need of a rewrite.

You can get the source code from this thread at Keen:Modding in case it helps:

https://keenmodding.org/viewtopic.php?f=33&t=1943
User avatar
K1n9_Duk3
Vorticon Elite
Posts: 779
Joined: Mon Aug 25, 2008 9:30
Location: Germany
Contact:

Re: Level editor programming

Post by K1n9_Duk3 »

I have some experience with programming my own level editors and I just spent some time diving deep into the file formats of Jill of the Jungle, so I guess I can give you some advice.

First of all, Jill is not an easy game to write a level editor for. Unless you want to challenge yourself, I would suggest working on a game with more simple file formats for your first level editor - games like Duke Nukem, Dark Ages or Cosmo's Cosmic Adventure.

The reason why I suggest this is that Jill's levels are in the exact same format as the Jill's saved games, which means the files store the internal variables of every single game object in the level. And those level objects are not bound to the same grid as the level tiles (they obviously store their pixel-perfect position, among other things). That means you would need to program two different editing modes - one for the tiles and one for the objects - which is probably too difficult for you if this is your first attempt at creating a level editor.


I can't really recommend any particular programming language or libraries. You should be able to write a level editor in pretty much any programming language, so pick the one you're most familiar with and look/ask for help if you don't know how to perform a specific operation in that language.

When you start programming, there are two ways to proceed (since this is your first project): The first is to focus on the game's file formats and start with the code that reads the files and represents the infromation in datastructures that are easy to use for you. While you're doing that, find a way to make the program show you the information it reads from the files (use a message window or print text to a console) so you can see early on if your code works as intended.

The second is to focus on the user interface first and write your own "mspaint" dummy program. Since most 2D games use tile-based levels, a level editor is usually very similar to a paint program. The only difference is that it uses bigger tiles instead of single pixels and a tile set instead of a color palette. You will probably end up trashing this dummy program and start from scratch when it comes to the actual level editor, but it helps you get used to your programming tools.

You will eventually reach the point where you want to display the level layout using the correct graphics. If you can't figure out how to load the graphics from the game files, you can just take a tool that can already do that and convert all the graphics you need into a format that is easier to read in your program. For Jill that would be programs like Camoto or Wombat. Or you can just take a lot of screenshots in the original game to get the graphics you need. (Jill's .SHA format is a pain, so I would actually recommend bypassing it unless you want to challenge yourself). Just be aware that not loading the graphics from the original files means your program might not display the levels correctly when the game/mod uses modified graphics files.

And just in case you didn't know: You can find info on the file formats of many DOS games here: http://www.shikadi.net/moddingwiki/
Hail to the K1n9, baby!
http://k1n9duk3.shikadi.net
User avatar
entropicdecay
Mad Mushroom
Posts: 576
Joined: Thu Nov 01, 2007 15:00
Contact:

Re: Level editor programming

Post by entropicdecay »

Thank you very much for the information and advice. Starting off by experimenting with making a "dummy" editor to learn how to program the functionality of a level editor sounds like a good idea, as well as making a level information viewer to practice working with the level file format of a game.

ModdingWiki I was definitely aware of, I'd find it very daunting to even consider attempting making a level editor without an reference like that. I do remember trying to figure out the format of Jill's levels myself but when I saw ModdingWiki's information, I realised that I had got several things wrong.

If the complexity of Jill's level file format may make it not ideal as a first game to make a level editor for, might something like Crystal Caves or Secret Agent be any more straightforward, since they don't feature in-level saving? (On the other hand, if I remember correctly Crystal Caves (not sure about Secret Agent) has its level data in the .exe file, which seems like it might present its own issues. Perhaps coding a function to extract level data to external files and to reinsert the edited data from said files would be a good idea in that case.)

Edit: And looking at ModdingWiki, apparently most of Secret Agent's data files are encrypted, so that'd presumably add an extra complication. I'll have to look around ModdingWiki and see if any games' level formats seem fairly straightforward.
User avatar
K1n9_Duk3
Vorticon Elite
Posts: 779
Joined: Mon Aug 25, 2008 9:30
Location: Germany
Contact:

Re: Level editor programming

Post by K1n9_Duk3 »

Creating an editor for Secret Agent should be pretty straightforward, but I would not recommend messing with Cystal Caves unless you want to dive deep into disassemblers and patching executables. The reason for that is that the code to "load" a level in Crystal Caves would have looked somewhat like this:

Code: Select all

SetLevelLine( 0, '1111111111111111111111111111111111111111');
SetLevelLine( 1, '5gggggggggggggggggggggggggggggggggggggg5');
SetLevelLine( 2, '6      ¡ ©    ©[=n  G  ©               4');
SetLevelLine( 3, '6 Ddd™d™ddddd™dddd™ddddddddddd™dddddš  4');
SetLevelLine( 4, '6¨             #                     _ 4');
SetLevelLine( 5, '6 #      b   b   b   b   b   b    ó    4');
SetLevelLine( 6, '6       ___ ___ ___ ___ ___ ___ ______ 4');
SetLevelLine( 7, '6                     #                4');
SetLevelLine( 8, '6 Ddn                           #      4');
SetLevelLine( 9, '6     b          [#           b        4');
SetLevelLine(10, '6    ˜dn     ]   nn $        ˜dn       4');
SetLevelLine(11, '6           Ddn   êén               b  4');
SetLevelLine(12, '6  b               ˜d™n            D™n 4');
SetLevelLine(13, '6 D™n                                F 4');
SetLevelLine(14, '6  G              Y            Dš    JG4');
SetLevelLine(15, '6   °          rttyB rtty           rtt5');
SetLevelLine(16, '6           rtt5556B 4555tty        fgg5');
SetLevelLine(17, '6        rtt5555556 B4555555tty      Xn4');
SetLevelLine(18, '6        45555ggg56 B45ggg55556      nn4');
SetLevelLine(19, '6      rt55556 bb46B 46bb 45555ty   rtt5');
SetLevelLine(20, '6s     45555gh §§46BG46§§ fg55556   fgg5');
SetLevelLine(21, '6    rt5555h £×rt56 B45tyפ f5555ty    4');
SetLevelLine(22, '6    4555gh  n fggh Bfggh n  fg5556    4');
SetLevelLine(23, '6v rt5556©  ry     _   ~  ry  ©4555ty ¦4');
SetLevelLine(24, '5tt555555ttt55tttttttttttt55ttt555555tt5');
(The text strings make heavy use of extended characters, so the code isn't displayed correctly here.)

Since each row of level data is a text string in the source and the game was written in Turbo Pascal, the compiler automatically merged duplicate strings to reduce memory usage. That means if the same text string appears as a row in multiple levels, you can't just change the string for one level without affecting the other(s). You would have to change the actual code to avoid that. But since some strings are merged in the original executable, there is not enough space in the executable to mod every single level in any way you want. Some levels have to share the strings with other levels, there's no way around that without some serious patching.
Hail to the K1n9, baby!
http://k1n9duk3.shikadi.net
User avatar
entropicdecay
Mad Mushroom
Posts: 576
Joined: Thu Nov 01, 2007 15:00
Contact:

Re: Level editor programming

Post by entropicdecay »

K1n9_Duk3 wrote: Mon Nov 12, 2018 21:54 Since each row of level data is a text string in the source and the game was written in Turbo Pascal, the compiler automatically merged duplicate strings to reduce memory usage. That means if the same text string appears as a row in multiple levels, you can't just change the string for one level without affecting the other(s). You would have to change the actual code to avoid that. But since some strings are merged in the original executable, there is not enough space in the executable to mod every single level in any way you want. Some levels have to share the strings with other levels, there's no way around that without some serious patching.
Ah, I see. Yeah, that definitely sounds like it'd be tricky to deal with. Interesting to know Crystal Caves was written in Turbo Pascal though, I used some Pascal back in my college computing class. I guess I would've incorrectly assumed it'd be written in C, as when I've seen source code released for old DOS games it seems to generally tend to be C or C++.
Hisymak
Vortininja
Posts: 112
Joined: Sat Mar 26, 2016 20:13

Re: Level editor programming

Post by Hisymak »

Hi. I actually have quite solid experience making level editors for DOS tile-based platformer games. Some of you might remember, that about 2 years ago, I created level editors for Hocus Pocus and Vinyl Goddess From Mars.
The editors are made in Delphi 7, which is development toolkit based on Pascal programmig language. Delphi 7 is really outdated, but still it's, at least for me, the easiest way to create Windows GUI programs. Some more modern tools, like Qt, I find much more complicated and difficult to use, but that's rather about personal preference and experience.
To be honest, these two editors are not my only level editors I made. Many years earlier, about 2010 or 2012, I started creating a map editor for strategy game called Dune 2000. The UI as well as features went through long development and improvements during the years. Eventually the editor became really superior and powerful tool with features that can extremely ease creation of the maps, and was used by many people to create even hundreds of new maps and several full custom campaigns.
Then I got eager to create a level editor for another great classic game, which was lacking a fully functional level editor for many years: Hocus Pocus. I discovered the Modding Wiki and found out, that all the level format of Hocus Pocus was already reverse-engineered, and some attempts to create level editor for this game already happened, but none of them were fully usable. I challenged myself to create an user-friendly tool which can edit all the parts of the levels, including switches, locks etc.
Basically half of the work was already done, because I just took the source code of Dune 2000 editor as a base for Hocus Pocus editor, and re-used many parts of it, mostly the program "skeleton", user interface and rendeding and painting routines. What I needed to do, was to implement loading and saving levels in Hocus Pocus format, loading the tilesets and later sprites, and implement new UI for Hocus Pocus-specific level objects, like switches, locks etc. The level minimap feature is inherent from a strategy game, but appeared to be a great and innovative feature in a platformer game level editor, and I've probably not seen that in any other editor I tried, even Abiathar. One significant new thing I implemented in Hocus Pocus editor was the Pattern editing mode, which is very suitable for such game.
After success with creation of Hocus Pocus level editor, I wanted to create an editor for my other favourite childhood game: Vinyl Goddess from Mars. And here, I started off taking Hocus Pocus editor as a code base (which saved half of the work for me once again), and rewriting routines to load/save the levels and creating UI for VGFM-specific features. Creating VGFM level editor was much fun for me for the reason, that the level format was only partially reverse-engineered and documented on the Modding Wiki. I needed to reverse-engineer big part of the level format on my own. Which was really fun and satisfactory, because it felt like an adventure. Unlike in Hocus Pocus case, this time I also created a few full custom levels.
I was also seriously thinking about creating a third level editor in a row for another game I liked as a child: Jill of the Jungle. I was well-experienced with previous games, and the Jill level format was pretty well described on the modding Wiki, so it looked like another great challenge for me. But unfortunately, that did not happen, and I got disinterested and never even started making Jill level editor.
The main reason for this was lack of interest of modders to create some new levels and mods for either Hocus Pocus or Vinyl Goddess from Mars. In short, I did not get what I was expecting and looking forward to: new levels and mods for my favourite games I could play and enjoy. While the earliest Dune 2000 editor was heavily used to create numerous mods and whole campaigns (which got published too), the Hocus Pocus editor was barely used by a few most interested Hocus Pocus fans to create two, or probably three new levels, which they really published and I could play. For the latter VGFM editor, I got practically zero outcome, with my own custom levels being the only existing new levels for this game. And to make things worse, I unintentionally caused a flame discussion in the VGFM level editor thread on this forum. So in the end, I realized it's probably too late (about 25 years after publishing these games) for level editors to be worth being created, as the games no longer have community and modding base strong enough to create any serious mods and level packs for these games. And I directed my interest in completely different things.

Back to the technical topic. Technically you could just take source code of either Hocus or Vinyl level editors, and rewrite it to support Jill of the Jungle. But that's practically impossible to happen, as you most probably don't know either Delphi or Pascal, and are not familiar with the source code of the editors. But I hope I gave some useful or at least interesting information to you, and made some philosophical question whether it's even worth investing time and effort into something what barely somebody would use. You could give your opinion about that.
User avatar
K1n9_Duk3
Vorticon Elite
Posts: 779
Joined: Mon Aug 25, 2008 9:30
Location: Germany
Contact:

Re: Level editor programming

Post by K1n9_Duk3 »

Yeah, speaking of level editors for Jill of the Jungle: I decided to write one after my initial post about how Jill wouldn't be the best choice for somebody's very first level editor. It's currently in (closed) beta testing. I thought I should mention that before somebody else starts wasting time on yet another level editor. (But hey, if somebody actually wants to do that, go ahead and do it anyway.)
Hail to the K1n9, baby!
http://k1n9duk3.shikadi.net
User avatar
KeenRush
Android Dummy
Posts: 2560
Joined: Sat Oct 27, 2007 20:57
Location: KEEN1.EXE
Contact:

Re: Level editor programming

Post by KeenRush »

@K1n9_Duk3: Hey, how about creating a level loader patch for Crystal Caves? It probably wouldn't take more space than the data for the first level and could be patched over it. Something very simple that works like this:
1. See which level is to be loaded. Take level's file name from an array of strings. For example for level 1 the data could be "L1.CC1\0\0".
2. Open level file. Take first two bytes -- the level width. Take next two bytes -- the level height. Do the traditional two-loop for-y for-x and read from left to right, top to bottom the tiles for the level, each value taking two bytes. Simultaneously place the tile in the game's memory of the level (I assume it's just an array of integers). Do the same for sprites, call whatever sprite-setting codes the game ordinarily does.
3. Jump to where normal level loading does after it's done.
Since there's no issue of data storage, it wouldn't matter that the levels aren't compressed at all and might take several kb each. Simply not a problem as nobody is trying to play it using a 512kb harddrive.

I think I could do this myself if I knew the right addresses and could debug better. But for you this might not be a difficult task. This kind of layer would allow the simplest level editors to be made. I could help with this if you're willing to take a shot at it.

EDIT: I've now programmed a simple skeleton of a loader. It's not functional but if you want to try this project you could use it as a base (and save a little time). Essentially the loader needs the right Crystal Caves memory addresses in its code (and possibly some fixes in its file reading routines because I'm not an expert at this). If interested, send me e-mail or PM your address so I can send the file. As assumed, this system is very simple. I don't know how CC deals with initializing sprites in the level, so that's going to need some more coding, but I'd guess it won't be much more than pushing some x and y coordinates into the stack and calling a function. I can help with figuring those out if this proceeds. It'd be amazing to get Crystal Caves level editing working 100% right.
My newest mod - Commander Keen: Sunset: viewtopic.php?t=8568 | codename H.Y.E.N.A.
User avatar
entropicdecay
Mad Mushroom
Posts: 576
Joined: Thu Nov 01, 2007 15:00
Contact:

Re: Level editor programming

Post by entropicdecay »

K1n9_Duk3 wrote: Mon Dec 31, 2018 23:47 Yeah, speaking of level editors for Jill of the Jungle: I decided to write one after my initial post about how Jill wouldn't be the best choice for somebody's very first level editor. It's currently in (closed) beta testing.
That's exciting to hear.
Hisymak wrote: Mon Dec 31, 2018 19:02 Back to the technical topic. Technically you could just take source code of either Hocus or Vinyl level editors, and rewrite it to support Jill of the Jungle. But that's practically impossible to happen, as you most probably don't know either Delphi or Pascal, and are not familiar with the source code of the editors.
I do know some Pascal, but it's been quite a while since I used it much and I haven't used Delphi (I've used Turbo Pascal, Free Pascal and a little bit of Lazarus). And I most likely never got to the point of knowing enough to to understand something like a level editor. As of yet anyway. I didn't mean this topic as implying I would DEFINITELY create a level editor, or that I knew enough about programming yet to do so. What I was interested in was basically, HOW to learn what I'd need to learn to be able to program a level editor, or a general sense of how complicated a programming task it tends to be.
Post Reply