Added new chars, and variable width. drawStr now uses pointer notation.

This commit is contained in:
Sasha Koshka
2021-05-08 16:19:28 -04:00
parent 6b08c3ba35
commit b242999547
2 changed files with 627 additions and 30 deletions

37
main.c
View File

@@ -34,8 +34,8 @@ static int gameLoop(
SDL_Renderer*
);
static void drawChar(SDL_Renderer*, Uint8[][8], int, int, int);
static void drawStr(SDL_Renderer*, Uint8[][8], char*, int, int);
static int drawChar(SDL_Renderer*, int, int, int);
static int drawStr(SDL_Renderer*, char*, int, int);
/*
Chunk
@@ -153,8 +153,11 @@ int main() {
)) {
// For testing the font
//SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
//drawStr(renderer, font, "!\"#$%", 8, 8);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
drawStr(renderer, " !\"#$%&'()*+,-./", 0, 0);
drawStr(renderer, "0123456789:;<=>?", 0, 8);
drawStr(renderer, "@ABCDEFGHIJKLMNO", 0, 16);
drawStr(renderer, "PQRSTUVWXYZ[\\]^_", 0, 24);
SDL_PumpEvents();
@@ -725,10 +728,11 @@ static float perlin2d(float x, float y, int seed) {
/*
drawChar
Takes in a pointer to a renderer, a pointer to a font, a char,
and draws it at the specified x and y coordinates.
Takes in a pointer to a renderer, a charachter (as an int),
draws it at the specified x and y coordinates, and then returns
the charachter's width.
*/
static void drawChar(SDL_Renderer *renderer, Uint8 font[][8],
static int drawChar(SDL_Renderer *renderer,
int c, int x, int y
) {
for(int yy = 0; yy < 8; yy++) {
@@ -737,19 +741,22 @@ static void drawChar(SDL_Renderer *renderer, Uint8 font[][8],
SDL_RenderDrawPoint(renderer, x + xx, y + yy);
}
}
return font[c][8];
}
/*
drawChar
Takes in a pointer to a renderer, a pointer to a font, a char,
and draws it at the specified x and y coordinates.
drawStr
Takes in a pointer to a renderer, a string, draws it at the
specified x and y coordinates, and then returns the x position
it left off on.
*/
static void drawStr(SDL_Renderer *renderer, Uint8 font[][8],
static int drawStr(SDL_Renderer *renderer,
char *str, int x, int y
) {
for(int xx = 0; str[xx] > 0; xx++) {
drawChar(renderer, font, str[xx], x, y);
x += 8;
while(*str > 0) {
x += drawChar(renderer, *(str++), x, y);
}
return x;
}

View File

@@ -3,8 +3,8 @@
8bit ints for each row of pixels.
*/
Uint8 font[][8] = {
// NOTHING
Uint8 font[][9] = {
// NULL
{0},
// CLEAR SMILEY FACE
{
@@ -15,7 +15,9 @@ Uint8 font[][8] = {
0b10111101,
0b10011001,
0b10000001,
0b01111110
0b01111110,
9
},
// OPAQUE SMILEY FACE
{
@@ -26,7 +28,9 @@ Uint8 font[][8] = {
0b11000011,
0b11100111,
0b11111111,
0b01111110
0b01111110,
9
},
{0},
{0},
@@ -58,8 +62,12 @@ Uint8 font[][8] = {
{0},
{0},
// SPACE
{0},
// EXCLAMATION POINT
{
0,0,0,0,0,0,0,0,
4
},
// !
{
0b10000000,
0b10000000,
@@ -68,16 +76,20 @@ Uint8 font[][8] = {
0b10000000,
0,
0b10000000,
0
0,
2
},
// QUOTATION
// "
{
0b01010000,
0b01010000,
0b10100000,
0,0,0,0,0
0,0,0,0,0,
5
},
// HASH MARK
// #
{
0b01010000,
0b01010000,
@@ -86,9 +98,11 @@ Uint8 font[][8] = {
0b11111000,
0b01010000,
0b01010000,
0
0,
6
},
// DOLLAR SIGN
// $
{
0b00100000,
0b01111000,
@@ -97,9 +111,11 @@ Uint8 font[][8] = {
0b00001000,
0b11110000,
0b00100000,
0
0,
6
},
// PERCENT
// %
{
0b10001000,
0b10010000,
@@ -108,6 +124,580 @@ Uint8 font[][8] = {
0b01000000,
0b01001000,
0b10001000,
0
0,
6
},
// &
{
0b00100000,
0b01010000,
0b00100000,
0b01101000,
0b10110000,
0b10010000,
0b01101000,
0,
6
},
// '
{
0b01000000,
0b01000000,
0b10000000,
0,0,0,0,0,
3
},
// )
{
0b00110000,
0b01000000,
0b10000000,
0b10000000,
0b10000000,
0b01000000,
0b00110000,
0,
5
},
// (
{
0b11000000,
0b00100000,
0b00010000,
0b00010000,
0b00010000,
0b00100000,
0b11000000,
0,
5
},
// *
{
0, 0,
0b10010000,
0b01100000,
0b10010000,
0, 0, 0,
5
},
// +
{
0,
0b00100000,
0b00100000,
0b11111000,
0b00100000,
0b00100000,
0, 0,
6
},
// ,
{
0,0,0,0,0,
0b10000000,
0b10000000,
0b10000000,
2
},
// .
{
0,0,0,0,0,
0b10000000,
0b10000000,
0,
2
},
// -
{
0, 0, 0,
0b11111000,
0, 0, 0, 0,
6
},
// /
{
0b00001000,
0b00010000,
0b00010000,
0b00100000,
0b01000000,
0b01000000,
0b10000000,
0,
6
},
// 0
{
0b01110000,
0b10001000,
0b10011000,
0b10101000,
0b11001000,
0b10001000,
0b01110000,
0,
6
},
// 1
{
0b00100000,
0b01100000,
0b00100000,
0b00100000,
0b00100000,
0b00100000,
0b11111000,
0,
6
},
// 2
{
0b01110000,
0b10001000,
0b00001000,
0b00110000,
0b01000000,
0b10001000,
0b11111000,
0,
6
},
// 3
{
0b01110000,
0b10001000,
0b00001000,
0b00110000,
0b00001000,
0b10001000,
0b01110000,
0,
6
},
// 4
{
0b00011000,
0b00101000,
0b01001000,
0b10001000,
0b11111000,
0b00001000,
0b00001000,
0,
6
},
// 5
{
0b11111000,
0b10000000,
0b11110000,
0b00001000,
0b00001000,
0b10001000,
0b01110000,
0,
6
},
// 6
{
0b00110000,
0b01000000,
0b10000000,
0b11110000,
0b10001000,
0b10001000,
0b01110000,
0,
6
},
// 7
{
0b11111000,
0b10001000,
0b00001000,
0b00010000,
0b00100000,
0b00100000,
0b00100000,
0,
6
},
// 8
{
0b01110000,
0b10001000,
0b10001000,
0b01110000,
0b10001000,
0b10001000,
0b01110000,
0,
6
},
// 9
{
0b01110000,
0b10001000,
0b10001000,
0b01111000,
0b00001000,
0b00010000,
0b01100000,
0,
6
},
// :
{
0,
0b10000000,
0b10000000,
0, 0,
0b10000000,
0b10000000,
0,
2
},
// ;
{
0,
0b10000000,
0b10000000,
0, 0,
0b10000000,
0b10000000,
0b10000000,
2
},
// <
{
0b00010000,
0b00100000,
0b01000000,
0b10000000,
0b01000000,
0b00100000,
0b00010000,
0,
5
},
// =
{
0, 0,
0b11111000,
0, 0,
0b11111000,
0, 0,
6
},
// >
{
0b10000000,
0b01000000,
0b00100000,
0b00010000,
0b00100000,
0b01000000,
0b10000000,
0,
5
},
// ?
{
0b01110000,
0b10001000,
0b00001000,
0b00010000,
0b00100000,
0,
0b00100000,
0,
6
},
// @
{
0b01111000,
0b10000100,
0b10110100,
0b10110100,
0b10111100,
0b10000000,
0b01111000,
0,
7
},
// A
{
0b01110000,
0b10001000,
0b11111000,
0b10001000,
0b10001000,
0b10001000,
0b10001000,
0,
6
},
// B
{
0b11110000,
0b10001000,
0b11110000,
0b10001000,
0b10001000,
0b10001000,
0b11110000,
0,
6
},
// C
{
0b01110000,
0b10001000,
0b10000000,
0b10000000,
0b10000000,
0b10001000,
0b01110000,
0,
6
},
// D
{
0b11110000,
0b10001000,
0b10001000,
0b10001000,
0b10001000,
0b10001000,
0b11110000,
0,
6
},
// E
{
0b11111000,
0b10000000,
0b11100000,
0b10000000,
0b10000000,
0b10000000,
0b11111000,
0,
6
},
// F
{
0b11111000,
0b10000000,
0b11100000,
0b10000000,
0b10000000,
0b10000000,
0b10000000,
0,
6
},
// G
{
0b01111000,
0b10000000,
0b10011000,
0b10001000,
0b10001000,
0b10001000,
0b01110000,
0,
6
},
// H
{
0b10001000,
0b10001000,
0b11111000,
0b10001000,
0b10001000,
0b10001000,
0b10001000,
0,
6
},
// I
{
0b11100000,
0b01000000,
0b01000000,
0b01000000,
0b01000000,
0b01000000,
0b11100000,
0,
4
},
// J
{
0b00001000,
0b00001000,
0b00001000,
0b00001000,
0b00001000,
0b10001000,
0b01110000,
0,
6
},
// K
{
0b10001000,
0b10010000,
0b11100000,
0b10010000,
0b10001000,
0b10001000,
0b10001000,
0,
6
},
// L
{
0b10000000,
0b10000000,
0b10000000,
0b10000000,
0b10000000,
0b10000000,
0b11111000,
0,
6
},
// M
{
0b10001000,
0b11011000,
0b10101000,
0b10001000,
0b10001000,
0b10001000,
0b10001000,
0,
6
},
// N
{
0b10001000,
0b11001000,
0b10101000,
0b10011000,
0b10001000,
0b10001000,
0b10001000,
0,
6
},
// O
{
0b01110000,
0b10001000,
0b10001000,
0b10001000,
0b10001000,
0b10001000,
0b01110000,
0,
6
},
// P
{
0b11110000,
0b10001000,
0b11110000,
0b10000000,
0b10000000,
0b10000000,
0b10000000,
0,
6
},
// Q
{
0b01110000,
0b10001000,
0b10001000,
0b10001000,
0b10001000,
0b10010000,
0b01101000,
0,
6
},
// R
{
0b11110000,
0b10001000,
0b11110000,
0b10001000,
0b10001000,
0b10001000,
0b10001000,
0,
6
},
// S
{
0b01111000,
0b10000000,
0b01110000,
0b00001000,
0b00001000,
0b10001000,
0b01110000,
0,
6
}
};