Level editor programming

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

Level editor programming

Post by elecdude33 » Mon Oct 22, 2018 21:57

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: 2540
Joined: Sat Oct 27, 2007 20:57
Location: KEEN1.EXE
Contact:

Re: Level editor programming

Post by KeenRush » 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.) 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 - Planet Of Agony: https://pckf.com/viewtopic.php?t=4165 | codename H.Y.E.N.A.

elecdude33
Mad Mushroom
Posts: 448
Joined: Thu Nov 01, 2007 15:00
Contact:

Re: Level editor programming

Post by elecdude33 » Tue Oct 23, 2018 15:44

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: 2793
Joined: Tue Jan 08, 2008 16:12

Re: Level editor programming

Post by Roobar » Tue Oct 23, 2018 18:15

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: 2341
Joined: Wed Oct 31, 2007 22:54
Location: Border Village
Contact:

Re: Level editor programming

Post by Commander Spleen » Thu Nov 08, 2018 12:48

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: 472
Joined: Mon Aug 25, 2008 9:30
Location: Germany
Contact:

Re: Level editor programming

Post by K1n9_Duk3 » Fri Nov 09, 2018 22:41

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

elecdude33
Mad Mushroom
Posts: 448
Joined: Thu Nov 01, 2007 15:00
Contact:

Re: Level editor programming

Post by elecdude33 » Mon Nov 12, 2018 21:18

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: 472
Joined: Mon Aug 25, 2008 9:30
Location: Germany
Contact:

Re: Level editor programming

Post by K1n9_Duk3 » Mon Nov 12, 2018 21:54

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

elecdude33
Mad Mushroom
Posts: 448
Joined: Thu Nov 01, 2007 15:00
Contact:

Re: Level editor programming

Post by elecdude33 » Tue Nov 13, 2018 20:16

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++.

Post Reply