diff --git a/assets.h b/assets.h index 40fca82..18d9e89 100644 --- a/assets.h +++ b/assets.h @@ -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 diff --git a/assets/background1.png b/assets/background1.png new file mode 100644 index 0000000..f49dd61 Binary files /dev/null and b/assets/background1.png differ diff --git a/assets/font.png b/assets/font.png new file mode 100644 index 0000000..93dbdbd Binary files /dev/null and b/assets/font.png differ diff --git a/assets/font2array.py b/assets/font2array.py new file mode 100644 index 0000000..f92dca4 --- /dev/null +++ b/assets/font2array.py @@ -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) diff --git a/assets/sprite_barrel.png b/assets/sprite_barrel.png new file mode 100644 index 0000000..1a636a6 Binary files /dev/null and b/assets/sprite_barrel.png differ diff --git a/assets/wall_texture10.png b/assets/wall_texture10.png new file mode 100644 index 0000000..ee77ebf Binary files /dev/null and b/assets/wall_texture10.png differ diff --git a/assets/wall_texture11.png b/assets/wall_texture11.png new file mode 100644 index 0000000..0fc3965 Binary files /dev/null and b/assets/wall_texture11.png differ diff --git a/assets/wall_texture12.png b/assets/wall_texture12.png new file mode 100644 index 0000000..9666973 Binary files /dev/null and b/assets/wall_texture12.png differ diff --git a/assets/wall_texture13.png b/assets/wall_texture13.png new file mode 100644 index 0000000..566e808 Binary files /dev/null and b/assets/wall_texture13.png differ diff --git a/assets/wall_texture2.png b/assets/wall_texture2.png new file mode 100644 index 0000000..bdaa701 Binary files /dev/null and b/assets/wall_texture2.png differ diff --git a/assets/wall_texture3.png b/assets/wall_texture3.png new file mode 100644 index 0000000..2d4b2c7 Binary files /dev/null and b/assets/wall_texture3.png differ diff --git a/assets/wall_texture4.png b/assets/wall_texture4.png new file mode 100644 index 0000000..2edf13e Binary files /dev/null and b/assets/wall_texture4.png differ diff --git a/assets/wall_texture5.png b/assets/wall_texture5.png new file mode 100644 index 0000000..a560b82 Binary files /dev/null and b/assets/wall_texture5.png differ diff --git a/assets/wall_texture6.png b/assets/wall_texture6.png new file mode 100644 index 0000000..aef64b7 Binary files /dev/null and b/assets/wall_texture6.png differ diff --git a/assets/wall_texture7.png b/assets/wall_texture7.png new file mode 100644 index 0000000..b442ab7 Binary files /dev/null and b/assets/wall_texture7.png differ diff --git a/assets/wall_texture8.png b/assets/wall_texture8.png new file mode 100644 index 0000000..afd9feb Binary files /dev/null and b/assets/wall_texture8.png differ diff --git a/assets/wall_texture9.png b/assets/wall_texture9.png new file mode 100644 index 0000000..31f7c59 Binary files /dev/null and b/assets/wall_texture9.png differ diff --git a/main.c b/main.c index 932c23a..a9a60ba 100755 --- a/main.c +++ b/main.c @@ -1010,6 +1010,62 @@ void SFG_drawMap() } y += SFG_MAP_PIXEL_SIZE; + } +} + +/** + 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++; } } @@ -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); } }