Possible to extend game via downloadable content

Monkey Forums/Monkey Programming/Possible to extend game via downloadable content

AJStubzy(Posted 2015) [#1]
I am looking into using Monkey to rewrite a game i wrote for Android using Marmalade (as i just can't get my head around native c++)

One of the features i am looking to implement, if possible, is to extend my game through downloadable levels. However, i need the downloadable content to communicate with the main program and vice versa.

So the main program loads, then a sub program load's within the main program.

The main program will control score's, controls and other global stuff, where by the level will just play within the canvas. When certain events trigger on the main program, these need to be passed to the level's and vice-versa.

Is this possible with Monkey?


k.o.g.(Posted 2015) [#2]
Why you don't create your levels with json or similar?


AJStubzy(Posted 2015) [#3]
Continuity, keeping the whole game designed in one language. Ideally, the levels will be created and compiled to a form of binary file which the main program will load.

Possible?


Sicilica(Posted 2015) [#4]
What k.o.g. was saying is, you need to separate your levels from the actual code.

What you are trying to do could work, theoretically, on at least the C++ desktop target. It could MAYBE be done on Android with some really involved hacks and workarounds, but on Android or almost any platform for that matter, the main issue is that your code is always running in a sandbox to keep the device safe, and what you're doing isn't really playing in that sandbox.

Your program should contain all the logic for how your game runs, but then your levels should be in external files that you use as resources. Think of it as using images, sounds, etc - the actual pixel data isn't a binary program, it's just stored externally and then read from disc by your main program. With your levels, you want to find some way to store them in their own files (say level1.level, level2.level and so on) and teach your main program how to parse those files. JSON and XML are really good examples of formats for storing that kind of arbitrary data in a text file. Personally, I use the open source Tiled editor (available at http://www.mapeditor.org/), which uses an XML based format.

All your level files contain are the positions of objects - instructions that say, create an enemy here, make the ground solid here, and so on. They don't contain actual program code. Then it's a really simple job to download them from a webserver, store them on the filesystem, and read them later.


Soap(Posted 2015) [#5]
To be absolutely clear, what OP wants is possible with monkey.


Skn3(Posted 2015) [#6]
You have two options:

1:
Define your level features and hard code them into your game engine. So for example you would program all of your enemy types, item types, spring boards, platforms, etc. then you create level files that tell the game where to place scenery, enemies and items. If you want to get more complicated you could include things like enemy movement paths, missions and so on.

To make them downloadable you could do this with the httprequest module. You would need a web server to store your levels. Your best bet would be to write a nodejs/php backend to handle distributing the level files.

2:
If you wanted to have new game elements/behaviours included in your level files then you would have to move into the realm of writing a scripting language. There is minic http://www.monkey-x.com/Community/posts.php?topic=3616 hasn't been updated in a while I don't think but it would allow you to add scriptable features.


AJStubzy(Posted 2015) [#7]
Thanks Skn3, I’ll take a look at the mentioned add-on.

However, the 3rd option which I was hoping to do is as follows.

I write the level file as a monkey file (combination of functions) and compile this out to a binary file (Library)

The main program can then load this file and I can make call’s to it to run the relevant functions/code, and pass details back to the main program. Ideally, the library can made call’s to functions within the main program also.

When the level completes or ends, the library is unloaded, and returned to the menu. When a new level is selected, the new library is loaded and the process starts again.


Gerry Quinn(Posted 2015) [#8]
That would be pretty complicated if it is possible at all.

A pragmatic solution would be to update the main program whenever you release a level that requires new functionality. Then you can have the level data as separate downloadable content.

Code is generally small in size anyway - it is assets that take up space, So your program will not grow huge.


tiresius(Posted 2015) [#9]
What you want is doable with an interpreted language but Monkey is translated+compiled into separate executable code so this sort of thing would be very hard to do, especially "adding" to the game code via download. I don't think you would want a copy of code for every level regardless? If you really need something like this, binding your engine to a scripting language like LUA might be the only way to go.

As others have suggested, perhaps build up the engine to handle all the features and make separate level data files to activate them.


Skn3(Posted 2015) [#10]
If you are compiling a dll/lib then you limit your target platforms. If you are just targeting say windows/Linux/Mac then this is a good (albeit a little heavy handed) approach.

If you are wanting to target mobile, why would you not want to lean on apple/Google content distribution networks and let them handle downloads of updates via respective app stores. If you host the extra features yourself, and you have a ton of players, your gonna be shelling out for server/bandwidth usage. I guess you avoid waiting for the updates to be approved by apple/google...