Friday, May 18, 2018

algorithm - Making a symbol appear on any colour


I'm developing an RPG/roguelike-style game. Instead of having maps like:


.........
.........
....@....
...h.....

Oh look, a dwarf.


I was having solid background tiles, So sort of a tile based RPG without drawn tiles. I like the idea of having ascii tiles for creatures and things. It saves a lot of artist time. I can change the tiles so I get some kind of symbol slightly more...related? But better than having 4 directions for each separate thing.


If I did this in white, and had a snow area, you wouldn't be able to see. So make it black. As soon as you reach a dark place, you're again stuck as to where your character is. Is there an algorithm or something that can say 'this is too dark between the tile and the NPC' and change the colour to something seeable, but not going to a bright cyan from a pale pink or whatever?




Answer



Assuming you have one bright and one dark color for each character, you can check the difference in luminance, by converting the tile color and the NPC colors to HSL. Pick the NPC color with the greatest luminance difference from the tile.


If you don't want to manually assign both colors, you can simply hardcode:


if (tile_color.l > 0.5)
character_color.l = 0.1;
else
character_color.l = 0.9;

And assign HS pairs rather than RGB triplets to each character.


You could also just provide a lighter outline around dark characters, and a darker outline around light characters, all the time.



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...