Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Using tile sets from images #1

Open
bayou-brogrammer opened this issue May 24, 2022 · 5 comments
Open

Using tile sets from images #1

bayou-brogrammer opened this issue May 24, 2022 · 5 comments

Comments

@bayou-brogrammer
Copy link

Absolutely love the library you created and makes creating rougelikes a breeze.

My question is how would one go about loading tiles from a png image like most rougelikes use some for of tile set to style their game, (if you don't want just plain ascii)

@anaseto
Copy link
Owner

anaseto commented May 24, 2022

Hi!

You have to provide a mapping from grid cells to any image format satisfying the Image interface in the standard Go library. Using, for example, the gruid-sdl driver, that would be done when defining the GetImage method for the TileManager interface.

A grid cell in gruid is a rune, along some other fields, named for what they are typically used for, like to encode some abstract color scheme or miscellaneous attributes (for things that would require special styling, like reverse or italic or any image manipulation), but they can be used to encode more complex meanings: the field names correspond to terminal ascii conventions, because even if you do tiles you usually also want an ascii version so using a compatible encoding comes handy, but the mapping gives you total freedom (if you only want tiles, you could just use some generic constants for the Attrs field encoding all the possible image combinations).

For example, Harmonist uses a mapping from grid cells to images that works as follows: a monocolor base64 encoded png image is chosen based on the rune field (and configuration options tiles vs ascii), and then it is colored on the fly depending on the color field of the corresponding grid cell, for example. Also, a custom grid cell attribute AttrInMap is used to distinguish cells that should be mapped to an image with a textual representation (like log text and status information) from cells that should be mapped to an image representing some entity on the map.

@bayou-brogrammer
Copy link
Author

Interesting! I was using Harmonist as an example repo with building my rougelike, although a good bit of it is quite advanced for starting out.

I saw that harmonist was using base64 encoded pngs and waas curious why you didnt just load from a png file each time, but that was probably simpler.

Thank you for the response! I will just have to write my own parser for my tileset I am using
terminal8x8

@anaseto
Copy link
Owner

anaseto commented May 24, 2022

Yeah, Harmonist's repository may be a bit complex in some aspects: the code is quite old and was started before I made gruid. There is also gruid-rltuto, that is much simpler as a starting example, but only does the basics, with only sdl using textual tiles.

And, true, you'll have to write your own parser for loading the tiles from a png, which should be easy enough, as the Go standard library image package provides what's needed for extracting rectangle images from a tileset.

@bayou-brogrammer
Copy link
Author

Really appreciate the responses! I come from a web development background and fell in love with rust and from there starting building rougelikes after following (https://bfnightly.bracketproductions.com/)

Somehow i am now learning Go, but I always enjoy learning new languages by attempting to do really complex things. Makes the end result more enjoyable for me.

Can't wait to see the progression of Gruid and in the future, I would love to help out if i can

@anaseto
Copy link
Owner

anaseto commented May 25, 2022

That rust roguelike tutorial is indeed very interesting and complete: the author often shared about its progress on the roguelikedev sub and clearly put a lot of work into it!

Anyway, making roguelikes is indeed a great way to learn a new programming language. Good luck with that!

As for the progression of Gruid, I don't expect much evolution in the core library (maybe small additions in ui or rl, but it should be stable overall), but more probably other external modules that build upon it (like after someone implemented some generally useful extension while making a gruid-based roguelike).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants