aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--assets/scripts/mainMenu.lua20
-rw-r--r--src/main.cpp61
3 files changed, 40 insertions, 49 deletions
diff --git a/Makefile b/Makefile
index d493731..64a9a6b 100644
--- a/Makefile
+++ b/Makefile
@@ -7,10 +7,10 @@ NT_SDL_TTF_DLL_LOCATION = WindowsShit/SDL2_ttf-2.24.0/x86_64-w64-mingw32/bin/SDL
NT_SDL_IMAGE_DLL_LOCATION = WindowsShit/SDL2_image-2.6.0/x86_64-w64-mingw32/bin/SDL2_image.dll
NT_SDL_MIXER_DLL_LOCATION = WindowsShit/SDL2_mixer-2.6.1/x86_64-w64-mingw32/bin/SDL2_mixer.dll
NT_LIBWINPTHREAD_LOCATION = WindowsShit/libwinpthread-1.dll
-MACOS_SDL_DYLIB_LOCATION = /opt/homebrew/opt/sdl2/lib/libSDL2.dylib
-MACOS_SDL_TTF_DYLIB_LOCATION = /opt/homebrew/opt/sdl2_ttf/lib/libSDL2_ttf.dylib
-MACOS_SDL_IMAGE_DYLIB_LOCATION = /opt/homebrew/opt/sdl2_image/lib/libSDL2_image.dylib
-MACOS_SDL_MIXER_DYLIB_LOCATION = /opt/homebrew/opt/sdl2_mixer/lib/libSDL2_mixer.dylib
+MACOS_SDL_DYLIB_LOCATION = /opt/homebrew/opt/sdl2/lib/libSDL2-2.0.0.dylib
+MACOS_SDL_TTF_DYLIB_LOCATION = /opt/homebrew/opt/sdl2_ttf/lib/libSDL2_ttf-2.0.0.dylib
+MACOS_SDL_IMAGE_DYLIB_LOCATION = /opt/homebrew/opt/sdl2_image/lib/libSDL2_image-2.0.0.dylib
+MACOS_SDL_MIXER_DYLIB_LOCATION = /opt/homebrew/opt/sdl2_mixer/lib/libSDL2_mixer-2.0.0.dylib
APP_NAME = ShowdownOfTheSticks
UNAME_S := $(shell uname -s)
diff --git a/assets/scripts/mainMenu.lua b/assets/scripts/mainMenu.lua
new file mode 100644
index 0000000..acd9e53
--- /dev/null
+++ b/assets/scripts/mainMenu.lua
@@ -0,0 +1,20 @@
+movementSpeed = 3;
+
+function Setup()
+ setBgImage("assets/backgrounds/city-background-1.png")
+end
+
+function Update()
+ if keys[getKeycodeByName("RIGHT")] or keys[getKeycodeByName("D")] then
+ movePlayer(movementSpeed, 0)
+ end
+ if keys[getKeycodeByName("LEFT")] or keys[getKeycodeByName("A")] then
+ movePlayer(movementSpeed * -1, 0)
+ end
+ if keys[getKeycodeByName("DOWN")] or keys[getKeycodeByName("S")] then
+ movePlayer(0, movementSpeed)
+ end
+ if keys[getKeycodeByName("UP")] or keys[getKeycodeByName("W")] then
+ movePlayer(0, movementSpeed * -1)
+ end
+end \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 16c88d7..f5c399d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,12 +1,16 @@
-#define SDL_MAIN_HANDLED // Prevents SDL from shitting the Windows cross-compiler and causing a "WinMain" error
+// TOTL Studios (TM)
+// Showdown of the Sticks - developed by Arslaan Pathan ([email protected])
+#include "lua/lua.hpp"
+#include <iostream>
+// Prevents SDL from shitting the Windows cross-compiler and causing a "WinMain" error
+// At least that's what I think - I'm not sure what this does but if I remove it the code won't work
+// If it ain't broke don't fix it
+#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
-#include "lua/lua.hpp"
-#include <unistd.h>
-#include <iostream>
#define WIDTH 1280
#define HEIGHT 720
@@ -18,31 +22,6 @@ SDL_Event event;
SDL_Rect rect = {WIDTH/2, HEIGHT/2, 50, 50};
SDL_Texture* background_texture = nullptr;
-// const char* bgImagePath;
-
-
-constexpr char* LUA_FILE_MAIN_MENU = R"(
-movementSpeed = 3;
-
-function Setup()
- setBgImage("assets/backgrounds/city-background-1.png")
-end
-
-function Update()
- if keys[getKeycodeByName("RIGHT")] or keys[getKeycodeByName("D")] then
- movePlayer(movementSpeed, 0)
- end
- if keys[getKeycodeByName("LEFT")] or keys[getKeycodeByName("A")] then
- movePlayer(movementSpeed * -1, 0)
- end
- if keys[getKeycodeByName("DOWN")] or keys[getKeycodeByName("S")] then
- movePlayer(0, movementSpeed)
- end
- if keys[getKeycodeByName("UP")] or keys[getKeycodeByName("W")] then
- movePlayer(0, movementSpeed * -1)
- end
-end
-)";
int l_move_rect(lua_State* L) {
int dx = luaL_checkinteger(L, 1);
@@ -54,24 +33,16 @@ int l_move_rect(lua_State* L) {
int l_keycode_from_string(lua_State* L) {
const char* keystr = luaL_checkstring(L, 1);
-
- int scancode = -2;
-
- if (strcmp(keystr, "RIGHT") == 0) scancode = SDL_SCANCODE_RIGHT;
- else if (strcmp(keystr, "LEFT") == 0) scancode = SDL_SCANCODE_LEFT;
- else if (strcmp(keystr, "UP") == 0) scancode = SDL_SCANCODE_UP;
- else if (strcmp(keystr, "DOWN") == 0) scancode = SDL_SCANCODE_DOWN;
- else if (strcmp(keystr, "D") == 0) scancode = SDL_SCANCODE_D;
- else if (strcmp(keystr, "A") == 0) scancode = SDL_SCANCODE_A;
- else if (strcmp(keystr, "S") == 0) scancode = SDL_SCANCODE_S;
- else if (strcmp(keystr, "W") == 0) scancode = SDL_SCANCODE_W;
-
- scancode += 1;
-
- lua_pushinteger(L, scancode);
+ SDL_Scancode sc = SDL_GetScancodeFromName(keystr);
+ if (sc == SDL_SCANCODE_UNKNOWN) {
+ lua_pushinteger(L, -1);
+ } else {
+ lua_pushinteger(L, sc + 1);
+ }
return 1;
}
+
int l_set_background_image(lua_State* L) {
const char* bgImagePath = luaL_checkstring(L, 1);
SDL_Surface* temp_surface = IMG_Load(bgImagePath);
@@ -123,7 +94,7 @@ int main() {
lua_register(L, "movePlayer", l_move_rect);
lua_register(L, "getKeycodeByName", l_keycode_from_string);
lua_register(L, "setBgImage", l_set_background_image);
- luaL_dostring(L, LUA_FILE_MAIN_MENU);
+ luaL_dofile(L, "assets/scripts/mainMenu.lua");
bool keys[SDL_NUM_SCANCODES] = {false};
bool running = true;