[Fix] Silly collision bug. Pixel-Perfect collision should now be *perfect*(tm).
This commit is contained in:
parent
e1b23f928b
commit
d288a2db9f
@ -38,11 +38,21 @@ int CollideSprite(const gl_texture* at, const int asx, const int asy, const Vec2
|
||||
int inter_y0 = MAX(ay1, by1);
|
||||
int inter_y1 = MIN(ay2, by2);
|
||||
|
||||
// Real vertical sprite value (flipped).
|
||||
int rasy = at->sy - asy - 1;
|
||||
int rbsy = bt->sy - bsy - 1;
|
||||
|
||||
// Set up the base points.
|
||||
int abx = asx*(int)(at->sw) - ax1;
|
||||
int aby = rasy*(int)(at->sh) - ay1;
|
||||
int bbx = bsx*(int)(bt->sw) - bx1;
|
||||
int bby = rbsy*(int)(bt->sh) - by1;
|
||||
|
||||
for(y = inter_y0; y <= inter_y1; y++)
|
||||
for(x = inter_x0; x <= inter_x1; x++)
|
||||
// Computer offsets for surface before passing to TransparentPixel test.
|
||||
if((!gl_isTrans(at, asx*(int)(at->sw) + x-ax1, asy*(int)(at->sh) + y-ay1)) &&
|
||||
(!gl_isTrans(bt, bsx*(int)(bt->sw) + x-bx1, bsy*(int)(bt->sh) + y-by1)))
|
||||
if((!gl_isTrans(at, abx + x, aby + y)) &&
|
||||
(!gl_isTrans(bt, bbx + x, bby + y)))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
12
src/opengl.c
12
src/opengl.c
@ -148,7 +148,7 @@ static GLuint gl_loadSurface(SDL_Surface* surface, int* rw, int* rh) {
|
||||
if(rw)*rw = potw;
|
||||
if(rh)*rh = poth;
|
||||
|
||||
if(surface->w != potw || surface->h != poth) {
|
||||
if((surface->w != potw) || (surface->h != poth)) {
|
||||
// Size isn't original.
|
||||
SDL_Rect rtemp;
|
||||
rtemp.x = rtemp.y = 0;
|
||||
@ -273,17 +273,19 @@ gl_texture* gl_newImage(const char* path) {
|
||||
|
||||
SDL_FreeSurface(tmp); // Free the temp surface.
|
||||
|
||||
SDL_LockSurface(surface);
|
||||
trans = SDL_MapTrans(surface);
|
||||
SDL_UnlockSurface(surface);
|
||||
|
||||
if(SDL_VFlipSurface(surface)) {
|
||||
WARN("Error flipping surface");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Do after flipping for collision detection.
|
||||
SDL_LockSurface(surface);
|
||||
trans = SDL_MapTrans(surface);
|
||||
SDL_UnlockSurface(surface);
|
||||
|
||||
t = gl_loadImage(surface);
|
||||
t->trans = trans;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user