quantumde1 4 weken geleden
bovenliggende
commit
5b3cd0b4c3
7 gewijzigde bestanden met toevoegingen van 156 en 65 verwijderingen
  1. 1 0
      .gitignore
  2. BIN
      mc.glb
  3. 18 7
      source/graphics/engine.d
  4. 0 12
      source/graphics/gamelogic.d
  5. 130 33
      source/scripts/lua.d
  6. 0 2
      source/ui/menu.d
  7. 7 11
      source/variables.d

+ 1 - 0
.gitignore

@@ -27,6 +27,7 @@ a.out
 /plugins/
 sky
 *.dylib*
+capture.mp4
 res/
 /scripts/
 docs/

BIN
mc.glb


+ 18 - 7
source/graphics/engine.d

@@ -53,10 +53,13 @@ void engineLoader()
     helloScreen();
     ClearBackground(Colors.BLACK);
     EndDrawing();
-    camera.target = Vector2(screenWidth/2.0f, screenHeight/2.0f);
-    camera.offset = Vector2(screenWidth/2.0f, screenHeight/2.0f);
-    camera.rotation = 0.0f;
-    camera.zoom = 1.0f;
+    camera = Camera(
+        Vector3(0.0f, 10.0f, 8.0f),
+        Vector3(0.0f, 5.0f, 0.0f),
+        Vector3(0.0, 1.0, 0.0),
+        45.0f,
+        CameraProjection.CAMERA_PERSPECTIVE
+    );
     while (true)
     {
         switch (currentGameState)
@@ -86,16 +89,24 @@ void engineLoader()
                     }
                     BeginDrawing();
                     ClearBackground(Colors.BLACK);
-                    // main logic
-                    BeginMode2D(camera);
+
+                    /* 2D part */
+                    
+                    // background display logic
                     backgroundLogic();
+                    // character display logic
                     characterLogic();
                     // effects logic
                     effectsLogic();
-                    EndMode2D();
                     //drawing dialogs
                     dialogLogic();
+
+                    /* 3D part */
+
+                    BeginMode3D(camera);
+                    DrawGrid(10, 2);
                     luaEventLoop();
+                    EndMode3D();
                     EndDrawing();
                 }
                 break;

+ 0 - 12
source/graphics/gamelogic.d

@@ -58,18 +58,6 @@ void texturesLogic(TextureEngine[] textures) {
 
 void effectsLogic() {
     UpdateMusicStream(music);
-    if (isCameraMoving) {
-        float delta = GetFrameTime() * cameraMoveSpeed;
-        camera.target.x += (cameraTargetX - camera.target.x) * delta;
-        camera.target.y += (cameraTargetY - camera.target.y) * delta;
-        camera.zoom += (cameraTargetZoom - camera.zoom) * delta;
-
-        if (fabs(camera.target.x - cameraTargetX) < 5.0f &&
-            fabs(camera.target.y - cameraTargetY) < 5.0f &&
-            fabs(camera.zoom - cameraTargetZoom) < 0.5f) {
-            isCameraMoving = false;
-        }
-    }
     playUIAnimation(framesUI, animationAlpha);
 }
 

+ 130 - 33
source/scripts/lua.d

@@ -304,35 +304,6 @@ extern (C) nothrow int luaL_playVideo(lua_State* L)
 
 /* ui animations */
 
-extern (C) nothrow int luaL_moveCamera(lua_State *L) {
-    try {
-        oldCamera = camera;
-        float targetX = cast(float) luaL_checknumber(L, 1);
-        float targetY = cast(float) luaL_checknumber(L, 2);
-        float zoom = cast(float) luaL_optnumber(L, 3, 1.0f);
-        float speed = cast(float) luaL_optnumber(L, 4, 5.0f);
-        debugWriteln(targetX, targetY, zoom, speed);
-        cameraTargetX = targetX;
-        cameraTargetY = targetY;
-        cameraTargetZoom = zoom;
-        cameraMoveSpeed = speed;
-        isCameraMoving = true;
-    } catch (Exception e) {
-        debugWriteln(e.msg);
-    }
-    return 0;
-}
-
-extern (C) nothrow int luaL_restoreCamera(lua_State *L) {
-    camera = oldCamera;
-    return 0;
-}
-
-extern (C) nothrow int luaL_isCameraMoving(lua_State *L) {
-    lua_pushboolean(L, isCameraMoving);
-    return 1;
-}
-
 extern (C) nothrow int luaL_loadUIAnimation(lua_State *L) {
     try {
         //loads from uifx folder HPFF files, in which png textures are stored
@@ -522,6 +493,16 @@ extern (C) nothrow int luaL_isMouseButtonPressed(lua_State* L)
     }
 }
 
+extern (C) nothrow int luaL_getMouseX(lua_State *L) {
+    lua_pushnumber(L, GetMousePosition.x);
+    return 1;
+}
+
+extern (C) nothrow int luaL_getMouseY(lua_State *L) {
+    lua_pushnumber(L, GetMousePosition.y);
+    return 1;
+}
+
 extern (C) nothrow int luaL_loadScript(lua_State* L)
 {
     try
@@ -541,6 +522,48 @@ extern (C) nothrow int luaL_setGameState(lua_State *L) {
     return 0;
 }
 
+extern (C) nothrow int luaL_setCamera(lua_State *L) {
+    camera.position = Vector3(
+        luaL_checknumber(L, 1),
+        luaL_checknumber(L, 2),
+        luaL_checknumber(L, 3)
+    );
+    camera.target = Vector3(
+        luaL_checknumber(L, 4),
+        luaL_checknumber(L, 5),
+        luaL_checknumber(L, 6)
+    );
+    return 0;
+}
+
+ModelAnimation *modelAnimations;
+int animationCurrentFrame = 0;
+int animsCount = 0;
+
+extern (C) nothrow int luaL_loadModelAnimations(lua_State *L) {
+    modelAnimations = LoadModelAnimations(luaL_checkstring(L, 1), &animsCount);
+    return 0;
+}
+
+extern (C) nothrow int luaL_updateModelAnimation(lua_State *L) {
+        ModelAnimation anim = modelAnimations[cast(int)luaL_checkinteger(L, 2)];
+        int speedMultipler;
+        if (lua_gettop(L) == 3) {
+            speedMultipler = cast(int)luaL_checkinteger(L, 3);
+        } else {
+            speedMultipler = 1;
+        }
+        animationCurrentFrame = (animationCurrentFrame + speedMultipler)%anim.frameCount;
+        Model *model = cast(Model*)luaL_checkudata(L, 1, "Model");
+        UpdateModelAnimation(*model, anim, animationCurrentFrame);
+        return 0;
+}
+
+extern (C) nothrow int luaL_resetModelAnimation(lua_State *L) {
+    animationCurrentFrame = 0;
+    return 0;
+}
+
 /* raylib direct bindings for graphics */
 
 /* basic */
@@ -683,6 +706,71 @@ extern (C) nothrow int luaL_drawTextureEx(lua_State *L) {
     return 0;
 }
 
+extern (C) nothrow int luaL_loadModel(lua_State *L) {
+    const char* fileName = luaL_checkstring(L, 1);
+    Model model = LoadModel(fileName);
+    
+    Model* modelPtr = cast(Model*)lua_newuserdata(L, Model.sizeof);
+    *modelPtr = model;
+    
+    if (luaL_newmetatable(L, "Model")) {
+        lua_pushcfunction(L, &luaL_textureGC);
+        lua_setfield(L, -2, "__gc");
+    }
+    lua_setmetatable(L, -2);
+    return 1;
+}
+
+extern (C) nothrow int luaL_drawModel(lua_State *L) {
+    Model* model = cast(Model*)luaL_checkudata(L, 1, "Model");
+    float x = luaL_checknumber(L, 2);
+    float y = luaL_checknumber(L, 3);
+    float z = luaL_checknumber(L, 4);
+    float rotation = luaL_optnumber(L, 5, 0);
+    float scale = luaL_optnumber(L, 6, 1);
+    Color color = Colors.WHITE;
+    if (lua_istable(L, 6)) {
+        lua_getfield(L, 6, "r");
+        color.r = cast(ubyte)lua_tointeger(L, -1);
+        lua_pop(L, 1);
+        
+        lua_getfield(L, 6, "g");
+        color.g = cast(ubyte)lua_tointeger(L, -1);
+        lua_pop(L, 1);
+        
+        lua_getfield(L, 6, "b");
+        color.b = cast(ubyte)lua_tointeger(L, -1);
+        lua_pop(L, 1);
+        
+        lua_getfield(L, 6, "a");
+        color.a = cast(ubyte)lua_tointeger(L, -1);
+        lua_pop(L, 1);
+    }
+    DrawModelEx(
+        *model,
+        Vector3(x, y, z),
+        Vector3(0.0f, 1.0f, 0.0f),
+        rotation,
+        Vector3(scale, scale, scale),
+        color
+    );
+    return 0;
+}
+
+extern (C) nothrow int luaL_showCursor(lua_State *L) {
+    ShowCursor();
+    return 0;
+}
+
+extern (C) nothrow int luaL_hideCursor(lua_State *L) {
+    HideCursor();
+    return 0;
+}
+
+extern (C) nothrow int luaL_setMousePosition(lua_State *L) {
+    SetMousePosition(cast(int)luaL_checkinteger(L, 1), cast(int)luaL_checkinteger(L, 2));
+    return 0;
+}
 
 /* Register functions */
 
@@ -697,9 +785,6 @@ extern (C) nothrow void luaL_loader(lua_State* L)
     lua_register(L, "unloadAnimationUI", &luaL_unloadUIAnimation);
     lua_register(L, "setDialogBoxBackground", &luaL_setDialogBoxBackground);
     lua_register(L, "setDialogEndIndicator", &luaL_setDialogBoxEndIndicatorTexture);
-    lua_register(L, "moveCamera", &luaL_moveCamera);
-    lua_register(L, "restoreCamera", &luaL_restoreCamera);
-    lua_register(L, "isCameraMoving", &luaL_isCameraMoving);
     lua_register(L, "playVideo", &luaL_playVideo);
     lua_register(L, "loadMusic", &luaL_loadMusic);
     lua_register(L, "playMusic", &luaL_playMusic);
@@ -721,8 +806,14 @@ 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, "getMouseX", &luaL_getMouseX);
+    lua_register(L, "getMouseY", &luaL_getMouseY);
     lua_register(L, "setGameState", &luaL_setGameState);
-
+    lua_register(L, "setCamera", &luaL_setCamera);
+    lua_register(L, "loadModelAnimations", &luaL_loadModelAnimations);
+    lua_register(L, "updateModelAnimation", &luaL_updateModelAnimation);
+    lua_register(L, "resetModelAnimation", &luaL_resetModelAnimation);
+    
     //raylib direct bindings
     lua_register(L, "unloadFont", &luaL_unloadFont);
     lua_register(L, "loadFont", &luaL_loadFont);
@@ -737,6 +828,12 @@ extern (C) nothrow void luaL_loader(lua_State* L)
     lua_register(L, "measureTextY", &luaL_measureTextY);
     lua_register(L, "getTextureWidth", &luaL_getTextureWidth);
     lua_register(L, "getTextureHeight", &luaL_getTextureHeight);
+    lua_register(L, "loadModel", &luaL_loadModel);
+    lua_register(L, "drawModel", &luaL_drawModel);
+    lua_register(L, "showCursor", &luaL_showCursor);
+    lua_register(L, "hideCursor", &luaL_hideCursor);
+    lua_register(L, "setMousePosition", &luaL_setMousePosition);
+
     //compat
     lua_register(L, "setFont", &luaL_loadFont);
 

+ 0 - 2
source/ui/menu.d

@@ -78,11 +78,9 @@ int showMainMenu() {
         }
         UpdateMusicStream(music);
         BeginDrawing();
-        BeginMode2D(camera);
         backgroundLogic();
         effectsLogic();
         luaEventLoop();
-        EndMode2D();
         EndDrawing();
     }
     debugWriteln("menu assets unloading");

+ 7 - 11
source/variables.d

@@ -68,9 +68,7 @@ enum EngineExitCodes {
     EXIT_OK = 0,
 }
 
-Camera2D camera;
-
-Camera2D oldCamera;
+Camera3D camera;
 
 TextureEngine[] characterTextures;
 
@@ -114,20 +112,18 @@ float baseWidth;
 
 float baseHeight;
 
-float cameraTargetX = 0;
-
-float cameraTargetY = 0;
-
-float cameraTargetZoom = 1.0f;
-
-float cameraMoveSpeed = 5.0f;
-
 float frameDuration = 0.016f;
 
 float typingSpeed = 0.6f;
 
 float scale = 1.0f;
 
+float acceleration = 0.2f;
+
+float maxVelocity = 10.0f;
+
+float currentVelocity = 0.0f;
+
 /* textures */
 
 Texture2D[] framesUI;