Agora funcionando.
[Projeto-PCG.git] / maploader.cpp
blob06fe0a47ee08a9bedcf2d3380b4452d8ebb35b80
1 #include "maploader.h"
2 #include "luaenv.h"
4 static Mapa* mapa = NULL;
6 static int regmap (lua_State *L) {
7 double width = lua_tonumber(L, 1);
8 double height = lua_tonumber(L, 2);
9 Ponto spawn;
10 spawn.x = lua_tonumber(L, 3);
11 spawn.y = lua_tonumber(L, 4);
12 mapa->setSpawn(spawn);
13 mapa->setTamanho(width,height);
14 return 0;
17 static int regplatform (lua_State *L) {
18 mapa->novaPlataforma(luaL_checknumber(L, 1),
19 luaL_checknumber(L, 2),
20 luaL_checknumber(L, 3),
21 luaL_checknumber(L, 4),
22 lua_toboolean(L, 5));
23 return 0;
26 static int regweapon (lua_State *L) {
27 const char* nome = lua_tostring(L, 1);
28 double x = lua_tonumber(L, 2);
29 double y = lua_tonumber(L, 3);
30 mapa->dropWeapon(nome, Ponto(x, y));
31 return 0;
34 void MapLoader::load(std::string name, Mapa* m) {
35 mapa = m;
36 lua_State* l = newState();
37 registerFunction(l,"regmap",regmap);
38 registerFunction(l,"regplatform",regplatform);
39 registerFunction(l,"regweapon",regweapon);
40 doLuaFile(l,"maploader.lua");
41 doLuaFile(l,name.c_str());
42 lua_close(l);