add scaffold for 2048

This commit is contained in:
2026-10-05 03:54:40 +02:00
parent 904b8c3a29
commit f5be3992a6
2 changed files with 63 additions and 1 deletions
+12 -1
View File
@@ -8,9 +8,11 @@ SRC := src/engine/engine.c \
OUT := build/main OUT := build/main
SNAKE_SRC := src/examples/snake.c $(SRC) SNAKE_SRC := src/examples/snake.c $(SRC)
SNAKE := build/snake SNAKE := build/snake
2048_SRC := src/examples/2048.c $(SRC)
2048 := build/2048
build: build:
$(CC) -o $(OUT) src/main.c $(SRC) $(INC) $(LIBS) $(CC) -o $(OUT) -O3 -DNDEBUG src/main.c $(SRC) $(INC) $(LIBS)
run: run:
$(OUT) $(OUT)
@@ -24,6 +26,15 @@ run-snake:
clean-snake: clean-snake:
rm $(SNAKE) rm $(SNAKE)
build-2048:
$(CC) -o $(2048) -O3 -DNDEBUG $(2048_SRC) $(INC) $(LIBS)
run-2048:
$(2048)
clean-2048:
rm $(2048)
clean: clean:
rm $(OUT) rm $(OUT)
+51
View File
@@ -0,0 +1,51 @@
#include "engine.h"
// polling events every frame
void
client_poll_event()
{
SDL_Event ev = game_state->event;
if (ev.type == SDL_EVENT_QUIT) {
game_state->is_running = false;
}
if (ev.type == SDL_EVENT_KEY_DOWN) {
switch (ev.key.key) {
case SDLK_Q:
game_state->is_running = false;
break;
default:
break;
}
}
}
// performed every frame
void
client_update_framebuffer()
{
// single green demo pixel
game_state->framebuffer[0] = 0x00FF00;
put_rect(0, 0, 1100, 200, 0xFFFF00);
put_string("Hello, traveller. You have come\nto the right place!",
20, 20, 2, 2, 3, 0x000000, 0xFFFF00
);
}
int
main()
{
// initialize the engine
if (engine_init(
client_poll_event,
client_update_framebuffer
)) {
engine_start();
engine_stop();
return 0;
} else {
return 1;
}
}