drawtileex
This commit is contained in:
parent
2cb24f14fa
commit
f2911ceebd
79
inc/lzy.h
79
inc/lzy.h
|
@ -93,6 +93,8 @@ int LZY_DrawLine(int x0, int y0, int x1, int y1);
|
|||
int LZY_DrawRect(int x, int y, unsigned int w, unsigned int h);
|
||||
int LZY_DrawFillRect(int x, int y, unsigned int w, unsigned int h);
|
||||
int LZY_DrawTile(unsigned int id, int x, int y);
|
||||
int LZY_DrawTileEx(unsigned int id, int x, int y, unsigned int w,
|
||||
unsigned int h);
|
||||
int LZY_DrawChar(unsigned char chr, int x, int y);
|
||||
int LZY_DrawText(const char *text, int x, int y);
|
||||
LZY_Music *LZY_MusicLoad(const char *path);
|
||||
|
@ -311,6 +313,41 @@ int LZY_DrawTile(unsigned int id, int x, int y) {
|
|||
#endif
|
||||
}
|
||||
|
||||
int LZY_DrawTileEx(unsigned int id, int x, int y, unsigned int w,
|
||||
unsigned int h) {
|
||||
#ifndef LZY_GINT_TILESET
|
||||
LZY_UNUSED(id);
|
||||
LZY_UNUSED(x);
|
||||
LZY_UNUSED(y);
|
||||
LZY_UNUSED(w);
|
||||
LZY_UNUSED(h);
|
||||
return -1;
|
||||
#else
|
||||
extern bopti_image_t LZY_GINT_TILESET;
|
||||
int ix, iy;
|
||||
|
||||
if (w * h == 0)
|
||||
return -1;
|
||||
|
||||
x += draw_off_x;
|
||||
y += draw_off_y;
|
||||
|
||||
ix = id % tset_width;
|
||||
iy = id / tset_width;
|
||||
|
||||
if (ix >= (int)tset_width || ix + w - 1 >= tset_width ||
|
||||
iy >= (int)tset_height || iy + h - 1 >= tset_height)
|
||||
return -1;
|
||||
|
||||
ix *= LZY_TILE_SIZE;
|
||||
iy *= LZY_TILE_SIZE;
|
||||
dsubimage(x, y, &LZY_GINT_TILESET, ix, iy, w * LZY_TILE_SIZE,
|
||||
h * LZY_TILE_SIZE, DIMAGE_NONE);
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int LZY_DrawChar(unsigned char chr, int x, int y) {
|
||||
#ifndef LZY_GINT_FONT
|
||||
LZY_UNUSED(chr);
|
||||
|
@ -776,6 +813,48 @@ int LZY_DrawTile(unsigned int id, int x, int y) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int LZY_DrawTileEx(unsigned int id, int x, int y, unsigned int w,
|
||||
unsigned int h) {
|
||||
SDL_Rect src, dst;
|
||||
|
||||
if (w * h == 0) {
|
||||
error = "tile size can't be 0";
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (id >= (unsigned int)(tset_width * tset_height)) {
|
||||
error = "id exceeds boundaries";
|
||||
return -1;
|
||||
}
|
||||
|
||||
src.x = id % tset_width;
|
||||
src.y = id / tset_width;
|
||||
|
||||
if (src.x >= tset_width || src.x + w - 1 >= (unsigned int)tset_width ||
|
||||
src.y >= tset_height ||
|
||||
src.y + h - 1 >= (unsigned int)tset_height) {
|
||||
error = "tile is not in tileset";
|
||||
return -1;
|
||||
}
|
||||
|
||||
src.x *= LZY_TILE_SIZE;
|
||||
src.y *= LZY_TILE_SIZE;
|
||||
src.w = w * LZY_TILE_SIZE;
|
||||
src.h = h * LZY_TILE_SIZE;
|
||||
|
||||
dst.x = x;
|
||||
dst.y = y;
|
||||
dst.w = w * LZY_TILE_SIZE;
|
||||
dst.h = h * LZY_TILE_SIZE;
|
||||
|
||||
if (SDL_RenderCopy(renderer, tset, &src, &dst) < 0) {
|
||||
error = SDL_GetError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LZY_DrawChar(unsigned char chr, int x, int y) {
|
||||
const unsigned int id = (unsigned int)chr - LZY_FIRST_CHR;
|
||||
SDL_Rect src, dst;
|
||||
|
|
|
@ -46,7 +46,10 @@ int main(int argc, const char **argv) {
|
|||
LZY_DrawLine(x, y, 0, 0);
|
||||
|
||||
/* draw player */
|
||||
LZY_DrawTile(1, x, y);
|
||||
if (LZY_DrawTileEx(1, x, y, 3, 2))
|
||||
LZY_Log(LZY_GetError());
|
||||
if (LZY_DrawTile(1, x, y))
|
||||
LZY_Log(LZY_GetError());
|
||||
}
|
||||
LZY_DrawEnd();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue