ochadenas / cpudefense

A tower defense game for Android based on a microprocessor theme
MIT License
130 stars 8 forks source link

A simpler way to create levels #117

Open Urban-Hacker opened 8 months ago

Urban-Hacker commented 8 months ago

As said in #115 it would be nice to have a way to easily create levels. There is currently a guide in the wiki however the process is a bit cumbersome and I agree with @ochadenas creating an editor now would be too much work.

My suggestion for now is to have a simpler format in JSON that can be used to describe levels. Those json files could be potentially directly loaded in game, thus not requiring a contributor to build the game.

This would enable to easily create levels and those could be included in game via a simple pull requests. Currently levels look like this:

createChip(5, 10, ident = 101, type = Chip.ChipType.ENTRY) createChip(20, 10, 1) createChip(40, 20, 2) createChip(40, 50, ident = 999, type = Chip.ChipType.CPU)

This would be "trivial" to convert to json to have something like

"chips" : [ "chip" : {"x":5, "y":10, id:"xxx", type:"ChipType.CPU"}, "chip" : {"x..."} ]

Stages can then be split to have one stage in a json file with a collection of level. I think this would allow anyone to quickly create a series of level, test them without requiring to re-build the game and then do a pull request to have them included.

This can also make an editor easier since all the editor has to do is to output the json, so this can be a fully separated app.

Kutabu commented 8 months ago

You were a bit quicker with the idea. I had already thought about the fact that an external editor would be quick to create, because the level code isn't really the problem. I didn't get past the point of how the level finds its way into the code, because currently every level has to be hard-coded with the version. Whether it's .json or another file format doesn't matter as long as the levels don't always have to be compiled in the code.

There is currently a lack of visualisation and a test option for the player. If the level files are in a subfolder, every user could create levels and test them ingame before they are shared (in whatever way). User levels could be accessed via an extra tab in the level menu, which might only be enabled when a developer mode is activated in the settings (you could also associate the display of the framerate with this ). Therefore, extra level properties like name and creator are usefull.

ochadenas commented 8 months ago

I agree that reading the levels from a file definition (and yes, JSON would be quite a natural choice) would be a good first step. But still this will require some work.

But would this be a kind of personal level editor? Or how can those levels be put in a central repository somehow, to share them with others? I have not a good idea how to make this happen.

Kutabu commented 8 months ago

I think it's primarily a first step towards a level editor. You can programme the levels offline and test them in your own installation first. I would probably write a script that translates some visualisation into the level code. In the simplest case, some nonsense with Excel and VBA, so that you use the table as a basic grid and insert the connections as numbers.

The easiest way to share levels would be to put the files online in Github (repo, wiki, discussions) or send them to you via PM/mail. Then you or the community can do a quality check and roll it out with the next update. Yitro has done the same in Antiyoy, although the quality check has not been so great in the meantime. I don't think it's necessary to create a real structure for an online exchange within the game for the time being.

Urban-Hacker commented 8 months ago

I agree that reading the levels from a file definition (and yes, JSON would be quite a natural choice) would be a good first step. But still this will require some work.

But would this be a kind of personal level editor? Or how can those levels be put in a central repository somehow, to share them with others? I have not a good idea how to make this happen.

I think maybe having the levels in a second repository could simplify sharing / opening pull request. This would also make it easier to create content without having to re-release the game every time a new level is created.

For now I would not do an editor or even a second repository I would just separate the levels in some format (json, yml, xml, whatever) and have the possibility to sideload them without re-building the game.

Then people can still submit pull requests for their game. Anything else adds quickly a lot of complexity.

BTW this is one of the main reason why I wanted to re-implement the base gameplay in Godot for my own game so that people can simply open the levels in godot and start creating content without having to code anything :).