Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool player::resolveCollision( double x, double y, bool movedX, bool movedY, bool bumped )
- {
- int X = floor(x), Y = floor(y);
- int X2 = floor(_x), Y2 = floor(_y);
- bool XE = (X == x || X2 == _x), YE = (Y == y);
- bool hasChanged = false;
- bool cols[3][3];
- bool cols2[3][3];
- bool cols3[3][3];
- bool cols4[3][3];
- for( int i = 0; i < 3; i ++ )for( int j = 0; j < 3; j ++ )cols[j][i] = ((map*)MyMap)->getBlockSolid( X - 1 + j, Y - 1 + i );
- for( int i = 0; i < 3; i ++ )for( int j = 0; j < 3; j ++ )cols2[j][i] = ((map*)MyMap)->getBlockSolid( X2 - 1 + j, Y - 1 + i );
- for( int i = 0; i < 3; i ++ )for( int j = 0; j < 3; j ++ )cols4[j][i] = ((map*)MyMap)->getBlockSolid( X - 1 + j, Y2 - 1 + i );
- for( int i = 0; i < 3; i ++ )for( int j = 0; j < 3; j ++ )cols3[j][i] = ((map*)MyMap)->getBlockSolid( X2 - 1 + j, Y2 - 1 + i );
- if( !bumped ){
- if( _vspeed > 0 ){
- if( cols[0][2] && cols[2][2] && !cols[1][2] && cols2[1][2] && !XE && _hspeed > 0 ) { _x = X; _hspeed = 0; resolveCollision( x, _y, movedX, movedY, true ); return true; }
- else if( cols2[0][2] && cols2[2][2] && !cols2[1][2] && cols[1][2] && !XE && _hspeed < 0 ) { _x = X2; _hspeed = 0; resolveCollision( x, _y, movedX, movedY, true ); return true; }
- }
- else if( _vspeed < 0 ){
- if( cols[0][1] && cols[2][1] && !cols[1][1] && cols2[1][1] && !XE && _hspeed > 0 ) { _x = X; _hspeed = 0; resolveCollision( x, _y, movedX, movedY, true ); return true; }
- else if( cols2[0][1] && cols2[2][1] && !cols2[1][1] && cols[1][1] && !XE && _hspeed < 0 ) { _x = X2; _hspeed = 0; resolveCollision( x, _y, movedX, movedY, true ); return true; }
- }
- if( _hspeed < 0 ){
- if( cols[1][0] && cols[1][2] && !cols[1][1] && cols4[1][1] && !YE && _vspeed > 0 ) { _y = Y; _vspeed = 0; resolveCollision( x, _y, movedX, movedY, true ); return true; }
- else if( cols3[0][0] && cols3[0][2] && !cols3[0][1] && cols[1][1] && !YE && _vspeed < 0 ) { _y = Y2; _vspeed = 0; resolveCollision( x, _y, movedX, movedY, true ); return true; }
- }
- if( _hspeed > 0 ){
- if( cols[2][0] && cols[2][2] && !cols[2][1] && cols4[2][1] && !YE && _vspeed > 0 ) { _y = Y; _vspeed = 0; resolveCollision( x, _y, movedX, movedY, true ); return true; }
- else if( cols3[2][0] && cols3[2][2] && !cols3[2][1] && cols[2][1] && !YE && _vspeed < 0 ) { _y = Y2; _vspeed = 0; resolveCollision( x, _y, movedX, movedY, true ); return true; }
- }
- }
- if( !movedY ){
- if( ( cols2[1][2] || ( cols2[2][2] && !XE ) ) && _vspeed >= 0 && _y <= Y ) { _y = Y; _vspeed = 0; hasChanged = true; if( gravdir == G_DOWN ) onGround = true; resolveCollision( x, _y, movedX, true ); return true; }
- else if( gravdir == G_DOWN ) { onGround = false;}
- if( ( cols2[1][1] || ( cols2[2][1] && !XE ) ) && _vspeed < 0 && _y >= Y ) { _y = Y2; _vspeed = 0; if( gravdir == G_UP ) onGround = true; if( _hspeed < 0 && !cols3[0][1] ){ _x += _hspeed/10.0; } hasChanged = true; resolveCollision( x, _y, movedX, true ); return true; }
- else if( gravdir == G_UP ) { onGround = false;}
- }
- if( !movedX ){
- if( ( cols[1][1] || ( cols[1][2] && !YE ) ) && _hspeed < 0 ) { _x = X + 1; _hspeed = 0; if( gravdir == G_LEFT ) onGround = true; resolveCollision( _x, _y, true, movedY ); return true; }
- else if( gravdir == G_LEFT ) { onGround = false;}
- if( ( cols[2][1] || ( cols[2][2] && !YE ) ) && _hspeed > 0 ) { _x = X; _hspeed = 0; if( gravdir == G_RIGHT ) onGround = true; resolveCollision( _x, _y, true, movedY ); return true; }
- else if( gravdir == G_RIGHT ) { onGround = false;}
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement