Spherical forums

Sphere Development => Sphere Support => Topic started by: mezzoEmrys on August 25, 2013, 11:14:21 pm

Title: Procedural Generation of Maps?
Post by: mezzoEmrys on August 25, 2013, 11:14:21 pm
I've been looking through various sphere documentations and I can't seem to find any hints of how this would be done. I could see it being done in ascii, but as for implementing graphics I am unsure as to how I would manage to make any sort of map be generated at runtime.
Does anyone have any suggestions as to if/how this would be possible?
Title: Re: Procedural Generation of Maps?
Post by: DaVince on August 26, 2013, 05:52:00 am
Sure. You can do enough with the map engine to make random maps, or to generate and expand it forevermore. In fact, I remember seeing a demo of random map generation a few years ago, though that was an example of pre-generated stuff, not procedurally generated stuff. Not sure where it (or the person who made it) went.

Use these functions to your advantage (check the wiki (http://wiki.spheredev.org/API:Functions) for usage instructions):
- Add new layers: GetMapEngine().layerAppend()
- Change a layer's size: SetLayerWidth(), SetLayerHeight()
- Edit the tiles on a layer: SetTile()
- Change the tile graphics: SetTileImage()
- Re-save an existing map as another one: GetMapEngine().save()
- Edit most things about a sprite (including directions and graphics).

Also use an UpdateScript that keeps track of where you are so you can start expanding and generating the map when necessary.


Also, here are some things you simply cannot do and need a workaround for:
- You cannot generate a brand new map file; you need to have one. (Unless you're painstakingly reimplementing the map file format using the RawFile functions.) Recommended is that you already have a single small empty map.
- You cannot edit maps when the map engine isn't open. It needs to be open.
- You cannot set the tile size. Better have made up beforehand how big you want your tiles to be.
- I'm pretty sure you can't generate new persons on a map, but you'll have to experiment with CreatePerson() and
- You might not be able to create new directions in a spriteset. (Those apparently require a SpritesetDirection object of which there is no constructor provided in JS...)

As for good algorithms to generate the landscape, I have never dabbled in that so I don't know.
Title: Re: Procedural Generation of Maps?
Post by: Fat Cerberus on August 26, 2013, 10:07:39 pm

- I'm pretty sure you can't generate new persons on a map, but you'll have to experiment with CreatePerson() and


Sure you can. Just put your CreatePerson() calls in the map's enter script and pass true for the third parameter (destroy_with_map).  I'm almost positive that's what the map engine does internally anyway when loading a map.
Title: Re: Procedural Generation of Maps?
Post by: mezzoEmrys on August 26, 2013, 10:36:57 pm
Thank you muchly, now I just have to actually put together a tileset to test out my attempts ;w;
Title: Re: Procedural Generation of Maps?
Post by: DaVince on August 27, 2013, 04:32:29 am
Good luck!



- I'm pretty sure you can't generate new persons on a map, but you'll have to experiment with CreatePerson() and


Sure you can. Just put your CreatePerson() calls in the map's enter script and pass true for the third parameter (destroy_with_map).  I'm almost positive that's what the map engine does internally anyway when loading a map.

Well, I mean and have it saved in the generated map. Though I suppose you can hack your way around that rather easily, anyway.
Title: Re: Procedural Generation of Maps?
Post by: Radnen on August 27, 2013, 05:23:27 am

Sure you can. Just put your CreatePerson() calls in the map's enter script and pass true for the third parameter (destroy_with_map).  I'm almost positive that's what the map engine does internally anyway when loading a map.


I did precisely that when I made the in-map game editor for Pokemon Azure quite a few years ago. Heh, what a nifty technical project that was.