Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38977
| From | Graeme Geldenhuys <graemeg@example.net> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Game color question, with max 256 colors |
| Date | 2019-06-02 00:21 +0100 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <qcv1ae$1670$1@gioia.aioe.org> (permalink) |
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
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
Game color question, with max 256 colors Graeme Geldenhuys <graemeg@example.net> - 2019-06-02 00:21 +0100
Re: Game color question, with max 256 colors Andreas Leitgeb <avl@logic.at> - 2019-06-02 14:16 +0000
Re: Game color question, with max 256 colors Graeme Geldenhuys <graemeg@example.net> - 2019-06-05 17:53 +0100
csiph-web