summaryrefslogtreecommitdiff
path: root/src/Api.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Api.h')
-rw-r--r--src/Api.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/Api.h b/src/Api.h
new file mode 100644
index 0000000..da763c2
--- /dev/null
+++ b/src/Api.h
@@ -0,0 +1,71 @@
+#ifndef DNG_API_H
+#define DNG_API_H
+
+#include "Level.h"
+#include <lua.hpp>
+#include <memory>
+
+extern std::shared_ptr<Level> lvl;
+
+static int
+c_update_player_pos(lua_State* L)
+{
+ // stack ordering
+ int dy = static_cast<int>(lua_tonumber(L, -1));
+ int dx = static_cast<int>(lua_tonumber(L, -2));
+
+ bool res = false;
+
+ if (lvl->canStep(dx, dy)) {
+ lvl->player.x += dx;
+ lvl->player.y += dy;
+ res = true;
+ }
+
+ lua_pushboolean(L, res);
+
+ return 1;
+}
+
+static int
+c_player_can_move(lua_State* L)
+{
+ // stack ordering
+ int dy = static_cast<int>(lua_tonumber(L, -1));
+ int dx = static_cast<int>(lua_tonumber(L, -2));
+
+ bool res = lvl->canStep(dx, dy);
+ lua_pushboolean(L, res);
+
+ return 1;
+}
+
+static int
+c_enemy_can_move(lua_State* L)
+{
+ return 1;
+}
+
+static int
+c_spawn_enemy(lua_State* L)
+{
+ return 1;
+}
+
+static int
+c_destroy_enemy(lua_State* L)
+{
+ return 1;
+}
+
+static void
+init_c_api(lua_State* L)
+{
+ lua_register(L, "c_update_player_pos", c_update_player_pos);
+ lua_register(L, "c_player_can_move", c_player_can_move);
+ lua_register(L, "c_enemy_can_move", c_enemy_can_move);
+ lua_register(L, "c_spawn_enemy", c_spawn_enemy);
+ lua_register(L, "c_destroy_enemy", c_destroy_enemy);
+}
+
+#endif // DNG_API_H \ No newline at end of file