- [NEW] spr_r per a rotar sprites (retalla cantos)
- [NEW] sspr admet un nou paràmetre "invert", per a invertir la x i la y.
This commit is contained in:
28
mini.cpp
28
mini.cpp
@@ -872,7 +872,7 @@ void spr(uint8_t n, int x, int y, float w, float h, bool flip_x, bool flip_y) {
|
||||
}
|
||||
}
|
||||
|
||||
void sspr(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool flip_x, bool flip_y) {
|
||||
void sspr(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool flip_x, bool flip_y, bool invert) {
|
||||
if (dw==0) dw=sw;
|
||||
if (dh==0) dh=sh;
|
||||
float sdx = float(sw)/float(dw);
|
||||
@@ -885,13 +885,37 @@ void sspr(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool f
|
||||
for(int y=dy;y<dy+dh;++y) {
|
||||
csx = ssx;
|
||||
for(int x=dx;x<dx+dw;++x) {
|
||||
pset(x, y, sget(SDL_max(sx, csx), SDL_max(sy,csy)));
|
||||
uint8_t color = invert ? sget(SDL_max(sy,csy),SDL_max(sx, csx)) : sget(SDL_max(sx, csx), SDL_max(sy,csy));
|
||||
pset(x, y, color);
|
||||
csx += sdx;
|
||||
}
|
||||
csy += sdy;
|
||||
}
|
||||
}
|
||||
|
||||
void spr_r(int sx, int sy, int sw, int sh, int x, int y, float a)
|
||||
{
|
||||
const int x0 = sw>>1;
|
||||
const int y0 = sh>>1;
|
||||
|
||||
const float sa = SDL_sinf(a);
|
||||
const float ca = SDL_cosf(a);
|
||||
|
||||
for (int ix=0; ix<=sw; ++ix)
|
||||
{
|
||||
for (int iy=0; iy<=sh; ++iy)
|
||||
{
|
||||
const float dx = ix-x0;
|
||||
const float dy = iy-y0;
|
||||
const float xx = dx*ca - dy*sa + float(x0);
|
||||
const float yy = dx*sa + dy*ca + float(y0);
|
||||
|
||||
if (xx>=0 && xx<sw-1 && yy>=0 && yy<=sh-1)
|
||||
pset(x+ix, y+iy, sget(sx+xx, sy+yy));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tline(int x0, int y0, int x1, int y1, float mx, float my, float mdx, float mdy) {
|
||||
int x, y;
|
||||
int dx, dy;
|
||||
|
||||
Reference in New Issue
Block a user