From 0e1e74a000d36801a29f6ff1b94209ffeb67dea0 Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Mon, 30 Jan 2023 15:51:45 +0100 Subject: [PATCH] - [NEW] beat() function --- lua.cpp | 7 +++++++ mini.cpp | 13 +++++++++++++ mini.h | 1 + 3 files changed, 21 insertions(+) diff --git a/lua.cpp b/lua.cpp index afe088b..457d2e5 100644 --- a/lua.cpp +++ b/lua.cpp @@ -507,6 +507,12 @@ extern "C" { return 1; } + static int cpp_beat(lua_State *L) { + int16_t beats = luaL_optnumber(L, 1, -1); + lua_pushboolean(L, beat(beats)); + return 1; + } + static int cpp_abs(lua_State *L) { float x = luaL_checknumber(L, 1); lua_pushnumber(L, abs(x)); @@ -842,6 +848,7 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_mbtnp); lua_setglobal(L, "mbtnp"); lua_pushcfunction(L,cpp_time); lua_setglobal(L, "time"); + lua_pushcfunction(L,cpp_beat); lua_setglobal(L, "beat"); lua_pushcfunction(L,cpp_abs); lua_setglobal(L, "abs"); lua_pushcfunction(L,cpp_ceil); lua_setglobal(L, "ceil"); lua_pushcfunction(L,cpp_flr); lua_setglobal(L, "flr"); diff --git a/mini.cpp b/mini.cpp index af1f27d..768179c 100644 --- a/mini.cpp +++ b/mini.cpp @@ -88,6 +88,8 @@ int8_t pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID; Mix_Music *music = NULL; Mix_Chunk *sounds[MAX_SOUNDS]; +int16_t beats, num_beats = 0; + char* get_value_from_line(char* line) { char* equal_character = strchr(line, '='); if (equal_character == NULL) return NULL; @@ -334,6 +336,8 @@ int main(int argc,char*argv[]){ } else { loop(); } + if (beats==0)beats=num_beats; + if (beats>0)beats--; key_just_pressed = 0; mouse_just_pressed = 0; pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID; @@ -943,6 +947,15 @@ float time() { return float(SDL_GetTicks())/1000.0f; } +bool beat(int16_t i) { + if (i<0) { + return beats==0; + } else { + beats=num_beats=i; + return false; + } +} + /*float abs(float x) { return SDL_fabsf(x); }*/ diff --git a/mini.h b/mini.h index 2451e74..a8d4e0b 100644 --- a/mini.h +++ b/mini.h @@ -215,6 +215,7 @@ bool mbtn(uint8_t i); bool mbtnp(uint8_t i); float time(); +bool beat(int16_t i); //float abs(float x);