From 3c399d6ea4ad3528f1845944bb6d5b00697d2c0b Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Sun, 15 Jun 2025 20:27:31 +1200 Subject: Add punch feature + knockback etc, lots of cool shit --- src/main.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index b2a48d9..24a3147 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -357,7 +357,7 @@ int main() lua_setglobal(L, "HEIGHT"); SDL_Init(SDL_INIT_EVERYTHING); - SDL_CreateWindowAndRenderer(WIDTH, HEIGHT, 0, &window, &renderer); + SDL_CreateWindowAndRenderer(WIDTH, HEIGHT, SDL_RENDERER_PRESENTVSYNC, &window, &renderer); SDL_SetWindowTitle(window, "Showdown of the Sticks"); SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); SDL_RenderSetLogicalSize(renderer, WIDTH, HEIGHT); @@ -388,6 +388,9 @@ int main() call_lua_function(L, "Setup"); + Uint32 lastFrameTime = SDL_GetTicks(); + float deltaTime = 0.0f; + while (running) { push_keys_to_lua(L, keys); @@ -395,6 +398,13 @@ int main() call_lua_function(L, "Update"); + Uint32 currentFrameTime = SDL_GetTicks(); + deltaTime = (currentFrameTime - lastFrameTime) / 1000.0f; + lastFrameTime = currentFrameTime; + + lua_pushnumber(L, deltaTime); + lua_setglobal(L, "deltaTime"); + while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) @@ -538,7 +548,7 @@ int main() textList.clear(); SDL_RenderPresent(renderer); - SDL_Delay(10); + SDL_Delay(1); } lua_close(L); -- cgit v1.2.3