feat: data structure for domino blocks
This commit is contained in:
parent
1be303f6f6
commit
e7bfbbc35c
5
Makefile
5
Makefile
|
@ -1,7 +1,8 @@
|
|||
CFLAGS := -Wall -Wextra
|
||||
CFLAGS := -ggdb -Wall -Wextra
|
||||
# -fsanitize=address
|
||||
LDFLAGS = -lglfw -lm -lGL -I./glad/include
|
||||
|
||||
SOURCES = main.c game.c game.h glad/src/glad.c assets/dominos.h
|
||||
SOURCES = main.c game.c game.h glad/src/glad.c assets/dominos.h domino.c domino.h
|
||||
|
||||
domino-dungeon: ${SOURCES}
|
||||
$(CC) ${CFLAGS} ${LDFLAGS} -o $@ $^
|
||||
|
|
34
game.c
34
game.c
|
@ -1,8 +1,10 @@
|
|||
#include <GLFW/glfw3.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "game.h"
|
||||
#include "domino.h"
|
||||
#include "assets/dominos.h"
|
||||
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
|
@ -12,6 +14,8 @@
|
|||
int mouse_x = 0, mouse_y = 0;
|
||||
int eyes_front = 0, eyes_back = 0;
|
||||
|
||||
struct bricks bricks = {0};
|
||||
|
||||
void key_callback(int key, int scancode, int action, int mods) {
|
||||
if (action != GLFW_PRESS) return;
|
||||
switch (key) {
|
||||
|
@ -38,8 +42,36 @@ void mouse_button_callback(int button, int action, int mods) {
|
|||
}
|
||||
}
|
||||
|
||||
void init() {
|
||||
bricks_append(
|
||||
&bricks,
|
||||
(struct brick) {
|
||||
.front = {.x = 10, .y = 5, .val = 3},
|
||||
.back = {.x = 11, .y = 5, .val = 2},
|
||||
}
|
||||
);
|
||||
bricks_append(
|
||||
&bricks,
|
||||
(struct brick) {
|
||||
.front = {.x = 12, .y = 5, .val = 2},
|
||||
.back = {.x = 13, .y = 5, .val = 5},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void draw_image(decoded_image img) {
|
||||
for (int i = 0; i < img.buf_size; i++) img.buf[i] = i;
|
||||
for (size_t i = 0; i < img.buf_size; i++) img.buf[i] = i;
|
||||
|
||||
for (size_t i = 0; i < bricks.count; i++) {
|
||||
struct brick *b = &bricks.items.brick[i];
|
||||
|
||||
for (int y = 0; y < DOMINO_HEIGHT; y++) {
|
||||
for (int x = 0; x < DOMINO_WIDTH; x++) {
|
||||
img.buf[(b->front.y * 10 + y) * img.width + b->front.x * 10 + x] =
|
||||
(*(uint32_t*) &domino[b->front.val][b->back.val][y * DOMINO_WIDTH * BYTES_PER_PIXEL + x * BYTES_PER_PIXEL]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = 0; y < DOMINO_HEIGHT; y++) {
|
||||
for (int x = 0; x < DOMINO_WIDTH; x++) {
|
||||
|
|
3
main.c
3
main.c
|
@ -22,6 +22,7 @@ unsigned int VAO;
|
|||
extern void key_callback(int key, int scancode, int action, int mods);
|
||||
extern void cursor_position_callback(int xpos, int ypos);
|
||||
extern void mouse_button_callback(int button, int action, int mods);
|
||||
extern void init();
|
||||
extern void draw_image(decoded_image img);
|
||||
|
||||
uint32_t buffer[256 * 240] = {0};
|
||||
|
@ -251,6 +252,8 @@ int main() {
|
|||
glUseProgram(shader_program);
|
||||
glUniform1i(glGetUniformLocation(shader_program, "texture1"), 0);
|
||||
|
||||
init();
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, true);
|
||||
#else
|
||||
|
|
Loading…
Reference in a new issue