added WIP-version of draw_character

This commit is contained in:
Silas Gramlich 2025-10-14 22:09:59 +02:00
parent e01184ed59
commit 57542da0da
2 changed files with 145 additions and 0 deletions

106
characters.h Normal file
View file

@ -0,0 +1,106 @@
#include <stdint.h>
#ifndef CHARACTERS_H
#define CHARACTERS_H
uint32_t characters[96] =
{0b000000000000000000000000000000, // SPACE
0b100001000010000000001000000000, // !
0b101001010000000000000000000000, // "
0b010101111101010111110101000000, // #
0b111101010011110010101111000000, // $
0b101000010001000100001010000000, // %
0b010001010001101100100110100000, // &
0b100001000000000000000000000000, // '
0b010001000010000100000100000000, // (
0b100000100001000010001000000000, // )
0b000001010001000101000000000000, // *
0b000000100011100010000000000000, // +
0b000000000000000100001000000000, // ,
0b000000000011000000000000000000, // -
0b000000000000000000001000000000, // .
0b001000010001000100001000000000, // /
0b111001010010100101001110000000, // 0
0b001000010000100001000010000000, // 1
0b111000010011100100001110000000, // 2
0b111000010011100001001110000000, // 3
0b101001010011100001000010000000, // 4
0b111001000011100001001110000000, // 5
0b111001000011100101001110000000, // 6
0b111000010000100001000010000000, // 7
0b111001010011100101001110000000, // 8
0b111001010011100001001110000000, // 9
0b000001000000000100000000000000, // :
0b000001000000000100001000000000, // ;
0b001000100010000010000010000000, // <
0b000001110000000111000000000000, // =
0b100000100000100010001000000000, // >
0b111000010001100000000100000000, // ?
0b011101010110101101100111100000, // @
0b111001010010100111001010000000, // A
0b110001010011000101001110000000, // B
0b011001000010000100000110000000, // C
0b110001010010100101001100000000, // D
0b111001000011100100001110000000, // E
0b111001000011100100001000000000, // F
0b011001000010000101000110000000, // G
0b101001010011100101001010000000, // H
0b111000100001000010001110000000, // I
0b111000010000100101000110000000, // J
0b101001010011000101001010000000, // K
0b100001000010000100001110000000, // L
0b111111010110101101011010100000, // M
0b100101101010110100101001000000, // N
0b111001010010100101001110000000, // O
0b111001010011100100001000000000, // P
0b111001010010100101001111000000, // Q
0b111001010011000101001010000000, // R
0b111001000011100001001110000000, // S
0b111000100001000010000100000000, // T
0b101001010010100101001110000000, // U
0b101001010010100101000100000000, // V
0b101011010110101101010101000000, // W
0b101001010001000101001010000000, // X
0b101001010011100010000100000000, // Y
0b111100001001100100001111000000, // Z
0b110001000010000100001100000000, // [
0b100001000001000001000010000000, // backslash
0b110000100001000010001100000000, // ]
0b010001010000000000000000000000, // ^
0b000000000000000000001110000000, // _
0b100000100000000000000000000000, // `
0b000000110010100101000111000000, // a
0b100001110010100101001110000000, // b
0b000001110010000100001110000000, // c
0b001001110010100101001110000000, // d
0b000001110010100100001110000000, // e
0b011000100011100010000100000000, // f
0b000001110010100111000010011100, // g
0b100001000011100101001010000000, // h
0b100000000010000100001100000000, // i
0b010000000001000010000100011000, // j
0b100001000010100110001010000000, // k
0b110000100001000010001110000000, // l
0b000001111010101101011010100000, // m
0b000001100010100101001010000000, // n
0b000001110010100101001110000000, // o
0b000001110010100101001110010000, // p
0b000001110010100101001110000100, // q
0b000001010011000100001000000000, // r
0b000000110011000001001100000000, // s
0b010001110001000010000110000000, // t
0b000001010010100101001110000000, // u
0b000001010010100101000100000000, // v
0b000001010110101101010101000000, // w
0b000001010010100010001010000000, // x
0b000001010010100111000010011100, // y
0b000001110000100010001110000000, // z
0b011000100011000010000110000000, // {
0b100001000010000100001000000000, // |
0b110000100001100010001100000000, // }
0b000000000001010101000000000000, // ~
0b000000000000000000000000000000 // DEL
};
#endif // CHARACTERS_H

39
game.c
View file

@ -6,6 +6,7 @@
#include "game.h"
#include "domino.h"
#include "assets/dominos.h"
#include "characters.h"
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
@ -107,6 +108,40 @@ draw(
}
}
void
draw_character(
struct image canvas,
char character,
size_t xpos, size_t ypos
) {
const int character_width = 5;
const int character_height = 6;
struct image texture;
texture.width = character_height;
texture.height = character_width;
texture.buf = (uint32_t[30]) {0};
const uint32_t bitmask = characters[character - ' '];
for (size_t i = 0; i < character_width; i++) {
for (size_t j = 0; j < character_height; j++) {
if (bitmask >> ((character_height - j - 1) * character_width + (character_width - i + 1)) & 1) {
// (0b101101 >> ((height - y - 1) * width + (width - x + 1))) & 1
texture.color[j*character_width + i] = (struct color){255, 255, 255, 0};
}
//else {
// texture.color[j*character_width + i] = (struct color){0, 0, 0, 255};
//};
}
}
draw(canvas, texture, xpos, ypos);
}
//void
//draw_text(
//
//)
void render(struct image canvas) {
for (size_t i = 0; i < canvas.bufsize; i++) canvas.buf[i] = i;
@ -128,5 +163,9 @@ void render(struct image canvas) {
if (has_active) {
draw(canvas,domino[active.back.val][active.front.val], CLAMP(mouse_x + active.front.x, 0, canvas.width), CLAMP(mouse_y + active.front.y, 0, canvas.height));
}
// character
draw_character(canvas, 'D', 50, 20); // debugging
}