VERSIÓ 1.4.7
- [NEW] map.cell() per a establir o llegir el tamany dels tiles del mapa
This commit is contained in:
17
lua.cpp
17
lua.cpp
@@ -217,7 +217,21 @@ extern "C" {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int cpp_map_cell(lua_State *L) {
|
||||
if (lua_gettop(L)==2) {
|
||||
int celx = luaL_checknumber(L, 1);
|
||||
int cely = luaL_checknumber(L, 2);
|
||||
settilesize(celx, cely);
|
||||
lua_pushinteger(L, mget(celx, cely));
|
||||
return 0;
|
||||
} else {
|
||||
lua_pushinteger(L, gettilew());
|
||||
lua_pushinteger(L, gettileh());
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// palette
|
||||
// ===============================================
|
||||
@@ -1120,6 +1134,7 @@ void push_lua_funcs() {
|
||||
lua_pushcfunction(L,cpp_map_surf); lua_setfield(L, -2, "surf");
|
||||
lua_pushcfunction(L,cpp_map_draw); lua_setfield(L, -2, "draw");
|
||||
lua_pushcfunction(L,cpp_map_tile); lua_setfield(L, -2, "tile");
|
||||
lua_pushcfunction(L,cpp_map_cell); lua_setfield(L, -2, "cell");
|
||||
lua_setglobal(L, "map");
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
35
mini.cpp
35
mini.cpp
@@ -60,6 +60,8 @@ surface_t *screen_surface = &surfaces[0];
|
||||
surface_t *dest_surface = screen_surface;
|
||||
surface_t *source_surface = NULL;
|
||||
surface_t *map_surface = NULL;
|
||||
uint8_t tile_width = 8;
|
||||
uint8_t tile_height = 8;
|
||||
|
||||
font_t fonts[MAX_FONTS];
|
||||
font_t *current_font;
|
||||
@@ -1308,10 +1310,10 @@ void sset(int x, int y, uint8_t color) {
|
||||
|
||||
void spr(uint8_t n, int x, int y, float w, float h, bool flip_x, bool flip_y) {
|
||||
if (!source_surface) return;
|
||||
int tx = (n%(source_surface->w >> 3))<<3;
|
||||
int ty = (n/(source_surface->w >> 3))<<3;
|
||||
int tw = w*8 - 1;
|
||||
int th = h*8 - 1;
|
||||
int tx = (n%(source_surface->w / tile_width))*tile_width;
|
||||
int ty = (n/(source_surface->w / tile_height))*tile_height;
|
||||
int tw = w*tile_width - 1;
|
||||
int th = h*tile_height - 1;
|
||||
//int tx2 = tx1 + tw;
|
||||
//int ty2 = ty1 + th;
|
||||
int txd = 1;
|
||||
@@ -1444,6 +1446,13 @@ void mset(int celx, int cely, uint8_t snum) {
|
||||
TILES(celx, cely) = snum;
|
||||
}
|
||||
|
||||
uint8_t gettilew() { return tile_width; }
|
||||
uint8_t gettileh() { return tile_height; }
|
||||
void settilesize(int w, int h) {
|
||||
tile_width = w;
|
||||
tile_height = h;
|
||||
}
|
||||
|
||||
void map() { //int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer) {
|
||||
if (map_surface==NULL) return;
|
||||
int celw = map_surface->w;// >> 3;
|
||||
@@ -1452,28 +1461,28 @@ void map() { //int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, u
|
||||
int cely = 0;
|
||||
//if (celw <= 0 || celh <= 0 || celw >= TILES_WIDTH || celh >= TILES_HEIGHT) return;
|
||||
int sx = ds::origin[0]; int sy = ds::origin[1];
|
||||
if (sx+celw*8 < ds::clip[0] || sx > ds::clip[2] || sy+celh*8 < ds::clip[1] || sy > ds::clip[3]) return;
|
||||
if (sx+celw*tile_width < ds::clip[0] || sx > ds::clip[2] || sy+celh*tile_height < ds::clip[1] || sy > ds::clip[3]) return;
|
||||
if (sx<0) {
|
||||
int diff = -sx/8;
|
||||
int diff = -sx/tile_width;
|
||||
celx += diff;
|
||||
celw -= diff;
|
||||
sx += diff*8;
|
||||
sx += diff*tile_width;
|
||||
}
|
||||
if (sy<0) {
|
||||
int diff = -sy/8;
|
||||
int diff = -sy/tile_height;
|
||||
cely += diff;
|
||||
celh -= diff;
|
||||
sy += diff*8;
|
||||
sy += diff*tile_height;
|
||||
}
|
||||
sx -= ds::origin[0]; sy -= ds::origin[1];
|
||||
for (int y=0; y<celh; ++y) {
|
||||
for (int x=0; x<celw; ++x) {
|
||||
const uint8_t tile = mget(celx+x, cely+y);
|
||||
if (tile==0) continue;
|
||||
const int fx = sx+(x*8)+ds::origin[0];
|
||||
const int fy = sy+(y*8)+ds::origin[1];
|
||||
if ( (fx+8<ds::clip[0]) || (fy+8<ds::clip[1]) || (fx>ds::clip[2]) || (fy>ds::clip[3]) ) continue;
|
||||
spr(tile, sx+x*8, sy+y*8);
|
||||
const int fx = sx+(x*tile_width)+ds::origin[0];
|
||||
const int fy = sy+(y*tile_height)+ds::origin[1];
|
||||
if ( (fx+tile_width<ds::clip[0]) || (fy+tile_height<ds::clip[1]) || (fx>ds::clip[2]) || (fy>ds::clip[3]) ) continue;
|
||||
spr(tile, sx+x*tile_width, sy+y*tile_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
mini.h
3
mini.h
@@ -225,6 +225,9 @@ void tvline(int x, int y0, int y1, float mx, float my, float mdx=0.0f, float mdy
|
||||
|
||||
uint8_t mget(int celx, int cely);
|
||||
void mset(int celx, int cely, uint8_t snum);
|
||||
uint8_t gettilew();
|
||||
uint8_t gettileh();
|
||||
void settilesize(int w, int h);
|
||||
void map(); //int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer=0);
|
||||
|
||||
bool btn(uint8_t i);
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define MINI_VERSION "1.4.6"
|
||||
#define MINI_VERSION "1.4.7"
|
||||
|
||||
@@ -102,6 +102,15 @@ function map.tile(x, y) end
|
||||
---Set the tile at the position (x,y) in the current tilemap
|
||||
function map.tile(x, y, tile) end
|
||||
|
||||
---@param w number
|
||||
---@param h number
|
||||
---Set current tile size
|
||||
function map.cell(w, h) end
|
||||
|
||||
---@return number w, number h
|
||||
---Set current tile size
|
||||
function map.cell() end
|
||||
|
||||
---@class pal
|
||||
pal = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user