Code Monkey home page Code Monkey logo

tiletools's Introduction

tiletools

Formerly known as tilegen.py, tiletools is a collection of tile-managing tools grouped together in a single repository.

tilegen.py

Splits big image into smaller tiles, checks MD5 signature for repeated images, and deletes them if found. After the purge, a new smaller tileset is created according to specified dimensions. Requires PIL and Python 3.10 to work. Usage is best explained by example:

tilegen.py ./sample/maniac.png -- 16x16 result 256x192

will create a 256x192 tileset called result_256x192.png composed of the original sample/maniac.png image, cut in 16x16 tiles. Identical tiles are removed if found, so the actual number of tiles may be smaller than the total number of tiles in the original. A Tiled-compatible result_map.json that uses the tileset will also be created. You can use the result prefix as the directory where both files will be created.

Now you can specify multiple images as input and this script will generate unique tiles from all of them, but it's the last image used that will create a map.json tilemap. These multiple files are separated from the rest of the parameters by a --. If no -- is found, the previous behaviour of a single input file is considered for compatibility.

Tiled with generated sample map

map.py

map.py [-h] [--version] [--room-width RW] [--room-height RH] [--max-ents MAX_ENTS] [--max-bytes MAX_BYTES] [-b] [-d DIR] [-c CONF] [--aplib] [-r] [-t] [-q] map_json id

ubox version of map.py is also included, but with the additional option -t or --transpose to encode the map in a transposed matrix layout in memory. This is necessary if your game needs to scroll the screen horizontally (you will probably need a new rendering function too). map.py creates a C or assembly version of the Tiled-compatible map.json file.

vwrap_down.py and vwrap_up.py

vwrap_up.py <input_images...> -- <output_image> <width> <step>
vwrap_down.py <input_images...> -- <output_image> <width> <step>

vwrap_{up|down}.py scripts create vertically wrapped around copies of the input_images and stack them side by side in the output file. Wrapping around is useful for pixel-level scrolling in games on the MSX1, like Konami's Pippols. width defines the output image width. If the tiles won't fit, vwrap_{up|down}.py will wrap to the next 8 lines. If step is 1, the resulting image contains 8 times the amount of input tiles. Step can be 1 (8 times), 2 (4 times) and 4 (2 times).

How to create transition tiles between two or more tiles

There are two types of tiles in a tileset:

  • horizontal aligned tiles will wrap around themselves, not considering transition tiles;
  • vertical aligned tiles will be considered as transitional tiles and vwrap_{up|down}.py will create transitional tiles between them;

You shouldn't mix vertical and horizontal tiles in the same file, because it creates unused wraping tiles.

Usage

For instance, considering a file called input.png composed of two horizontally aligned tiles:

wrapped tile (input)

calling:

vwrap_down.py input.png -- output.png 136 1

will result in the following output.png file:

wrapped tile (output)

TODO

Some tilegen.py features I may add some day:

  • Remove ImageMagick dependency;
  • Allow multiple input files;
  • Create separated tilebanks when tilesets are bigger than 256 and use the screen region to decide which tilebank to use;
  • Detection of near-identical tiles;
  • Detection of color-swapped tiles;

tiletools's People

Contributors

pvmm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

onode

tiletools's Issues

Create separate tile regions

Tilesets bigger than 256 tiles should be separated in tile regions (tileset#1 and tileset#2). This allow us to still map everything into a single byte. We can forego the last significant bit of the tile number and use screen region where its cell is (top or bottom) to decide which tileset we are referring to by using the 8th bit of the tile number. It requires replicating some tiles in both tilesets if they are used in both regions of the screen. Alternatively split the screen in left and right regions too.

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.