Skip to main content

News

Topic: Procedural Generation of Maps? (Read 6124 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
Procedural Generation of Maps?
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?

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Procedural Generation of Maps?
Reply #1
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 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.
  • Last Edit: August 26, 2013, 05:53:56 am by DaVince

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: Procedural Generation of Maps?
Reply #2

- 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.
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

Re: Procedural Generation of Maps?
Reply #3
Thank you muchly, now I just have to actually put together a tileset to test out my attempts ;w;

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Procedural Generation of Maps?
Reply #4
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.

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Procedural Generation of Maps?
Reply #5

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.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here