- [NEW] tilemap.new(x,y)
- [CHG] tilemap.new i tilemap.load alliberen la surface anterior (si hi havia) del mapa
This commit is contained in:
13
lua.cpp
13
lua.cpp
@@ -140,10 +140,20 @@ extern "C" {
|
|||||||
// map
|
// map
|
||||||
// ===============================================
|
// ===============================================
|
||||||
|
|
||||||
|
static int cpp_map_new(lua_State *L) {
|
||||||
|
int w = luaL_checknumber(L, 1);
|
||||||
|
int h = luaL_checknumber(L, 2);
|
||||||
|
uint8_t s = newsurf(w, h);
|
||||||
|
uint8_t old = getmap(); if (old) freesurf(old);
|
||||||
|
setmap(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int cpp_map_load(lua_State *L) {
|
static int cpp_map_load(lua_State *L) {
|
||||||
const char* str = luaL_checkstring(L, 1);
|
const char* str = luaL_checkstring(L, 1);
|
||||||
setmap(loadsurf(str));
|
uint8_t s = loadsurf(str);
|
||||||
|
uint8_t old = getmap(); if (old) freesurf(old);
|
||||||
|
setmap(s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -833,6 +843,7 @@ void push_lua_funcs() {
|
|||||||
lua_setglobal(L, "surface");
|
lua_setglobal(L, "surface");
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
lua_pushcfunction(L,cpp_map_new); lua_setfield(L, -2, "new");
|
||||||
lua_pushcfunction(L,cpp_map_load); lua_setfield(L, -2, "load");
|
lua_pushcfunction(L,cpp_map_load); lua_setfield(L, -2, "load");
|
||||||
lua_pushcfunction(L,cpp_map_save); lua_setfield(L, -2, "save");
|
lua_pushcfunction(L,cpp_map_save); lua_setfield(L, -2, "save");
|
||||||
lua_pushcfunction(L,cpp_map_set); lua_setfield(L, -2, "set");
|
lua_pushcfunction(L,cpp_map_set); lua_setfield(L, -2, "set");
|
||||||
|
|||||||
2
mini.cpp
2
mini.cpp
@@ -1022,11 +1022,13 @@ void tvline(int x, int y0, int y1, float mx, float my, float mdx, float mdy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t mget(int celx, int cely) {
|
uint8_t mget(int celx, int cely) {
|
||||||
|
if (!map_surface) return 0;
|
||||||
if (celx < 0 || celx > (map_surface->w-1) || cely < 0 || cely > (map_surface->h-1)) return 0;
|
if (celx < 0 || celx > (map_surface->w-1) || cely < 0 || cely > (map_surface->h-1)) return 0;
|
||||||
return TILES(celx, cely);
|
return TILES(celx, cely);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mset(int celx, int cely, uint8_t snum) {
|
void mset(int celx, int cely, uint8_t snum) {
|
||||||
|
if (!map_surface) return;
|
||||||
if (celx < 0 || celx > (map_surface->w-1) || cely < 0 || cely > (map_surface->h-1)) return;
|
if (celx < 0 || celx > (map_surface->w-1) || cely < 0 || cely > (map_surface->h-1)) return;
|
||||||
TILES(celx, cely) = snum;
|
TILES(celx, cely) = snum;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ function surface.getPixel(x, y) end
|
|||||||
---@class tilemap
|
---@class tilemap
|
||||||
tilemap = {}
|
tilemap = {}
|
||||||
|
|
||||||
|
---@param w number
|
||||||
|
---@param h number
|
||||||
|
---Create new map specifying width and height
|
||||||
|
function tilemap.new(w, h) end
|
||||||
|
|
||||||
---@param filename string
|
---@param filename string
|
||||||
---@return number surface
|
---@return number surface
|
||||||
---Load a tilemap from a file and set it as current tilemap
|
---Load a tilemap from a file and set it as current tilemap
|
||||||
@@ -403,7 +408,7 @@ function window.setResolution(w, h) end
|
|||||||
config = {}
|
config = {}
|
||||||
|
|
||||||
---@param key string
|
---@param key string
|
||||||
---@param value string
|
---@param value any
|
||||||
---Sets the value of a key in the configuration file
|
---Sets the value of a key in the configuration file
|
||||||
function config.setKey(key, value) end
|
function config.setKey(key, value) end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user