Giter Club home page Giter Club logo

mapgen2's Introduction

http://unmaintained.tech/badge.svg

JavaScript version of my Polygon Map Generator.

  • Most of the algorithms are reimplemented rather than ported, so there are some minor differences, but it mostly follows what’s described on this page.
  • The data structures are rather different. The mesh connectivity is separate from the generated map (elevation, rivers, biomes, etc.). The original project uses an “array of struct” approach whereas this one uses a “struct of arrays” approach (see explanation).
  • The naming convention for the data is x_property_y where x and y are r, s, or t indicating the type of the input (x) and output (y). For example, t_downslope_s would be an array indexed by a t (triangle) id, and returning an s (side) id.
  • The maps are created with 0 ≤ x ≤ 1000, 0 ≤ y ≤ 1000.

This repository contains the map generation algorithms but not the code for UI or rendering.

Output

If your game needs polygon data:

let polygons = [];
for (let r = 0; r < map.mesh.numSolidRegions; r++) {
    polygons.push({
       biome: map.r_biome[r],
       vertices: map.mesh.r_circulate_t([], r)
                         .map((t) => map.t_pos([], t))
    });
}

If you want the noisy edges instead, see map.s_lines[s] for the line segments that should be used instead of side s.

If your game needs the polygons split into triangles:

let triangles = [];
for (let s = 0; s < map.mesh.numSolidSides; s++) {
    let r = map.mesh.s_begin_r(s),
        t1 = map.mesh.s_inner_t(s),
        t2 = map.mesh.s_outer_t(s);
    triangles.push({
       biome: map.r_biome[r],
       indices: [
          map.r_pos([], r),
          map.t_pos([], t1),
          map.t_pos([], t2),
       ]
    });
}

If your game needs the polygons split into tiles:

The map coordinates are 0 to 1000. Scale these to the desired size of the map. Use a polygon rasterization library like points-in-polygon to get a list of tiles for each polygon. I have not tried this yet.

mapgen2's People

Contributors

redblobgames avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.