Compare commits
8 Commits
5306e82897
...
61b02fdeef
| Author | SHA1 | Date | |
|---|---|---|---|
| 61b02fdeef | |||
| 7abc8648a1 | |||
| 2f0817d20c | |||
| ecb493f9c8 | |||
| 9c3baebc1e | |||
| 173654e0bd | |||
| ba1daf810d | |||
| 45d31579d2 |
35
lua.cpp
35
lua.cpp
@@ -140,10 +140,20 @@ extern "C" {
|
||||
// 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) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -168,6 +178,8 @@ extern "C" {
|
||||
uint8_t celw = luaL_checknumber(L, 5);
|
||||
uint8_t celh = luaL_checknumber(L, 6);
|
||||
uint8_t layer = luaL_optinteger(L, 7, 0);*/
|
||||
uint8_t surface = luaL_checkinteger(L, 1);
|
||||
setsource(surface);
|
||||
map(); //celx, cely, sx, sy, celw, celh, layer);
|
||||
return 0;
|
||||
}
|
||||
@@ -395,22 +407,22 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_draw_rect(lua_State *L) {
|
||||
int x0 = luaL_checknumber(L, 1);
|
||||
int y0 = luaL_checknumber(L, 2);
|
||||
int x1 = luaL_checknumber(L, 3);
|
||||
int y1 = luaL_checknumber(L, 4);
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
int w = luaL_checknumber(L, 3);
|
||||
int h = luaL_checknumber(L, 4);
|
||||
uint8_t color = luaL_checkinteger(L, 5);
|
||||
rect(x0, y0, x1, y1, color);
|
||||
rect(x, y, w, h, color);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_draw_rectfill(lua_State *L) {
|
||||
int x0 = luaL_checknumber(L, 1);
|
||||
int y0 = luaL_checknumber(L, 2);
|
||||
int x1 = luaL_checknumber(L, 3);
|
||||
int y1 = luaL_checknumber(L, 4);
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
int w = luaL_checknumber(L, 3);
|
||||
int h = luaL_checknumber(L, 4);
|
||||
uint8_t color = luaL_checkinteger(L, 5);
|
||||
rectfill(x0, y0, x1, y1, color);
|
||||
rectfill(x, y, w, h, color);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -833,6 +845,7 @@ void push_lua_funcs() {
|
||||
lua_setglobal(L, "surface");
|
||||
|
||||
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_save); lua_setfield(L, -2, "save");
|
||||
lua_pushcfunction(L,cpp_map_set); lua_setfield(L, -2, "set");
|
||||
|
||||
41
mini.cpp
41
mini.cpp
@@ -203,7 +203,7 @@ uint8_t newsurf(int w, int h) {
|
||||
surfaces[i].w = w;
|
||||
surfaces[i].h = h;
|
||||
surfaces[i].size = w*h;
|
||||
surfaces[i].p = (uint8_t*)malloc(surfaces[i].size);
|
||||
surfaces[i].p = (uint8_t*)calloc(surfaces[i].size,1);
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -499,12 +499,13 @@ void simple_pset(int x, int y, uint8_t color) {
|
||||
|
||||
void cls(uint8_t color) {
|
||||
const uint8_t col = ds::draw_palette[color];
|
||||
for (int y=ds::clip[1]; y<=ds::clip[3];++y) {
|
||||
/*for (int y=ds::clip[1]; y<=ds::clip[3];++y) {
|
||||
for (int x=ds::clip[0]; x<=ds::clip[2];++x) {
|
||||
simple_pset(x,y,col);
|
||||
}
|
||||
}
|
||||
//SDL_memset(dest_surface->p, color, dest_surface->size);
|
||||
}*/
|
||||
|
||||
SDL_memset(dest_surface->p, col, dest_surface->size);
|
||||
}
|
||||
|
||||
void color(uint8_t color) {
|
||||
@@ -675,25 +676,29 @@ void vline(int x, int y0, int y1, uint8_t color) {
|
||||
vline(x, y0, y1);
|
||||
}
|
||||
|
||||
void rect(int x0, int y0, int x1, int y1) {
|
||||
hline(x0, y0, x1);
|
||||
hline(x0, y1, x1);
|
||||
vline(x0, y0, y1);
|
||||
vline(x1, y0, y1);
|
||||
void rect(int x, int y, int w, int h) {
|
||||
int x1 = w+x-1;
|
||||
int y1 = h+y-1;
|
||||
hline(x, y, x1);
|
||||
hline(x, y1, x1);
|
||||
vline(x, y, y1);
|
||||
vline(x1, y, y1);
|
||||
}
|
||||
|
||||
void rect(int x0, int y0, int x1, int y1, uint8_t color) {
|
||||
void rect(int x, int y, int w, int h, uint8_t color) {
|
||||
ds::pen_color = color;
|
||||
rect(x0, y0, x1, y1);
|
||||
rect(x, y, w, h);
|
||||
}
|
||||
|
||||
void rectfill(int x0, int y0, int x1, int y1) {
|
||||
for (int y=y0; y<=y1; ++y) hline(x0, y, x1);
|
||||
void rectfill(int x, int y, int w, int h) {
|
||||
int x1 = w+x-1;
|
||||
int y1 = h+y-1;
|
||||
for (int i=y; i<=y1; ++i) hline(x, i, x1);
|
||||
}
|
||||
|
||||
void rectfill(int x0, int y0, int x1, int y1, uint8_t color) {
|
||||
void rectfill(int x, int y, int w, int h, uint8_t color) {
|
||||
ds::pen_color = color;
|
||||
rectfill(x0, y0, x1, y1);
|
||||
rectfill(x, y, w, h);
|
||||
}
|
||||
|
||||
void fillp(uint16_t pat, bool transparent) {
|
||||
@@ -1022,19 +1027,21 @@ void tvline(int x, int y0, int y1, float mx, float my, float mdx, float mdy) {
|
||||
}
|
||||
|
||||
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;
|
||||
return TILES(celx, cely);
|
||||
}
|
||||
|
||||
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;
|
||||
TILES(celx, cely) = snum;
|
||||
}
|
||||
|
||||
void map() { //int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer) {
|
||||
if (map_surface==NULL) return;
|
||||
uint8_t celw = map_surface->w >> 3;
|
||||
uint8_t celh = map_surface->h >> 3;
|
||||
uint8_t celw = map_surface->w;// >> 3;
|
||||
uint8_t celh = map_surface->h;// >> 3;
|
||||
int celx = 0;
|
||||
int cely = 0;
|
||||
//if (celw <= 0 || celh <= 0 || celw >= TILES_WIDTH || celh >= TILES_HEIGHT) return;
|
||||
|
||||
8
mini.h
8
mini.h
@@ -156,11 +156,11 @@ void hline(int x0, int y, int x1, uint8_t color);
|
||||
void vline(int x, int y0, int y1);
|
||||
void vline(int x, int y0, int y1, uint8_t color);
|
||||
|
||||
void rect(int x0, int y0, int x1, int y1);
|
||||
void rect(int x0, int y0, int x1, int y1, uint8_t color);
|
||||
void rect(int x, int y, int w, int h);
|
||||
void rect(int x, int y, int w, int h, uint8_t color);
|
||||
|
||||
void rectfill(int x0, int y0, int x1, int y1);
|
||||
void rectfill(int x0, int y0, int x1, int y1, uint8_t color);
|
||||
void rectfill(int x, int y, int w, int h);
|
||||
void rectfill(int x, int y, int w, int h, uint8_t color);
|
||||
|
||||
void fillp(uint16_t pat, bool transparent = false);
|
||||
|
||||
|
||||
@@ -69,6 +69,11 @@ function surface.getPixel(x, y) end
|
||||
---@class tilemap
|
||||
tilemap = {}
|
||||
|
||||
---@param w number
|
||||
---@param h number
|
||||
---Create new map specifying width and height
|
||||
function tilemap.new(w, h) end
|
||||
|
||||
---@param filename string
|
||||
---@return number surface
|
||||
---Load a tilemap from a file and set it as current tilemap
|
||||
@@ -82,8 +87,9 @@ function tilemap.save(filename) end
|
||||
---Set surface as the current tilemap
|
||||
function tilemap.set(surface) end
|
||||
|
||||
---Draw the tilemap
|
||||
function tilemap.draw() end
|
||||
---@param surface number
|
||||
---Draw the tilemap, using the provided surface as tile graphics source
|
||||
function tilemap.draw(surface) end
|
||||
|
||||
---@param x number
|
||||
---@param y number
|
||||
@@ -403,7 +409,7 @@ function window.setResolution(w, h) end
|
||||
config = {}
|
||||
|
||||
---@param key string
|
||||
---@param value string
|
||||
---@param value any
|
||||
---Sets the value of a key in the configuration file
|
||||
function config.setKey(key, value) end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user