static int draw() { int offsetX = self->offsetX; int drawn = drawLoopingAnimationToMap(); if (drawn == TRUE) { if (game.status == IN_GAME && offsetX == 0 && self->offsetX != offsetX) { shakeScreen(LIGHT, 5); } addSparkles(); } return drawn; }
void Level::fixCoordsWithObj(LevelObj& obj, Actor* act)// f32& xx, f32& yy, f32& vx, f32& vy, f32& gx, f32& gy) { obj.state = 1; f32 px = act->x+act->gvx*2; f32 py = act->y+act->gvy*2; int dists[4]; dists[0] = distToLine(px, py, obj.x[0], obj.y[0], obj.x[1], obj.y[1]).toint(); dists[1] = distToLine(px, py, obj.x[1], obj.y[1], obj.x[2], obj.y[2]).toint(); dists[2] = distToLine(px, py, obj.x[2], obj.y[2], obj.x[3], obj.y[3]).toint(); dists[3] = distToLine(px, py, obj.x[3], obj.y[3], obj.x[0], obj.y[0]).toint(); int best1 = -1; int bestd; for(int i = 0; i < 4; i++) if((dists[i] < bestd || best1 == -1)) bestd=dists[i], best1 = i; int best2 = -1; for(int i = 0; i < 4; i++) if((dists[i] < bestd || best2 == -1) && i != best1) bestd=dists[i], best2 = i; bool invalid1 = obj.neighbors[best1] != -1; bool invalid2 = obj.neighbors[best2] != -1; if(invalid1 && invalid2) //Corner: Just collide with the neighbor fixCoordsWithObj(objs->objs[obj.neighbors[best1]], act); else { if(invalid1) { best1 = best2; invalid1 = invalid2; } int n = best1; int n2 = (n+1)%4; f32 oldx = act->x; projectToLine(act->x, act->y, obj.x[n], obj.y[n], obj.x[n2], obj.y[n2]); f32 fx, fy; fx = act->vx; fy = act->vy; projectVecToLine(fx, fy, obj.y[n2], obj.x[n], obj.y[n], obj.x[n2]); bool bounce = obj.type == BEH_BOUNCY || (fabs(fx)+fabs(fy))>8; if(!bounce) { projectVecToLine(act->vx, act->vy, obj.x[n], obj.y[n], obj.x[n2], obj.y[n2]); fx = -(obj.y[n2]-obj.y[n]); fy = obj.x[n2]-obj.x[n]; vecNormalize(fx, fy); act->gx = fx; act->gy = fy; if(fabs(act->gx) < 0.4) { act->gx = 0; // act->vx = 0; act->x = oldx; } act->x += act->gx; act->y += act->gy; } else { addSparkles(obj); fx = act->vx; fy = act->vy; f32 nx = -(obj.y[n2]-obj.y[n]); f32 ny = obj.x[n2]-obj.x[n]; vecNormalize(nx, ny); f32 dotp = -fx*nx-fy*ny; fx = fx+nx*dotp*2; fy = fy+ny*dotp*2; if(obj.type != BEH_BOUNCY) { fx /= 2; fy /= 2; } else { fx *= f32(1.7); fy *= f32(1.7); } act->vx = fx + nx/2; act->vy = fy + ny/2; act->x += nx*3; act->y += ny*3; } } }