feat: draw dominos
8
Makefile
|
@ -1,6 +1,12 @@
|
|||
CFLAGS := -Wall -Wextra
|
||||
LDFLAGS = -lglfw -lm -lGL -I./glad/include
|
||||
|
||||
domino-dungeon: main.c game.c game.h glad/src/glad.c
|
||||
domino-dungeon: main.c game.c game.h glad/src/glad.c assets/dominos.h
|
||||
$(CC) ${CFLAGS} ${LDFLAGS} -o $@ $^
|
||||
|
||||
assets/dominos.h: src_build/domino_assets
|
||||
$< assets/1bit_dominoes_asset_pack/white_and_blue_dominoes.png > $@
|
||||
|
||||
src_build/domino_assets: src_build/domino_assets.c
|
||||
$(CC) -o $@ $^ -lm
|
||||
|
||||
|
|
|
@ -91,3 +91,8 @@ For open source projects, say how it is licensed.
|
|||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
|
||||
|
||||
## Attribution
|
||||
|
||||
- https://actuallykron.itch.io/dominoes-pack
|
||||
|
|
39
assets/1bit_dominoes_asset_pack/Licence & Credits.txt
Normal file
|
@ -0,0 +1,39 @@
|
|||
|
||||
|
||||
░█████╗░██████╗░███████╗██████╗░██╗████████╗
|
||||
██╔══██╗██╔══██╗██╔════╝██╔══██╗██║╚══██╔══╝
|
||||
██║░░╚═╝██████╔╝█████╗░░██║░░██║██║░░░██║░░░
|
||||
██║░░██╗██╔══██╗██╔══╝░░██║░░██║██║░░░██║░░░
|
||||
╚█████╔╝██║░░██║███████╗██████╔╝██║░░░██║░░░
|
||||
░╚════╝░╚═╝░░╚═╝╚══════╝╚═════╝░╚═╝░░░╚═╝░░░
|
||||
|
||||
|
||||
Created By: actuallyKron
|
||||
Download from: actuallykron.itch.io/free-emoji-pack
|
||||
|
||||
Itch.io: actuallykron.itch.io
|
||||
Twitter: @actuallyKron
|
||||
Instagram: @actuallyKron
|
||||
|
||||
This is pack #3 out of #52
|
||||
Check out the other packs here (they're released weekly)
|
||||
itch.io/c/1824146/weekly-asset-pack-collection
|
||||
|
||||
██╗░░░░░██╗░█████╗░███████╗███╗░░██╗░█████╗░███████╗
|
||||
██║░░░░░██║██╔══██╗██╔════╝████╗░██║██╔══██╗██╔════╝
|
||||
██║░░░░░██║██║░░╚═╝█████╗░░██╔██╗██║██║░░╚═╝█████╗░░
|
||||
██║░░░░░██║██║░░██╗██╔══╝░░██║╚████║██║░░██╗██╔══╝░░
|
||||
███████╗██║╚█████╔╝███████╗██║░╚███║╚█████╔╝███████╗
|
||||
╚══════╝╚═╝░╚════╝░╚══════╝╚═╝░░╚══╝░╚════╝░╚══════╝
|
||||
|
||||
|
||||
Licenced under CC0 1.0 Universal (CC0 1.0)
|
||||
https://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
- You can use these assets for personal or commercial use
|
||||
- You can Modify these assets
|
||||
- Credit is not required but is very much appreciated
|
||||
|
||||
*** Please refrain from redistribute this assest pack ***
|
||||
|
||||
More info @ https://creativecommons.org/publicdomain/zero/1.0/
|
BIN
assets/1bit_dominoes_asset_pack/black_and_green_dominoes .png
Normal file
After Width: | Height: | Size: 901 B |
BIN
assets/1bit_dominoes_asset_pack/black_and_white_dominoes.png
Normal file
After Width: | Height: | Size: 940 B |
BIN
assets/1bit_dominoes_asset_pack/black_and_yellow_dominoes.png
Normal file
After Width: | Height: | Size: 986 B |
BIN
assets/1bit_dominoes_asset_pack/blanks.png
Normal file
After Width: | Height: | Size: 486 B |
BIN
assets/1bit_dominoes_asset_pack/blue_and_red_deominoes.png
Normal file
After Width: | Height: | Size: 941 B |
BIN
assets/1bit_dominoes_asset_pack/brown_and_yellow.png
Normal file
After Width: | Height: | Size: 946 B |
BIN
assets/1bit_dominoes_asset_pack/cheery_tree_dominoes.png
Normal file
After Width: | Height: | Size: 940 B |
BIN
assets/1bit_dominoes_asset_pack/dark_red_dominoes.png
Normal file
After Width: | Height: | Size: 934 B |
BIN
assets/1bit_dominoes_asset_pack/red_and_peach_dominoes.png
Normal file
After Width: | Height: | Size: 941 B |
BIN
assets/1bit_dominoes_asset_pack/tree_bark_dominoes.png
Normal file
After Width: | Height: | Size: 940 B |
BIN
assets/1bit_dominoes_asset_pack/white_and_blue_dominoes.png
Normal file
After Width: | Height: | Size: 945 B |
22
game.c
|
@ -1,13 +1,17 @@
|
|||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "game.h"
|
||||
#include "assets/dominos.h"
|
||||
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#define CLAMP(x,a,b) (MIN(MAX(x,a),b))
|
||||
|
||||
int mouse_x = 0, mouse_y = 0;
|
||||
int eyes_front = 0, eyes_back = 0;
|
||||
|
||||
void key_callback(int key, int scancode, int action, int mods) {
|
||||
if (action != GLFW_PRESS) return;
|
||||
|
@ -25,11 +29,23 @@ void cursor_position_callback(int xpos, int ypos) {
|
|||
}
|
||||
|
||||
void mouse_button_callback(int button, int action, int mods) {
|
||||
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {}
|
||||
printf("click!\n");
|
||||
|
||||
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
|
||||
if (++eyes_back >= NUM_DOMINO_X) {
|
||||
eyes_back = 0;
|
||||
eyes_front = (eyes_front+1)%NUM_DOMINO_Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_image(decoded_image img) {
|
||||
// for (int i = 0; i < img.buf_size; i++) img.buf[i] = i;
|
||||
img.buf[CLAMP(mouse_y, 0, img.height) * img.width +
|
||||
CLAMP(mouse_x, 0, img.width)] = -1;
|
||||
|
||||
for (int y = 0; y < DOMINO_HEIGHT; y++) {
|
||||
for (int x = 0; x < DOMINO_WIDTH; x++) {
|
||||
img.buf[(CLAMP(mouse_y, 0, img.height) + y) * img.width + CLAMP(mouse_x, 0, img.width) + x] =
|
||||
(*(uint32_t*) &domino[eyes_front][eyes_back][y * DOMINO_WIDTH * BYTES_PER_PIXEL + x * BYTES_PER_PIXEL]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
60
src_build/domino_assets.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include <stdio.h>
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
#define NUM_DOMINO_X 7
|
||||
#define NUM_DOMINO_Y 6
|
||||
#define DOMINO_WIDTH 23
|
||||
#define DOMINO_HEIGHT 12
|
||||
#define START_X 2
|
||||
#define START_Y 2
|
||||
#define MARGIN_X 9
|
||||
#define MARGIN_Y 4
|
||||
|
||||
void print_domino(unsigned char *data, int width, int n, int posx, int posy) {
|
||||
printf(" {");
|
||||
for (int y = 0; y < DOMINO_HEIGHT; y++) {
|
||||
for (int x = 0; x < DOMINO_WIDTH; x++) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
printf("%3d, ", data[(y + posy) * width * n + (x + posx) * n + i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("},\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int x,y,n;
|
||||
if (argc != 2) return 1;
|
||||
|
||||
unsigned char *data = stbi_load(argv[1], &x, &y, &n, 0);
|
||||
// n = n < 3 ? n : 3;
|
||||
|
||||
printf("#define NUM_DOMINO_X %d\n", NUM_DOMINO_X );
|
||||
printf("#define NUM_DOMINO_Y %d\n", NUM_DOMINO_Y );
|
||||
printf("#define DOMINO_WIDTH %d\n", DOMINO_WIDTH );
|
||||
printf("#define DOMINO_HEIGHT %d\n", DOMINO_HEIGHT);
|
||||
printf("#define BYTES_PER_PIXEL %d\n", n);
|
||||
|
||||
printf("unsigned char domino[%d][%d][%d] = {\n",
|
||||
NUM_DOMINO_Y,
|
||||
NUM_DOMINO_X,
|
||||
DOMINO_WIDTH * DOMINO_HEIGHT * n
|
||||
);
|
||||
|
||||
for (int domino_y = 0; domino_y < NUM_DOMINO_Y; domino_y++) {
|
||||
printf(" {\n");
|
||||
for (int domino_x = 0; domino_x < NUM_DOMINO_X; domino_x++) {
|
||||
print_domino(
|
||||
data, x, n,
|
||||
START_X + domino_x * (DOMINO_WIDTH + MARGIN_X),
|
||||
START_Y + domino_y * (DOMINO_HEIGHT + MARGIN_Y)
|
||||
);
|
||||
}
|
||||
printf(" },\n");
|
||||
}
|
||||
|
||||
printf("};\n");
|
||||
|
||||
return 0;
|
||||
}
|