Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Player::handle_collisions(){
- int ax = (__x + __hspeed) / Global.Block.Size -1;
- for( int x = ax; x < ax + 2; x ++ )
- for( int y = (floor(__y-__h))/Global.Block.Size; y< (floor(__y)+__h)/Global.Block.Size+1; ++y )
- {
- if( __y - __h < (y + 1) * Global.Block.Size && __y + __h - Global.Block.Size / 16 > (y) * Global.Block.Size &&
- __x + __hspeed >= x * Global.Block.Size && __x + __hspeed <= (x+1) * Global.Block.Size &&
- !(__x >= x * Global.Block.Size && __x <= (x+1) * Global.Block.Size) ){
- if( __hspeed > 0 || isdown.right ){
- if( Global.Play->GetMap()->Data()[x][y].left == true ){
- if( __x + __hspeed >= ((x) * Global.Block.Size) ){
- if( isdown.right ){
- if( y <= __y-__h ){
- __vspeed = 0;
- state = 10;
- }
- }
- __x = (x * Global.Block.Size)-1;
- __hspeed = 0;
- break;
- }
- }
- }
- if( __hspeed < 0 ){
- if( Global.Play->GetMap()->Data()[x][y].right == true ){
- if( __x + __hspeed <= ((x+1) * Global.Block.Size) ){
- __x = ((x+1) * Global.Block.Size)+1;
- __hspeed = 0;
- break;
- }
- }
- }
- }
- }
- int ay = (__y + __h - Global.Block.Size/2) / Global.Block.Size;
- if( __vspeed > 0 )
- for( int y = ay; y < ay + 2; y ++ )
- for( int x = (floor(__x-__w))/Global.Block.Size; x<= (floor(__x)+__w)/Global.Block.Size; ++x )
- {
- if( __x + __hspeed >= (x) * Global.Block.Size && __x + __hspeed <= (x+1) * Global.Block.Size ){
- double ydelta = Global.Play->GetMap()->Data()[x][y].get_delta( __x + __hspeed, __y + __h + __vspeed, x*Global.Block.Size, y*Global.Block.Size );
- if( ydelta != 0 ){
- __y = floor( __y + ydelta + __vspeed );
- __vspeed = 0;
- canjump = true;
- }
- if( Global.Play->GetMap()->Data()[x][y].down == true ){
- if( __y + __vspeed + Global.Block.Size / 8 + __h > ((y) * Global.Block.Size) ){
- canjump = true;
- }
- }
- }
- }
- ay = (__y - __h - Global.Block.Size/2) / Global.Block.Size;
- if( __vspeed < 0 )
- for( int y = ay; y < ay + 2; y ++ )
- for( int x = (floor(__x-__w))/Global.Block.Size; x<= (floor(__x)+__w)/Global.Block.Size; ++x )
- {
- //printf("---X: %i; Y: %i\n", x, y);
- if( __x + __hspeed >= (x) * Global.Block.Size && __x + __hspeed <= (x+1) * Global.Block.Size ){
- if( Global.Play->GetMap()->Data()[x][y].down == true ){
- if( __y + __vspeed - __h < ((y+1) * Global.Block.Size) ){
- __y = ((y+1) * Global.Block.Size) + __h;
- __vspeed = 0;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement