SeijiEmery / dungeon-generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dungeon-generator

Dependencies:

  • python 3.x
  • npm
  • webpack-cli

Install dependencies:

Lastly, install webpack-cli: npm install -g webpack-cli

Build instructions:

git clone https://github.com/seijiemery/dungeon-generator
cd dungeon-generator
pip3 install -r requirements.txt
npm install
./run.sh isometric_render_test

Overview:

Alt text

Procedural dungeon generator implemented for CMPM 147 over ~2 weeks. Uses a very simple phaser renderer and these asset packs from kenney.nl:

Code overview:

Javascript generator code in src:

  • src/tests/: code entrypoints + regression tests. Each .js file here generates a corresponding .html file (and webpack .js file) in build/. To run these tests use ./run.sh <filename-without-the-js-extension> from the root directory.
  • src/generators: room generators, etc
  • src/core/: utils, incl a 2d array implementation and code to draw and work with isometric tiles in the specific format that we're using, ie. 256x512 images containing individual 256x128 tiles centered at (128, 64). No, we did not use http://rotates.org/phaser/iso/ at all b/c we're stupid (and writing this from scratch was more fun) ¯_(ツ)_/¯
  • src/astar/: A* pathfinding impl
  • src/generated/: code generated by tools/: assets.js (generated code to load all .png assets based off asset manifests in build/assets/ and assets/asset_config.js), and config.json (just contains the values in config/config.yaml, but in a way that can be imported into the webpack build and w/out adding additional libraries for .yaml loading)

Assets + asset configuration file in assets:

  • zipped kenney.nl asset packs (unzipped to build/assets/)
  • assets/asset_config.yaml:
    • tells which kind of asset perspective to use (values: { Isometric, Angled })
    • defines asset categories (eg. walls, floors, objects, stairs) along w/ a list of assets. Each asset (eg. stoneWall) corresponds to all facings / orientations of that asset (eg. stoneWall_N, stoneWall_E, etc)

Python backend, server, and tools in tools:

  • tools/extract_assets.py: extracts, summarizes, and can preprocess (TBD) isometric kenney.nl asset packs stored inassets/. Notably, this generates asset info (as yaml files) in build/assets.yaml and build/assets/<asset-pack>.yaml for isometric oriented tiles (note: sprites for N, S, E, W directions), and sprite animations (TBD). These .yaml files can be used by...
  • tools/rebuild_phaser_renderer.py: assembles a phaser game from an html template with jinja2 markup (templates/phaser_template.html), javascript files (TBD), and generated javascript (TBD); the latter of which should handle asset loading from data in build/assets.yaml, etc. The output of this is build/example.html.
  • tools/simple_server.py: runs a small http server to serve / display html + js files (generated by rebuild_phaser_renderer.py + webpack), and assets (unpacked .pngs from extract_assets.py). Uses watchdog to detect file changes + re-run the python + webpack pipeline, and webbrowser (builtin) to rebuild + reopen / browse to an observed js file (note: corresponds to the single optional argument to ./run.sh [<file>], eg. ./run.sh barrel). The server will by default run at localhost:5000 (or whatever PORT is set to in simple_server.py), and will attempt to reconnect at consecutive addresses (ie. localhost:5001, localhost:5002, etc), for up to N (default 10-20) tries, iff the port is blocked. As the port isn't necessarily constant, the currently active server URL is currently written to build/server.yaml, for ease of development.
  • note that everything in build/ is explicitely not tracked by git + will be built from code, raw assets, and config files using python scripts in tools/. Do NOT attempt to modify or commit anything in build/, as everything in that directory is machine generated from other sources.

Tooling (please install these!)

To install anaconda within sublime:

  • press shift+ctrl/cmd+p => type "install" => press enter on "Package Control: install package".
  • type "anaconda", select, and press enter to install the anaconda python plugin.

Code formatting, etc:

Python code must be:

Note that with the anaconda package, invalid code formatting will be shown in sublime using white boxes. You can fix most formatting errors by typing <shift+ctrl/cmd+p> => "autof" => press enter on "Anaconda: Autoformat PEP8 Errors". This will also show the keybinding for this command, if you want to use that instead.

About

License:MIT License


Languages

Language:JavaScript 73.9%Language:Python 25.0%Language:HTML 0.9%Language:Shell 0.2%