collision.d 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.abstraction;
  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. placeOBB(
  19. cast(int)luaL_checkinteger(L, 1),
  20. Vector3(
  21. luaL_checknumber(L, 2),
  22. luaL_checknumber(L, 3),
  23. luaL_checknumber(L, 4)
  24. ),
  25. Vector3(
  26. luaL_checknumber(L, 5),
  27. luaL_checknumber(L, 6),
  28. luaL_checknumber(L, 7)
  29. ),
  30. Vector3(
  31. luaL_checknumber(L, 8),
  32. luaL_checknumber(L, 9),
  33. luaL_checknumber(L, 10)
  34. ),
  35. );
  36. } catch (Exception e) {
  37. debugWriteln("Error placing obb: ", e.msg);
  38. }
  39. return 0;
  40. }
  41. extern (C) nothrow int luaL_moveCollision(lua_State *L) {
  42. collisions[cast(int)luaL_checkinteger(L, 1)].center = Vector3(
  43. luaL_checknumber(L, 2),
  44. luaL_checknumber(L, 3),
  45. luaL_checknumber(L, 4)
  46. );
  47. return 0;
  48. }
  49. extern (C) nothrow int luaL_removeCollision(lua_State *L) {
  50. collisions = collisions[0 .. cast(int)luaL_checkinteger(L, 1)] ~ collisions[cast(int)luaL_checkinteger(L, 1) .. $];
  51. return 0;
  52. }
  53. extern (C) nothrow int luaL_setPlayerCollisionIndex(lua_State *L) {
  54. playerCollisionIndex = cast(int)luaL_checkinteger(L, 1);
  55. return 0;
  56. }
  57. extern (C) nothrow int luaL_drawCollisionWires(lua_State *L) {
  58. try {
  59. for (int i = 0; i < collisions.length; i++) {
  60. drawWireframe(collisions[i], Colors.RED);
  61. }
  62. } catch (Exception e) {
  63. }
  64. return 0;
  65. }
  66. extern (C) nothrow int luaL_checkCollision(lua_State *L) {
  67. try {
  68. for (int i = 0; i < collisions.length; i++) {
  69. debugWriteln("collision index check: ", i);
  70. bool collided = checkCollisionOBBvsOBB(collisions[playerCollisionIndex], collisions[i]);
  71. if (collided == true) {
  72. lua_pushboolean(L, true);
  73. }
  74. else lua_pushboolean(L, false);
  75. }
  76. } catch (Exception e) {
  77. }
  78. return 1;
  79. }
  80. extern (C) nothrow int luaL_checkCollisionIndex(lua_State *L) {
  81. try {
  82. bool collided = checkCollisionOBBvsOBB(collisions[cast(int)luaL_checkinteger(L, 1)], collisions[cast(int)luaL_checkinteger(L, 2)]);
  83. if (collided == true) {
  84. lua_pushboolean(L, true);
  85. }
  86. else lua_pushboolean(L, false);
  87. } catch (Exception e) {
  88. }
  89. return 1;
  90. }