Advertisement
Aslai

Untitled

Mar 31st, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.72 KB | None | 0 0
  1. void Player::handle_collisions(){
  2.             int ax = (__x + __hspeed) / Global.Block.Size -1;
  3.             for( int x = ax; x < ax + 2; x ++ )
  4.                 for( int y = (floor(__y-__h))/Global.Block.Size; y< (floor(__y)+__h)/Global.Block.Size+1; ++y )
  5.                 {
  6.                     if( __y - __h < (y + 1) * Global.Block.Size && __y + __h - Global.Block.Size / 16 > (y) * Global.Block.Size &&
  7.                        __x + __hspeed >= x * Global.Block.Size && __x + __hspeed <= (x+1) * Global.Block.Size &&
  8.                        !(__x >= x * Global.Block.Size && __x  <= (x+1) * Global.Block.Size) ){
  9.                         if( __hspeed > 0 || isdown.right ){
  10.                             if( Global.Play->GetMap()->Data()[x][y].left == true ){
  11.                                 if( __x + __hspeed >= ((x) * Global.Block.Size) ){
  12.                                     if( isdown.right ){
  13.                                         if( y <= __y-__h ){
  14.                                             __vspeed = 0;
  15.                                             state = 10;
  16.                                         }
  17.                                     }
  18.                     __x = (x * Global.Block.Size)-1;
  19.                                     __hspeed = 0;
  20.                                     break;
  21.                                 }
  22.                             }
  23.                         }
  24.                         if( __hspeed < 0 ){
  25.                             if( Global.Play->GetMap()->Data()[x][y].right == true ){
  26.                                 if( __x + __hspeed <= ((x+1) * Global.Block.Size) ){
  27.                                     __x = ((x+1) * Global.Block.Size)+1;
  28.                                     __hspeed = 0;
  29.                                     break;
  30.                                 }
  31.                             }
  32.                         }
  33.                     }
  34.  
  35.                 }
  36.     int ay = (__y + __h - Global.Block.Size/2) / Global.Block.Size;
  37.     if( __vspeed > 0 )
  38.         for( int y = ay; y < ay + 2; y ++ )
  39.             for( int x = (floor(__x-__w))/Global.Block.Size; x<= (floor(__x)+__w)/Global.Block.Size; ++x )
  40.             {
  41.                 if( __x + __hspeed >= (x) * Global.Block.Size && __x + __hspeed <= (x+1) * Global.Block.Size ){
  42.  
  43.                     double ydelta = Global.Play->GetMap()->Data()[x][y].get_delta( __x + __hspeed, __y + __h + __vspeed, x*Global.Block.Size, y*Global.Block.Size );
  44.                     if( ydelta != 0 ){
  45.                         __y = floor( __y + ydelta + __vspeed );
  46.                         __vspeed = 0;
  47.                         canjump = true;
  48.                     }
  49.                     if( Global.Play->GetMap()->Data()[x][y].down == true ){
  50.                         if( __y + __vspeed + Global.Block.Size / 8 + __h > ((y) * Global.Block.Size) ){
  51.                             canjump = true;
  52.                         }
  53.                     }
  54.                 }
  55.             }
  56.  
  57.     ay = (__y - __h - Global.Block.Size/2) / Global.Block.Size;
  58.     if( __vspeed < 0 )
  59.         for( int y = ay; y < ay + 2; y ++ )
  60.             for( int x = (floor(__x-__w))/Global.Block.Size; x<= (floor(__x)+__w)/Global.Block.Size; ++x )
  61.                 {
  62.                     //printf("---X: %i; Y: %i\n", x, y);
  63.                     if( __x + __hspeed >= (x) * Global.Block.Size && __x + __hspeed <= (x+1) * Global.Block.Size ){
  64.                         if( Global.Play->GetMap()->Data()[x][y].down == true ){
  65.                             if( __y + __vspeed - __h < ((y+1) * Global.Block.Size) ){
  66.                                 __y = ((y+1) * Global.Block.Size) + __h;
  67.                                 __vspeed = 0;
  68.                             }
  69.                         }
  70.                     }
  71.                 }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement