Path: csiph.com!aioe.org!.POSTED.xV/6gj+grSZn0+TB/DGTcw.user.gioia.aioe.org!not-for-mail From: Graeme Geldenhuys Newsgroups: comp.lang.java.programmer Subject: Game color question, with max 256 colors Date: Sun, 2 Jun 2019 00:21:53 +0100 Organization: Aioe.org NNTP Server Lines: 79 Message-ID: NNTP-Posting-Host: xV/6gj+grSZn0+TB/DGTcw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 Content-Language: en-GB X-Mozilla-News-Host: news://nntp.aioe.org:119 X-Notice: Filtered by postfilter v. 0.9.2 Xref: csiph.com comp.lang.java.programmer:38977 Hi, I'm studying a game created during Ludum Dare 22 by Notch (The creator of Minecraft). If you don't know, Ludum Dare is a competition where you have to create a game from scratch in 48 hours. Anyway, Notch purposely implemented a restricted "retro" color palette where all sprites in the spritesheet is drawn using only 4 color (white, black or 2 shades of gray). At runtime he can then manipulate the color of the sprite so the same sprite can be drawn using different colors. As for as I understand, he limited the game to 256 colors and each color channel is 4-bits. I think - not 100% sure. Anyway, he knocked up this class really fast and without commenting how it works or what it does. Is there anybody here that can figure this out? public class Color { public static int get(int a, int b, int c, int d) { return (get(d) << 24) + (get(c) << 16) + (get(b) << 8) + (get(a)); } public static int get(int d) { if (d < 0) return 255; int r = d / 100 % 10; int g = d / 10 % 10; int b = d % 10; return r * 36 + g * 6 + b; } } Usage of the above class is like this (actual snippet from the game code): if (isSwimming()) { yo += 4; int waterColor = Color.get(-1, -1, 115, 335); if (tickTime / 8 % 2 == 0) { waterColor = Color.get(-1, 335, 5, 115); } screen.render(xo + 0, yo + 3, 5 + 13 * 32, waterColor, 0); screen.render(xo + 8, yo + 3, 5 + 13 * 32, waterColor, 1); } if (attackTime > 0 && attackDir == 1) { screen.render(xo + 0, yo - 4, 6 + 13 * 32, Color.get(-1, 555, 555, 555), 0); screen.render(xo + 8, yo - 4, 6 + 13 * 32, Color.get(-1, 555, 555, 555), 1); if (attackItem != null) { attackItem.renderIcon(screen, xo + 4, yo - 4); } } From all the code I looked at, it seems the max value for the b, c and d parameters of Color.get() call is 555, and the lowest value is -1. The main thing that is puzzling me, is the get(int d) method inside the Color class. If anybody can shed some light on that, it would be greatly appreciated. If anybody was interested, the Ludum Dare 22 video (part 1 of 4) by Notch is: https://www.twitch.tv/videos/38122415 Regards, Graeme