diff --git a/Makefile b/Makefile index 9b6e44d..78392bf 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,11 @@ SRC := src/engine/engine.c \ OUT := build/main SNAKE_SRC := src/examples/snake.c $(SRC) SNAKE := build/snake +2048_SRC := src/examples/2048.c $(SRC) +2048 := build/2048 build: - $(CC) -o $(OUT) src/main.c $(SRC) $(INC) $(LIBS) + $(CC) -o $(OUT) -O3 -DNDEBUG src/main.c $(SRC) $(INC) $(LIBS) run: $(OUT) @@ -24,6 +26,15 @@ run-snake: clean-snake: rm $(SNAKE) +build-2048: + $(CC) -o $(2048) -O3 -DNDEBUG $(2048_SRC) $(INC) $(LIBS) + +run-2048: + $(2048) + +clean-2048: + rm $(2048) + clean: rm $(OUT) diff --git a/src/examples/2048.c b/src/examples/2048.c new file mode 100644 index 0000000..a6c449c --- /dev/null +++ b/src/examples/2048.c @@ -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; + } +} \ No newline at end of file