feat: print description
This commit is contained in:
parent
4f478efc65
commit
0ac20b711b
|
@ -46,7 +46,7 @@ uint32_t characters[96] = {
|
||||||
0b111001000011100100001000000000, // F
|
0b111001000011100100001000000000, // F
|
||||||
0b011001000010000101000110000000, // G
|
0b011001000010000101000110000000, // G
|
||||||
0b101001010011100101001010000000, // H
|
0b101001010011100101001010000000, // H
|
||||||
0b111000100001000010001110000000, // I
|
0b011100010000100001000111000000, // I
|
||||||
0b111000010000100101000110000000, // J
|
0b111000010000100101000110000000, // J
|
||||||
0b101001010011000101001010000000, // K
|
0b101001010011000101001010000000, // K
|
||||||
0b100001000010000100001110000000, // L
|
0b100001000010000100001110000000, // L
|
||||||
|
@ -78,7 +78,7 @@ uint32_t characters[96] = {
|
||||||
0b011000100011100010000100000000, // f
|
0b011000100011100010000100000000, // f
|
||||||
0b000001110010100111000010011100, // g
|
0b000001110010100111000010011100, // g
|
||||||
0b100001000011100101001010000000, // h
|
0b100001000011100101001010000000, // h
|
||||||
0b100000000010000100001100000000, // i
|
0b010000000001000010000110000000, // i
|
||||||
0b010000000001000010000100011000, // j
|
0b010000000001000010000100011000, // j
|
||||||
0b100001000010100110001010000000, // k
|
0b100001000010100110001010000000, // k
|
||||||
0b110000100001000010001110000000, // l
|
0b110000100001000010001110000000, // l
|
||||||
|
|
84
game.c
84
game.c
|
@ -184,34 +184,33 @@ void mouse_button_callback(int button, int action, int mods) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() {
|
void init(struct image canvas) {
|
||||||
|
camera_x = canvas.width / 2;
|
||||||
|
camera_y = canvas.height / 2;
|
||||||
|
|
||||||
bricks_append(
|
bricks_append(
|
||||||
&bricks,
|
&bricks,
|
||||||
(struct brick) {
|
(struct brick) {
|
||||||
.front = {.x = 10, .y = 5, .val = 3},
|
.front = {.x = 0, .y = 0, .val = 3},
|
||||||
.back = {.x = 11, .y = 5, .val = 2},
|
.back = {.x = 1, .y = 0, .val = 2},
|
||||||
}
|
|
||||||
);
|
|
||||||
bricks_append(
|
|
||||||
&bricks,
|
|
||||||
(struct brick) {
|
|
||||||
.front = {.x = 12, .y = 5, .val = 2},
|
|
||||||
.back = {.x = 13, .y = 5, .val = 5},
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
hand_count = 3;
|
hand[hand_count++] = (struct brick) {
|
||||||
hand[0] = (struct brick) {
|
.front = {.val = 0},
|
||||||
.front = {.x = 12, .y = 5, .val = 0},
|
.back = {.val = 3},
|
||||||
.back = {.x = 13, .y = 5, .val = 3},
|
|
||||||
};
|
};
|
||||||
hand[1] = (struct brick) {
|
hand[hand_count++] = (struct brick) {
|
||||||
.front = {.x = 12, .y = 5, .val = 4},
|
.front = {.val = 4},
|
||||||
.back = {.x = 13, .y = 5, .val = 1},
|
.back = {.val = 1},
|
||||||
};
|
};
|
||||||
hand[2] = (struct brick) {
|
hand[hand_count++] = (struct brick) {
|
||||||
.front = {.x = 12, .y = 5, .val = 2},
|
.front = {.val = 2},
|
||||||
.back = {.x = 13, .y = 5, .val = 5},
|
.back = {.val = 5},
|
||||||
|
};
|
||||||
|
hand[hand_count++] = (struct brick) {
|
||||||
|
.front = {.val = 2},
|
||||||
|
.back = {.val = 5},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,12 +224,7 @@ void draw( struct image canvas, struct image texture, size_t xpos, size_t ypos,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void draw_glyph( struct image canvas, uint32_t glyph, size_t xpos, size_t ypos, struct color color) {
|
||||||
draw_character(
|
|
||||||
struct image canvas,
|
|
||||||
char *character,
|
|
||||||
size_t xpos, size_t ypos
|
|
||||||
) {
|
|
||||||
struct image texture = {
|
struct image texture = {
|
||||||
.width = 5,
|
.width = 5,
|
||||||
.height = 6,
|
.height = 6,
|
||||||
|
@ -238,28 +232,27 @@ draw_character(
|
||||||
.buf = (uint32_t[30]) {0}
|
.buf = (uint32_t[30]) {0}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; character[i]; i++) {
|
texture.buf = (uint32_t[30]) {0};
|
||||||
const uint32_t bitmask = characters[character[i] - ' '];
|
|
||||||
texture.buf = (uint32_t[30]) {0};
|
|
||||||
|
|
||||||
for (size_t y = 0; y < texture.height; y++) {
|
for (size_t y = 0; y < texture.height; y++) {
|
||||||
for (size_t x = 0; x < texture.width; x++) {
|
for (size_t x = 0; x < texture.width; x++) {
|
||||||
if ((bitmask >> ((texture.height - y - 1) * texture.width + (texture.width - x - 1))) & 1) {
|
if ((glyph >> ((texture.height - y - 1) * texture.width + (texture.width - x - 1))) & 1) {
|
||||||
texture.buf[y * texture.width + x] = -1;
|
texture.color[y * texture.width + x] = color;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
draw(canvas, texture, xpos + i * texture.width, ypos, 0);
|
}
|
||||||
|
draw(canvas, texture, xpos, ypos, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(struct image canvas, char *string, size_t xpos, size_t ypos, struct color color) {
|
||||||
|
for (size_t i = 0; string[i]; i++) {
|
||||||
|
uint32_t glyph = characters[string[i] - ' '];
|
||||||
|
draw_glyph(canvas, glyph, xpos + i * 5, ypos, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//void
|
|
||||||
//draw_text(
|
|
||||||
//
|
|
||||||
//)
|
|
||||||
|
|
||||||
void render(struct image canvas) {
|
void render(struct image canvas) {
|
||||||
for (size_t i = 0; i < canvas.bufsize; i++) canvas.buf[i] = i;
|
for (size_t i = 0; i < canvas.bufsize; i++) canvas.buf[i] = 0;
|
||||||
|
|
||||||
// domino playground
|
// domino playground
|
||||||
for (size_t i = 0; i < bricks.count; i++) {
|
for (size_t i = 0; i < bricks.count; i++) {
|
||||||
|
@ -280,13 +273,20 @@ void render(struct image canvas) {
|
||||||
draw(canvas, red_and_peach_dominoes[b->back.val][b->front.val], b->front.x, b->front.y, b->front.vertical);
|
draw(canvas, red_and_peach_dominoes[b->back.val][b->front.val], b->front.x, b->front.y, b->front.vertical);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
draw_glyph(canvas, (uint32_t) 0b00011000111001100010000100011100, 50, 50, (struct color) {255, 255, 0, 255});
|
||||||
|
|
||||||
// active
|
// active
|
||||||
if (has_active) {
|
if (has_active) {
|
||||||
draw(canvas, red_and_peach_dominoes[active.back.val][active.front.val], CLAMP(mouse_x + active.front.x, 0, canvas.width), CLAMP(mouse_y + active.front.y, 0, canvas.height), active.front.vertical);
|
draw(canvas, red_and_peach_dominoes[active.back.val][active.front.val], CLAMP(mouse_x + active.front.x, 0, canvas.width), CLAMP(mouse_y + active.front.y, 0, canvas.height), active.front.vertical);
|
||||||
}
|
}
|
||||||
|
|
||||||
// character
|
// character
|
||||||
draw_character(canvas, "Hallo Welt", 50, 20); // debugging
|
char title[] = "domino dungeon";
|
||||||
|
char inventory[] = "Inventory";
|
||||||
|
// print(canvas, title, (canvas.width - (sizeof(title)-1) * 5) / 2, 5, (struct color) {255, 255, 255, 255});
|
||||||
|
print(canvas, inventory, (canvas.width - (sizeof(inventory)-1) * 5) / 2, canvas.height - DOMINO_WIDTH - 10, (struct color) {255, 255, 255, 255});
|
||||||
|
print(canvas, "Drag Dominos from your inventory onto the chain to", 3, 2, (struct color) {255, 255, 255, 255});
|
||||||
|
print(canvas, "reach the goal. Press [R] to rotate", 3, 9, (struct color) {255, 255, 255, 255});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
main.c
6
main.c
|
@ -22,8 +22,8 @@ unsigned int VAO;
|
||||||
extern void key_callback(int key, int scancode, int action, int mods);
|
extern void key_callback(int key, int scancode, int action, int mods);
|
||||||
extern void cursor_position_callback(int xpos, int ypos);
|
extern void cursor_position_callback(int xpos, int ypos);
|
||||||
extern void mouse_button_callback(int button, int action, int mods);
|
extern void mouse_button_callback(int button, int action, int mods);
|
||||||
extern void init();
|
extern void init(struct image canvas);
|
||||||
extern void render(struct image img);
|
extern void render(struct image canvas);
|
||||||
|
|
||||||
uint32_t buffer[256 * 240] = {0};
|
uint32_t buffer[256 * 240] = {0};
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ int main() {
|
||||||
glUseProgram(shader_program);
|
glUseProgram(shader_program);
|
||||||
glUniform1i(glGetUniformLocation(shader_program, "texture1"), 0);
|
glUniform1i(glGetUniformLocation(shader_program, "texture1"), 0);
|
||||||
|
|
||||||
init();
|
init(canvas);
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
emscripten_set_main_loop(loop, 0, true);
|
emscripten_set_main_loop(loop, 0, true);
|
||||||
|
|
Loading…
Reference in a new issue