game: map units combat and SDL2 render slice

This commit is contained in:
Hernâni Marques 2026-07-11 23:31:09 +02:00
parent 87d99f7007
commit 4dedf5943b
5 changed files with 228 additions and 0 deletions

44
src/main.c Normal file
View file

@ -0,0 +1,44 @@
#include "ok_game.h"
#include "ok_render.h"
#include <stdio.h>
#include <SDL.h>
#ifndef OPENKKND_VERSION
#define OPENKKND_VERSION "dev"
#endif
int main(int argc, char **argv) {
(void)argc;
(void)argv;
printf("OpenKKND %s — original genre RTS (MIT). No commercial IP assets.\n", OPENKKND_VERSION);
const int tw = 12;
if (!ok_render_init(OK_MAP_W * tw, OK_MAP_H * tw)) {
fprintf(stderr, "render init failed\n");
return 1;
}
OkGame game;
ok_game_init(&game);
Uint64 prev = SDL_GetPerformanceCounter();
const Uint64 freq = SDL_GetPerformanceFrequency();
while (game.running || true) {
SDL_Event e;
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT) goto done;
if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE) goto done;
if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_r) ok_game_init(&game);
}
Uint64 now = SDL_GetPerformanceCounter();
float dt = (float)(now - prev) / (float)freq;
prev = now;
if (dt > 0.05f) dt = 0.05f;
if (game.running) ok_game_update(&game, dt);
ok_render_draw(&game);
}
done:
ok_render_shutdown();
return 0;
}