text: #include "Game.h"
  #include "Scripts.h"
  #include "JollyEngine.h"
  
  extern "C"
  {
      void DefaultScript(uint32_t id, float dt)
      {
          // do nothing
      }
  
      void PlayerUpdate(uint32_t id, float dt)
      {
          Jolly::Entity entity{id, g_Scene};
          Jolly::QuadComponent& quad = entity.Get<Jolly::QuadComponent>();
  
          Math::Vec4 translate{};
  
          if (g_Input->GetKeyState(Jolly::KEY_W) == Jolly::INPUT_DOWN)
              translate.y += 0.001f * dt;
  
          if (g_Input->GetKeyState(Jolly::KEY_S) == Jolly::INPUT_DOWN)
              translate.y -= 0.001f * dt;
  
          if (g_Input->GetKeyState(Jolly::KEY_A) == Jolly::INPUT_DOWN)
              translate.x -= 0.001f * dt;
  
          if (g_Input->GetKeyState(Jolly::KEY_D) == Jolly::INPUT_DOWN)
              translate.x += 0.001f * dt;
  
          Math::Translate(quad.Transform, translate);
      }
  
      void CameraUpdate(uint32_t id, float dt)
      {
          Jolly::Entity entity{id, g_Scene};
          auto& camera = entity.Get<Jolly::CameraComponent>();
  
          float dx = 0.0f;
          float dy = 0.0f;
  
          if (g_Input->GetMouseState(Jolly::MOUSE_RIGHT) == Jolly::INPUT_DOWN)
          {
              if (g_Input->GetKeyState(Jolly::KEY_W) == Jolly::INPUT_DOWN)
                  camera.Pos += camera.Front * 0.01f * dt;
  
              if (g_Input->GetKeyState(Jolly::KEY_S) == Jolly::INPUT_DOWN)
                  camera.Pos -= camera.Front * 0.01f * dt;
  
              if (g_Input->GetKeyState(Jolly::KEY_A) == Jolly::INPUT_DOWN)
                  camera.Pos -= camera.Right * 0.01f * dt;
  
              if (g_Input->GetKeyState(Jolly::KEY_D) == Jolly::INPUT_DOWN)
                  camera.Pos += camera.Right * 0.01f * dt;
  
              if (g_Input->GetKeyState(Jolly::KEY_SPACE) == Jolly::INPUT_DOWN)
                  camera.Pos += camera.Up * 0.01f * dt;
  
              if (g_Input->GetKeyState(Jolly::KEY_LSHIFT) == Jolly::INPUT_DOWN)
                  camera.Pos -= camera.Up * 0.01f * dt;
  
              dx = (g_Input->MouseX - g_Input->LastMouseX) * 0.1f;
              dy = (g_Input->MouseY - g_Input->LastMouseY) * 0.1f;
  
              camera.Yaw -= dx;
              camera.Pitch -= dy;
  
              camera.Pitch = Math::Min(camera.Pitch, +89.0f);
              camera.Pitch = Math::Max(camera.Pitch, -89.0f);
  
              camera.Yaw = Math::FCMOVL(-180.0f, camera.Yaw, camera.Yaw + 360.0f, camera.Yaw);
              camera.Yaw = Math::FCMOVG(+180.0f, camera.Yaw, camera.Yaw - 360.0f, camera.Yaw);
          }
  
          Math::Vec4 direction;
          direction.x = Math::Cos(camera.Yaw * RADIANS) * Math::Cos(camera.Pitch * RADIANS);
          direction.y = Math::Sin(camera.Pitch * RADIANS);
          direction.z = Math::Sin(camera.Yaw * RADIANS) * Math::Cos(camera.Pitch * RADIANS);
  
          direction = Math::Normalize(direction);
  
          camera.View = Math::LookAt(camera.Pos, camera.Pos + direction, Math::Vec4{ 0.0f, 1.0f, 0.0f, 0.0f },
                  camera.Front, camera.Right, camera.Up);
      }
  }
  