Bladeren bron

added new functions

quantumde1 6 dagen geleden
bovenliggende
commit
6a7b351c3d
7 gewijzigde bestanden met toevoegingen van 563 en 21 verwijderingen
  1. 7 7
      conf/settings.conf
  2. BIN
      output.mp3
  3. 378 0
      source/graphics/collision.d
  4. 10 8
      source/graphics/engine.d
  5. 157 3
      source/scripts/lua.d
  6. 1 1
      source/ui/menu.d
  7. 10 2
      source/variables.d

+ 7 - 7
conf/settings.conf

@@ -1,12 +1,12 @@
-TITLE:Remember11 - Self Chapter
+TITLE:RECURSION
 MENU_SCRIPT:scripts/menu.lua
-SCRIPT:scripts/SA00.lua
+SCRIPT:scripts/main.lua
 DIALOG_END_INDICATOR:res/misc/circle.png
 DIALOG_BOX:res/misc/TEX#win_02b.PNG
 FALLBACK_FONT:res/font_en.png
 ICON:res/icon.png
-DEV_SCREEN_WIDTH:1344
-DEV_SCREEN_HEIGHT:1008
-SCREEN_WIDTH:1280
-SCREEN_HEIGHT:960
-DEFAULT_FULLSCREEN:false
+DEV_SCREEN_WIDTH:1920
+DEV_SCREEN_HEIGHT:1080
+SCREEN_WIDTH:1920
+SCREEN_HEIGHT:1080
+DEFAULT_FULLSCREEN:false

BIN
output.mp3


+ 378 - 0
source/graphics/collision.d

@@ -0,0 +1,378 @@
+module graphics.collision;
+
+import raylib;
+import raylib.raymath;
+import std.math;
+import variables;
+
+struct OBB
+{
+    Quaternion rotation;
+    Vector3 center;
+    Vector3 halfExtents;
+}
+
+void getAxes(ref const OBB obb, out Vector3 right, out Vector3 up, out Vector3 forward)
+{
+    Matrix rot = QuaternionToMatrix(obb.rotation);
+
+    right = Vector3(rot.m0, rot.m1, rot.m2);
+    up = Vector3(rot.m4, rot.m5, rot.m6);
+    forward = Vector3(rot.m8, rot.m9, rot.m10);
+}
+
+void getCorners(ref const OBB obb, out Vector3[8] corners)
+{
+    Vector3 right, up, forward;
+    getAxes(obb, right, up, forward);
+
+    right = Vector3Scale(right, obb.halfExtents.x);
+    up = Vector3Scale(up, obb.halfExtents.y);
+    forward = Vector3Scale(forward, obb.halfExtents.z);
+
+    corners[0] = Vector3Add(Vector3Add(Vector3Add(obb.center, right), up), forward);
+    corners[1] = Vector3Add(Vector3Add(Vector3Subtract(obb.center, right), up), forward);
+    corners[2] = Vector3Add(Vector3Add(Vector3Subtract(obb.center, right), up), Vector3Negate(
+            forward));
+    corners[3] = Vector3Add(Vector3Add(Vector3Add(obb.center, right), up), Vector3Negate(forward));
+
+    corners[4] = Vector3Add(Vector3Add(Vector3Add(obb.center, right), Vector3Negate(up)), forward);
+    corners[5] = Vector3Add(Vector3Add(Vector3Subtract(obb.center, right), Vector3Negate(up)), forward);
+    corners[6] = Vector3Add(Vector3Add(Vector3Subtract(obb.center, right), Vector3Negate(up)), Vector3Negate(
+            forward));
+    corners[7] = Vector3Add(Vector3Add(Vector3Add(obb.center, right), Vector3Negate(up)), Vector3Negate(
+            forward));
+}
+
+void drawWireframe(ref const OBB obb, Color color)
+{
+    Vector3[8] c;
+    getCorners(obb, c);
+
+    DrawLine3D(c[0], c[1], color);
+    DrawLine3D(c[1], c[2], color);
+    DrawLine3D(c[2], c[3], color);
+    DrawLine3D(c[3], c[0], color);
+
+    DrawLine3D(c[4], c[5], color);
+    DrawLine3D(c[5], c[6], color);
+    DrawLine3D(c[6], c[7], color);
+    DrawLine3D(c[7], c[4], color);
+
+    DrawLine3D(c[0], c[4], color);
+    DrawLine3D(c[1], c[5], color);
+    DrawLine3D(c[2], c[6], color);
+    DrawLine3D(c[3], c[7], color);
+}
+
+bool containsPoint(ref const OBB obb, Vector3 point)
+{
+    Vector3 local = Vector3Subtract(point, obb.center);
+
+    Quaternion inverseRot = QuaternionInvert(obb.rotation);
+    local = Vector3RotateByQuaternion(local, inverseRot);
+
+    return fabs(local.x) <= obb.halfExtents.x &&
+        fabs(local.y) <= obb.halfExtents.y &&
+        fabs(local.z) <= obb.halfExtents.z;
+}
+
+void projectBoundingBoxOntoAxis(ref const BoundingBox box, Vector3 axis, out float outMin, out float outMax)
+{
+    Vector3[8] corners = [
+        Vector3(box.min.x, box.min.y, box.min.z),
+        Vector3(box.max.x, box.min.y, box.min.z),
+        Vector3(box.max.x, box.max.y, box.min.z),
+        Vector3(box.min.x, box.max.y, box.min.z),
+        Vector3(box.min.x, box.min.y, box.max.z),
+        Vector3(box.max.x, box.min.y, box.max.z),
+        Vector3(box.max.x, box.max.y, box.max.z),
+        Vector3(box.min.x, box.max.y, box.max.z)
+    ];
+
+    float min = Vector3DotProduct(corners[0], axis);
+    float max = min;
+
+    for (int i = 1; i < 8; ++i)
+    {
+        float projection = Vector3DotProduct(corners[i], axis);
+        if (projection < min)
+            min = projection;
+        if (projection > max)
+            max = projection;
+    }
+
+    outMin = min;
+    outMax = max;
+}
+
+void projectOBBOntoAxis(ref const OBB obb, Vector3 axis, out float outMin, out float outMax)
+{
+    Vector3 right, up, forward;
+    getAxes(obb, right, up, forward);
+
+    float r =
+        fabs(Vector3DotProduct(right, axis)) * obb.halfExtents.x +
+        fabs(Vector3DotProduct(up, axis)) * obb.halfExtents.y +
+        fabs(
+            Vector3DotProduct(forward, axis)) * obb.halfExtents.z;
+
+    float centerProj = Vector3DotProduct(obb.center, axis);
+    outMin = centerProj - r;
+    outMax = centerProj + r;
+}
+
+bool checkCollisionBoundingBoxVsOBB(ref const BoundingBox box, ref const OBB obb)
+{
+    Vector3[3] aabbAxes = [
+        Vector3(1, 0, 0),
+        Vector3(0, 1, 0),
+        Vector3(0, 0, 1)
+    ];
+
+    Vector3[3] obbAxes;
+    getAxes(obb, obbAxes[0], obbAxes[1], obbAxes[2]);
+
+    Vector3[15] testAxes;
+    int axisCount = 0;
+
+    for (int i = 0; i < 3; i++)
+        testAxes[axisCount++] = aabbAxes[i];
+
+    for (int i = 0; i < 3; i++)
+        testAxes[axisCount++] = obbAxes[i];
+
+    for (int i = 0; i < 3; i++)
+    {
+        for (int j = 0; j < 3; j++)
+        {
+            Vector3 cross = Vector3CrossProduct(aabbAxes[i], obbAxes[j]);
+            if (Vector3LengthSqr(cross) > 0.000001f)
+            {
+                testAxes[axisCount++] = Vector3Normalize(cross);
+            }
+        }
+    }
+
+    for (int i = 0; i < axisCount; ++i)
+    {
+        Vector3 axis = testAxes[i];
+        float minA, maxA, minB, maxB;
+
+        projectBoundingBoxOntoAxis(box, axis, minA, maxA);
+        projectOBBOntoAxis(obb, axis, minB, maxB);
+
+        if (maxA < minB || maxB < minA)
+        {
+            return false;
+        }
+    }
+
+    return true;
+}
+
+bool checkCollisionOBBvsOBB(ref const OBB a, ref const OBB b)
+{
+    Vector3[3] axesA, axesB;
+    getAxes(a, axesA[0], axesA[1], axesA[2]);
+    getAxes(b, axesB[0], axesB[1], axesB[2]);
+
+    Vector3[15] testAxes;
+    int axisCount = 0;
+
+    for (int i = 0; i < 3; ++i)
+        testAxes[axisCount++] = axesA[i];
+
+    for (int i = 0; i < 3; ++i)
+        testAxes[axisCount++] = axesB[i];
+
+    for (int i = 0; i < 3; ++i)
+    {
+        for (int j = 0; j < 3; ++j)
+        {
+            Vector3 cross = Vector3CrossProduct(axesA[i], axesB[j]);
+            float len = Vector3Length(cross);
+            if (len > 0.0001f)
+            {
+                testAxes[axisCount++] = Vector3Scale(cross, 1.0f / len);
+            }
+        }
+    }
+
+    for (int i = 0; i < axisCount; ++i)
+    {
+        Vector3 axis = testAxes[i];
+
+        float minA, maxA, minB, maxB;
+        projectOBBOntoAxis(a, axis, minA, maxA);
+        projectOBBOntoAxis(b, axis, minB, maxB);
+
+        if (maxA < minB || maxB < minA)
+        {
+            return false;
+        }
+    }
+
+    return true;
+}
+
+RayCollision getRayCollisionOBB(Ray ray, ref const OBB obb)
+{
+    RayCollision result;
+    result.hit = false;
+    result.distance = 0;
+    result.normal = Vector3(0.0f, 0.0f, 0.0f);
+    result.point = Vector3(0.0f, 0.0f, 0.0f);
+
+    // Move ray into OBB's local space
+    Vector3 localOrigin = Vector3Subtract(ray.position, obb.center);
+    Quaternion inverseRot = QuaternionInvert(obb.rotation);
+    Vector3 localRayOrigin = Vector3RotateByQuaternion(localOrigin, inverseRot);
+    Vector3 localRayDir = Vector3RotateByQuaternion(ray.direction, inverseRot);
+
+    Vector3 boxMin = Vector3Negate(obb.halfExtents);
+    Vector3 boxMax = obb.halfExtents;
+
+    // Ray vs AABB in OBB-local space
+    float tmin = -float.infinity;
+    float tmax = float.infinity;
+    Vector3 normal = Vector3(0);
+
+    for (int i = 0; i < 3; ++i)
+    {
+        float origin;
+        float dir;
+        float min;
+        float max;
+
+        switch (i)
+        {
+        case 0:
+            origin = localRayOrigin.x;
+            dir = localRayDir.x;
+            min = boxMin.x;
+            max = boxMax.x;
+            break;
+        case 1:
+            origin = localRayOrigin.y;
+            dir = localRayDir.y;
+            min = boxMin.y;
+            max = boxMax.y;
+            break;
+        case 2:
+            origin = localRayOrigin.z;
+            dir = localRayDir.z;
+            min = boxMin.z;
+            max = boxMax.z;
+            break;
+        default:
+            assert(false);
+        }
+
+        if (fabs(dir) < 0.0001f)
+        {
+            if (origin < min || origin > max)
+                return result;
+        }
+        else
+        {
+            float ood = 1.0f / dir;
+            float t1 = (min - origin) * ood;
+            float t2 = (max - origin) * ood;
+            int axis = i;
+
+            if (t1 > t2)
+            {
+                float temp = t1;
+                t1 = t2;
+                t2 = temp;
+                axis = -axis;
+            }
+
+            if (t1 > tmin)
+            {
+                tmin = t1;
+                normal = Vector3(0);
+                switch (abs(axis))
+                {
+                case 0:
+                    normal.x = axis >= 0 ? -1.0f : 1.0f;
+                    break;
+                case 1:
+                    normal.y = axis >= 0 ? -1.0f : 1.0f;
+                    break;
+                case 2:
+                    normal.z = axis >= 0 ? -1.0f : 1.0f;
+                    break;
+                default:
+                    break;
+                }
+            }
+
+            if (t2 < tmax)
+            {
+                tmax = t2;
+            }
+
+            if (tmin > tmax)
+                return result;
+        }
+    }
+
+    // Convert result to world space
+    result.hit = true;
+    result.distance = tmin;
+    result.point = Vector3Add(ray.position, Vector3Scale(ray.direction, tmin));
+    result.normal = Vector3RotateByQuaternion(normal, obb.rotation);
+
+    return result;
+}
+
+bool checkCollisionSphereVsOBB(Vector3 sphereCenter, float radius, ref const OBB obb)
+{
+    Vector3 localCenter = Vector3Subtract(sphereCenter, obb.center);
+    Quaternion invRot = QuaternionInvert(obb.rotation);
+    localCenter = Vector3RotateByQuaternion(localCenter, invRot);
+
+    Vector3 Clamped = Vector3(
+        Clamp(localCenter.x, -obb.halfExtents.x, obb.halfExtents.x),
+        Clamp(localCenter.y, -obb.halfExtents.y, obb.halfExtents.y),
+        Clamp(localCenter.z, -obb.halfExtents.z, obb.halfExtents.z)
+    );
+
+    Vector3 worldClamped = Vector3RotateByQuaternion(Clamped, obb.rotation);
+    worldClamped = Vector3Add(worldClamped, obb.center);
+
+    float distSq = Vector3DistanceSqr(sphereCenter, worldClamped);
+    return distSq <= radius * radius;
+}
+
+void placeOBB(int index, Vector3 position, Vector3 size, Vector3 rotation) {
+    OBB newOBB;
+    newOBB.center = position;
+    newOBB.halfExtents = size;
+    newOBB.rotation = QuaternionFromEuler(
+        rotation.x * raylib.DEG2RAD,
+        rotation.y * raylib.DEG2RAD,
+        rotation.z * raylib.DEG2RAD
+    );
+    if (collisions.length <= index) {
+        collisions.length += 1;
+    }
+    collisions[index] = newOBB;
+}
+
+void removeOBB(int index) {
+    collisions = collisions[0 .. index] ~ collisions[index + 1 .. $];
+}
+
+void updatePlayerOBB(ref OBB playerOBB, Vector3 playerPosition, Vector3 modelCharacterSize, float playerRotation)
+{
+    playerOBB.center = Vector3(playerPosition.x,
+        playerPosition.y + modelCharacterSize.y / 2,
+        playerPosition.z);
+    playerOBB.halfExtents = Vector3(modelCharacterSize.x / 2,
+        modelCharacterSize.y / 2,
+        modelCharacterSize.z / 2);
+    playerOBB.rotation = QuaternionFromAxisAngle(Vector3(0, 1, 0), playerRotation * raylib.raymath.DEG2RAD);
+}

+ 10 - 8
source/graphics/engine.d

@@ -24,6 +24,7 @@ import system.abstraction;
 import variables;
 import system.cleanup;
 import std.algorithm;
+import graphics.collision;
 
 void engineLoader()
 {
@@ -53,11 +54,11 @@ void engineLoader()
     helloScreen();
     ClearBackground(Colors.BLACK);
     EndDrawing();
-    camera = Camera(
+    camera = Camera3D(
         Vector3(0.0f, 10.0f, 8.0f),
         Vector3(0.0f, 5.0f, 0.0f),
         Vector3(0.0, 1.0, 0.0),
-        45.0f,
+        90.0f,
         CameraProjection.CAMERA_PERSPECTIVE
     );
     while (true)
@@ -90,6 +91,13 @@ void engineLoader()
                     BeginDrawing();
                     ClearBackground(Colors.BLACK);
 
+                    /* 3D part */
+
+                    BeginMode3D(camera);
+                    luaEventLoop3D();
+                    EndMode3D();
+
+                    luaEventLoop2D();
                     /* 2D part */
                     
                     // background display logic
@@ -101,12 +109,6 @@ void engineLoader()
                     //drawing dialogs
                     dialogLogic();
 
-                    /* 3D part */
-
-                    BeginMode3D(camera);
-                    DrawGrid(10, 2);
-                    luaEventLoop();
-                    EndMode3D();
                     EndDrawing();
                 }
                 break;

+ 157 - 3
source/scripts/lua.d

@@ -13,6 +13,7 @@ import std.algorithm;
 import graphics.engine;
 import graphics.playback;
 import std.file;
+import graphics.collision;
 
 /* 
  * This module provides Lua bindings for various engine functionalities.
@@ -273,6 +274,11 @@ extern (C) nothrow int luaL_unloadMusic(lua_State* L)
     return 0;
 }
 
+extern (C) nothrow int luaL_setMusicVolume(lua_State *L) {
+    SetMusicVolume(music, luaL_checknumber(L, 1));
+    return 0;
+}
+
 extern (C) nothrow int luaL_playSfx(lua_State *L) {
     try {
     playSfx(to!string(luaL_checkstring(L, 1)));
@@ -493,6 +499,38 @@ extern (C) nothrow int luaL_isMouseButtonPressed(lua_State* L)
     }
 }
 
+extern (C) nothrow int luaL_isMouseButtonDown(lua_State* L)
+{
+    try
+    {
+        int keyCode = cast(int)luaL_checkinteger(L, 1);
+        bool isPressed = IsMouseButtonDown(keyCode);
+
+        double currentTime = GetTime();
+        if (isPressed && (currentTime - lastKeyPressTime) < keyPressCooldown)
+        {
+            lua_pushboolean(L, false);
+        }
+        else if (isPressed)
+        {
+            lastKeyPressTime = currentTime;
+            lua_pushboolean(L, true);
+        }
+        else
+        {
+            lua_pushboolean(L, false);
+        }
+
+        return 1;
+    }
+    catch (Exception e)
+    {
+        debugWriteln(e.msg);
+        lua_pushboolean(L, false);
+        return 1;
+    }
+}
+
 extern (C) nothrow int luaL_getMouseX(lua_State *L) {
     lua_pushnumber(L, GetMousePosition.x);
     return 1;
@@ -564,6 +602,91 @@ extern (C) nothrow int luaL_resetModelAnimation(lua_State *L) {
     return 0;
 }
 
+extern (C) nothrow int luaL_placeCollision(lua_State *L) {
+    try {
+        placeOBB(
+            cast(int)luaL_checkinteger(L, 1),
+            Vector3(
+                luaL_checknumber(L, 2),
+                luaL_checknumber(L, 3),
+                luaL_checknumber(L, 4)
+            ),
+            Vector3(
+                luaL_checknumber(L, 5),
+                luaL_checknumber(L, 6),
+                luaL_checknumber(L, 7)
+            ),
+            Vector3(
+                luaL_checknumber(L, 8),
+                luaL_checknumber(L, 9),
+                luaL_checknumber(L, 10)
+            ),
+        );
+    } catch (Exception e) {
+        debugWriteln("Error placing obb: ", e.msg);
+    }
+    return 0;
+}
+
+extern (C) nothrow int luaL_moveCollision(lua_State *L) {
+    collisions[cast(int)luaL_checkinteger(L, 1)].center = Vector3(
+        luaL_checknumber(L, 2),
+        luaL_checknumber(L, 3),
+        luaL_checknumber(L, 4)
+    );
+    return 0;
+}
+
+extern (C) nothrow int luaL_removeCollision(lua_State *L) {
+    collisions = collisions[0 .. cast(int)luaL_checkinteger(L, 1)] ~ collisions[cast(int)luaL_checkinteger(L, 1) .. $];
+    return 0;
+}
+
+extern (C) nothrow int luaL_setPlayerCollisionIndex(lua_State *L) {
+    playerCollisionIndex = cast(int)luaL_checkinteger(L, 1);
+    return 0;
+}
+
+extern (C) nothrow int luaL_drawCollisionWires(lua_State *L) {
+    try {
+        for (int i = 0; i < collisions.length; i++) {
+            drawWireframe(collisions[i], Colors.RED);
+        }
+    } catch (Exception e) {
+        
+    }
+    return 0;
+}
+
+extern (C) nothrow int luaL_checkCollision(lua_State *L) {
+    try {
+        for (int i = 0; i < collisions.length; i++) {
+            debugWriteln("collision index check: ", i);
+            bool collided = checkCollisionOBBvsOBB(collisions[playerCollisionIndex], collisions[i]);
+            if (collided == true) {
+                lua_pushboolean(L, true);
+            }
+            else lua_pushboolean(L, false);
+        }
+    } catch (Exception e) {
+
+    }
+    return 1;
+}
+
+extern (C) nothrow int luaL_checkCollisionIndex(lua_State *L) {
+    try {
+        bool collided = checkCollisionOBBvsOBB(collisions[cast(int)luaL_checkinteger(L, 1)], collisions[cast(int)luaL_checkinteger(L, 2)]);
+        if (collided == true) {
+            lua_pushboolean(L, true);
+        }
+        else lua_pushboolean(L, false);
+    } catch (Exception e) {
+
+    }
+    return 1;
+}
+
 /* raylib direct bindings for graphics */
 
 /* basic */
@@ -706,6 +829,11 @@ extern (C) nothrow int luaL_drawTextureEx(lua_State *L) {
     return 0;
 }
 
+extern (C) nothrow int luaL_drawRect(lua_State *L) {
+    DrawRectangle(cast(int)luaL_checkinteger(L, 1), cast(int)luaL_checkinteger(L, 2), cast(int)luaL_checkinteger(L, 3), cast(int)luaL_checkinteger(L, 4), Colors.WHITE);
+    return 0;
+}
+
 extern (C) nothrow int luaL_loadModel(lua_State *L) {
     const char* fileName = luaL_checkstring(L, 1);
     Model model = LoadModel(fileName);
@@ -772,6 +900,11 @@ extern (C) nothrow int luaL_setMousePosition(lua_State *L) {
     return 0;
 }
 
+extern (C) nothrow int luaL_drawFPS(lua_State *L) {
+    DrawFPS(cast(int)luaL_checkinteger(L, 1), cast(int)luaL_checkinteger(L, 2));
+    return 0;
+}
+
 /* Register functions */
 
 extern (C) nothrow void luaL_loader(lua_State* L)
@@ -790,6 +923,7 @@ extern (C) nothrow void luaL_loader(lua_State* L)
     lua_register(L, "playMusic", &luaL_playMusic);
     lua_register(L, "stopMusic", &luaL_stopMusic);
     lua_register(L, "unloadMusic", &luaL_unloadMusic);
+    lua_register(L, "setMusicVolume", &luaL_setMusicVolume);
     lua_register(L, "playSfx", &luaL_playSfx);
     lua_register(L, "stopSfx", &luaL_stopSfx);
     lua_register(L, "loadCharacter", &luaL_loadCharacter);
@@ -806,6 +940,7 @@ extern (C) nothrow void luaL_loader(lua_State* L)
     lua_register(L, "isKeyPressed", &luaL_isKeyPressed);
     lua_register(L, "isKeyDown", &luaL_isKeyDown);
     lua_register(L, "isMouseButtonPressed", &luaL_isMouseButtonPressed);
+    lua_register(L, "isMouseButtonDown", &luaL_isMouseButtonDown);
     lua_register(L, "getMouseX", &luaL_getMouseX);
     lua_register(L, "getMouseY", &luaL_getMouseY);
     lua_register(L, "setGameState", &luaL_setGameState);
@@ -813,8 +948,16 @@ extern (C) nothrow void luaL_loader(lua_State* L)
     lua_register(L, "loadModelAnimations", &luaL_loadModelAnimations);
     lua_register(L, "updateModelAnimation", &luaL_updateModelAnimation);
     lua_register(L, "resetModelAnimation", &luaL_resetModelAnimation);
+    lua_register(L, "placeCollision", &luaL_placeCollision);
+    lua_register(L, "moveCollision", &luaL_moveCollision);
+    lua_register(L, "removeCollision", &luaL_removeCollision);
+    lua_register(L, "playerCollisionIndex", &luaL_setPlayerCollisionIndex);
+    lua_register(L, "drawCollision", &luaL_drawCollisionWires);
+    lua_register(L, "checkAllCollision", &luaL_checkCollision);
+    lua_register(L, "checkSpecificCollision", &luaL_checkCollisionIndex);
     
     //raylib direct bindings
+    lua_register(L, "drawRectangle", &luaL_drawRect);
     lua_register(L, "unloadFont", &luaL_unloadFont);
     lua_register(L, "loadFont", &luaL_loadFont);
     lua_register(L, "getTime", &luaL_getTime);
@@ -833,6 +976,7 @@ extern (C) nothrow void luaL_loader(lua_State* L)
     lua_register(L, "showCursor", &luaL_showCursor);
     lua_register(L, "hideCursor", &luaL_hideCursor);
     lua_register(L, "setMousePosition", &luaL_setMousePosition);
+    lua_register(L, "drawFPS", &luaL_drawFPS);
 
     //compat
     lua_register(L, "setFont", &luaL_loadFont);
@@ -870,12 +1014,22 @@ int luaInit(string luaExec)
     return EngineExitCodes.EXIT_OK;
 }
 
-void luaEventLoop()
+void luaEventLoop2D()
+{
+    lua_getglobal(L, "EventLoop2D");
+    if (lua_pcall(L, 0, 0, 0) != LUA_OK)
+    {
+        debug debugWriteln("Error in EventLoop2D: ", to!string(lua_tostring(L, -1)));
+    }
+    lua_pop(L, 0);
+}
+
+void luaEventLoop3D()
 {
-    lua_getglobal(L, "EventLoop");
+    lua_getglobal(L, "EventLoop3D");
     if (lua_pcall(L, 0, 0, 0) != LUA_OK)
     {
-        debug debugWriteln("Error in EventLoop: ", to!string(lua_tostring(L, -1)));
+        debug debugWriteln("Error in EventLoop3D: ", to!string(lua_tostring(L, -1)));
     }
     lua_pop(L, 0);
 }

+ 1 - 1
source/ui/menu.d

@@ -80,7 +80,7 @@ int showMainMenu() {
         BeginDrawing();
         backgroundLogic();
         effectsLogic();
-        luaEventLoop();
+        luaEventLoop2D();
         EndDrawing();
     }
     debugWriteln("menu assets unloading");

+ 10 - 2
source/variables.d

@@ -5,6 +5,7 @@ import std.typecons;
 import raylib;
 import bindbc.lua;
 import system.abstraction;
+import graphics.collision;
 
 nothrow void resetAllScriptValues() {
     debugWriteln("Resetting all values!");
@@ -70,14 +71,14 @@ enum EngineExitCodes {
 
 Camera3D camera;
 
+OBB[] collisions;
+
 TextureEngine[] characterTextures;
 
 TextureEngine[] backgroundTextures;
 
 SystemSettings systemSettings;
 
-int currentGameState = 1;
-
 Font textFont;
 
 Music music;
@@ -140,12 +141,19 @@ int selectedChoice = 0;
 
 int choicePage = -1;
 
+int currentGameState = 1;
+
 int currentFrame = 0;
 
 int currentChoiceCharIndex = 0;
 
+int playerCollisionIndex = 0; //default, can be changed via setter function in graphics.collision
+
+/* ubyte values */
+
 ubyte animationAlpha = 127;
 
+
 /* lua */
 
 lua_State* L;