collision.d 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. module scripts.lua.collision;
  2. import bindbc.lua;
  3. import raylib;
  4. import variables;
  5. import graphics.effects;
  6. import std.conv;
  7. import system.debugwriteln;
  8. import system.config;
  9. import std.string;
  10. import std.algorithm;
  11. import system.init;
  12. import graphics.playback;
  13. import std.file;
  14. import graphics.collision;
  15. import audio.sfx;
  16. extern (C) nothrow int luaL_placeCollision(lua_State *L) {
  17. try {
  18. if (cast(int)luaL_checkinteger(L, 1) >= collisions.length) {
  19. collisions.length = collisions.length + cast(int)luaL_checkinteger(L, 1) + 1;
  20. }
  21. placeOBB(
  22. cast(int)luaL_checkinteger(L, 1),
  23. Vector3(
  24. luaL_checknumber(L, 2),
  25. luaL_checknumber(L, 3),
  26. luaL_checknumber(L, 4)
  27. ),
  28. Vector3(
  29. luaL_checknumber(L, 5),
  30. luaL_checknumber(L, 6),
  31. luaL_checknumber(L, 7)
  32. ),
  33. Vector3(
  34. luaL_checknumber(L, 8),
  35. luaL_checknumber(L, 9),
  36. luaL_checknumber(L, 10)
  37. ),
  38. );
  39. } catch (Exception e) {
  40. debugWriteln("Error placing obb: ", e.msg);
  41. }
  42. return 0;
  43. }
  44. extern (C) nothrow int luaL_moveCollision(lua_State *L) {
  45. if (collisions.length < cast(int)luaL_checkinteger(L, 1)) {
  46. collisions.length += 2;
  47. }
  48. collisions[cast(int)luaL_checkinteger(L, 1)].center = Vector3(
  49. luaL_checknumber(L, 2),
  50. luaL_checknumber(L, 3),
  51. luaL_checknumber(L, 4)
  52. );
  53. return 0;
  54. }
  55. extern (C) nothrow int luaL_removeAllCollisions(lua_State *L) {
  56. collisions.length = 2;
  57. return 0;
  58. }
  59. extern (C) nothrow int luaL_setPlayerCollisionIndex(lua_State *L) {
  60. playerCollisionIndex = cast(int)luaL_checkinteger(L, 1);
  61. return 0;
  62. }
  63. extern (C) nothrow int luaL_drawCollisionWires(lua_State *L) {
  64. try {
  65. for (int i = 0; i < collisions.length; i++) {
  66. drawWireframe(collisions[i], Colors.RED);
  67. }
  68. } catch (Exception e) {
  69. }
  70. return 0;
  71. }
  72. extern (C) nothrow int luaL_checkCollision(lua_State *L) {
  73. try {
  74. for (int i = 0; i < collisions.length; i++) {
  75. debugWriteln("collision index check: ", i);
  76. bool collided = checkCollisionOBBvsOBB(collisions[playerCollisionIndex], collisions[i]);
  77. if (collided == true) {
  78. lua_pushboolean(L, true);
  79. }
  80. else lua_pushboolean(L, false);
  81. }
  82. } catch (Exception e) {
  83. }
  84. return 1;
  85. }
  86. extern (C) nothrow int luaL_checkCollisionIndex(lua_State *L) {
  87. try {
  88. bool collided = checkCollisionOBBvsOBB(collisions[cast(int)luaL_checkinteger(L, 1)], collisions[cast(int)luaL_checkinteger(L, 2)]);
  89. if (collided == true) {
  90. lua_pushboolean(L, true);
  91. }
  92. else lua_pushboolean(L, false);
  93. } catch (Exception e) {
  94. }
  95. return 1;
  96. }