aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2025-06-15 11:10:31 +1200
committerArslaan Pathan <[email protected]>2025-06-15 11:10:31 +1200
commit5348dbdef1c55c076c8603bad98d20c73085d12b (patch)
tree443667e47fd88446e235e26e175cdbe0463c2598 /src
parent2e463dff8ccb0e2431a255b8623fab9cb455ce61 (diff)
downloadshowdownofthesticks-5348dbdef1c55c076c8603bad98d20c73085d12b.tar.xz
showdownofthesticks-5348dbdef1c55c076c8603bad98d20c73085d12b.zip
Add proper ground/platforms using Rects - may be swapped for textures later
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/main.cpp b/src/main.cpp
index c170abe..b2a48d9 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -54,7 +54,6 @@ SDL_Color veryDarkGrey = {30, 30, 47, 255};
const char *globalFontFile = "assets/fonts/OpenSans-Regular.ttf";
// Forward declarations
-int l_move_player(lua_State *L);
int l_keycode_from_string(lua_State *L);
int l_set_background_image(lua_State *L);
int l_queue_texture_for_render(lua_State *L);
@@ -88,6 +87,11 @@ struct QueuedText
SDL_Color color = {255, 255, 255, 255};
};
+struct QueuedRect {
+ SDL_Rect rect;
+ SDL_Color color;
+};
+
std::vector<QueuedTexture> textureList = {};
std::map<std::string, SDL_Texture *> textureCache;
@@ -96,17 +100,9 @@ std::vector<QueuedButton> buttonList = {};
std::vector<QueuedText> textList = {};
std::map<std::pair<std::string, int>, TTF_Font *> textCache;
-SDL_Rect rect = {WIDTH / 2, HEIGHT / 2, 50, 50};
-SDL_Texture *background_texture = nullptr;
+std::vector<QueuedRect> rectList = {};
-int l_move_player(lua_State *L)
-{
- int dx = luaL_checkinteger(L, 1);
- int dy = luaL_checkinteger(L, 2);
- rect.x += dx;
- rect.y += dy;
- return 0;
-}
+SDL_Texture *background_texture = nullptr;
int l_keycode_from_string(lua_State *L)
{
@@ -137,6 +133,21 @@ int l_queue_button_for_render(lua_State *L)
return 0;
}
+int l_queue_rect_for_render(lua_State* L) {
+ int x = luaL_checkinteger(L, 1);
+ int y = luaL_checkinteger(L, 2);
+ int w = luaL_checkinteger(L, 3);
+ int h = luaL_checkinteger(L, 4);
+ Uint8 r = luaL_checkinteger(L, 5);
+ Uint8 g = luaL_checkinteger(L, 6);
+ Uint8 b = luaL_checkinteger(L, 7);
+ Uint8 a = luaL_checkinteger(L, 8);
+ SDL_Rect rect = {x, y, w, h};
+ SDL_Color color = {r, g, b, a};
+ rectList.push_back({rect, color});
+ return 0;
+}
+
int l_queue_text_for_render(lua_State *L)
{
std::string text = (std::string)luaL_checkstring(L, 1);
@@ -313,7 +324,6 @@ void call_lua_function(lua_State *L, const char *func_name)
void expose_c_functions()
{
- lua_register(L, "movePlayer", l_move_player);
lua_register(L, "getKeycodeByName", l_keycode_from_string);
lua_register(L, "setBgImage", l_set_background_image);
lua_register(L, "queueTextureForRender", l_queue_texture_for_render);
@@ -322,6 +332,7 @@ void expose_c_functions()
lua_register(L, "queueTextForRender", l_queue_text_for_render);
lua_register(L, "getTextWidth", l_get_text_width);
lua_register(L, "quitGame", l_quit_game);
+ lua_register(L, "queueRectForRender", l_queue_rect_for_render);
}
int main()
@@ -479,6 +490,12 @@ int main()
}
buttonList.clear();
+ for (const auto& rect: rectList) {
+ SDL_SetRenderDrawColor(renderer, rect.color.r, rect.color.g, rect.color.b, rect.color.a);
+ SDL_RenderFillRect(renderer, &rect.rect);
+ }
+ rectList.clear();
+
for (const auto &text : textList)
{
std::pair<std::string, int> key = {text.font_file, text.font_size};