This commit is contained in:
Miloslav Číž 2019-10-10 21:58:46 +02:00
parent 8e266422b4
commit bbc6883717
18 changed files with 180 additions and 0 deletions

View File

@ -588,4 +588,85 @@ uint8_t SFG_backgrounds[][SFG_TEXTURE_SIZE * SFG_TEXTURE_SIZE] =
}
};
uint8_t SFG_charToFontIndex(char c)
{
if (c >= 'a' && c <= 'z')
return c - 'a';
if (c >= 'A' && c <= 'Z')
return c - 'A';
if (c >= '0' && c <= '9')
return c - '0';
switch (c)
{
case ' ': return 26; break;
case '.': return 27; break;
case ',': return 28; break;
case '!': return 29; break;
case '/': return 41; break;
case '-': return 42; break;
case '+': return 43; break;
case '(': return 44; break;
case ')': return 45; break;
case '%': return 46; break;
default: return 30; break; // "?"
}
}
/**
4x4 font, each character stored as 16 bits.
*/
SFG_PROGRAM_MEMORY uint16_t SFG_font[47] =
{
0xfaf0, // 0 "A"
0xfd70, // 1 "B"
0x6990, // 2 "C"
0xf960, // 3 "D"
0xfd90, // 4 "E"
0xfa80, // 5 "F"
0x69b0, // 6 "G"
0xf4f0, // 7 "H"
0x9f90, // 8 "I"
0x31f0, // 9 "J"
0xf4b0, // 10 "K"
0xf110, // 11 "L"
0xfc4f, // 12 "M"
0xf42f, // 13 "N"
0x6996, // 14 "O"
0xfae0, // 15 "P"
0x69b7, // 16 "Q"
0xfad0, // 17 "R"
0x5da0, // 18 "S"
0x8f80, // 19 "T"
0xf1f0, // 20 "U"
0xe1e0, // 21 "V"
0xf32f, // 22 "W"
0x9690, // 23 "X"
0xc7c0, // 24 "Y"
0xbd90, // 25 "Z"
0x0000, // 26 " "
0x0100, // 27 "."
0x0300, // 28 ","
0x0d00, // 29 "!"
0x48b4, // 30 "?"
0xf9f0, // 31 "0"
0x9f10, // 32 "1"
0xbdd0, // 33 "2"
0x9da0, // 34 "3"
0xe2f0, // 35 "4"
0xdbb0, // 36 "5"
0xfbb0, // 37 "6"
0x8bc0, // 38 "7"
0xfdf0, // 39 "8"
0xddf0, // 40 "9"
0x1680, // 41 "/"
0x2220, // 42 "-"
0x2720, // 43 "+"
0x0690, // 44 "("
0x0960, // 45 ")"
0x9249 // 46 "%"
};
#endif // guard

BIN
assets/background1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 979 B

BIN
assets/font.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

41
assets/font2array.py Normal file
View File

@ -0,0 +1,41 @@
# Python tool to convert font image to C bit array.
#
# by drummyfish
# released under CC0 1.0.
from PIL import Image
imageArray = []
paletteColors = []
paletteArray = []
image = Image.open("font.png").convert("RGB")
pixels = image.load()
column = 0
value = 0
index = 0
result = ""
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,!?0123456789/-+()%"
for x in range(image.size[0]):
if column == 4:
column = 0
value = 0
index += 1
continue
for y in range(image.size[1]):
value = value * 2 + (1 if pixels[x,y][0] < 128 else 0)
if column == 3:
result += " 0x" + hex(value)[2:].zfill(4) + ", // " + str(index) + " \"" + chars[index] + "\"\n"
column += 1
result = "{\n" + result + "}";
print(result)

BIN
assets/sprite_barrel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/wall_texture10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/wall_texture11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 927 B

BIN
assets/wall_texture12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
assets/wall_texture13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 995 B

BIN
assets/wall_texture2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/wall_texture3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
assets/wall_texture4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
assets/wall_texture5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 956 B

BIN
assets/wall_texture6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
assets/wall_texture7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
assets/wall_texture8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
assets/wall_texture9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

58
main.c
View File

@ -1013,6 +1013,62 @@ void SFG_drawMap()
}
}
/**
Draws text on screen using the bitmap font stored in assets.
*/
void SFG_drawText(
const char *text,
uint16_t x,
uint16_t y,
uint8_t size,
uint8_t color)
{
uint16_t pos = 0;
uint16_t currentX = x;
uint16_t currentY = y;
while (text[pos] != 0)
{
uint16_t character = SFG_font[SFG_charToFontIndex(text[pos])];
for (uint8_t i = 0; i < 4; ++i)
{
currentY = y;
for (uint8_t j = 0; j < 4; ++j)
{
if (character & 0x8000)
for (uint8_t k = 0; k < size; ++k)
for (uint8_t l = 0; l < size; ++l)
{
uint16_t drawX = currentX + k;
uint16_t drawY = currentY + l;
if (drawX >= 0 && drawX < SFG_GAME_RESOLUTION_X &&
drawY >= 0 && drawY < SFG_GAME_RESOLUTION_Y)
SFG_setGamePixel(drawX,drawY,color);
}
currentY += size;
character = character << 1;
}
currentX += size;
if (currentX >= SFG_GAME_RESOLUTION_X)
break;
}
currentX += size;
if (currentX >= SFG_GAME_RESOLUTION_X)
break;
pos++;
}
}
void SFG_draw()
{
if (SFG_keyPressed(SFG_KEY_MAP))
@ -1073,6 +1129,8 @@ void SFG_draw()
// substract head bob after rendering
SFG_player.camera.height -= headBobOffset;
#endif
SFG_drawText("test text!",10,20,3,7);
}
}