Advertisement
MRDANEEYUL

ground_z_get()

Oct 21st, 2020
3,073
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ground_z_get(_x, _y){
  2.  
  3. #macro GROUND 96
  4.  
  5.     if (_x == undefined) _x = x;
  6.     if (_y == undefined) _y = y;
  7.    
  8.     with (collision_point(_x, _y, obj_ramp_parent, false, true))
  9.     {
  10.         if (upDirection == compass.east)
  11.             return clamp(other.bbox_right - bbox_left + z + 1, z, z + height);
  12.         else if (upDirection == compass.west)
  13.             return clamp(bbox_right - other.bbox_left + z + 1, z, z + height);
  14.         else if (upDirection == compass.north)
  15.             return clamp(bbox_bottom - other.bbox_top + z + 2, z, z + height);
  16.     }
  17.        
  18.     var _groundZ = null;
  19.     var _list = ds_list_create();
  20.     var _count = instance_place_list(_x, _y, obj_z, _list, false);
  21.     for (var i = 0; i < _count; i++)
  22.     {
  23.         var _objZ = _list[| i];    
  24.         if (id != _objZ.id && (!variable_instance_exists(id, "collisionMask") || collisionMask != _objZ.id))
  25.         {
  26.             with(_objZ)
  27.                 if (_groundZ == null || z + height > _groundZ)
  28.                     _groundZ = z + height;
  29.         }
  30.     }
  31.     if (_groundZ == null)
  32.         _groundZ = GROUND;
  33.        
  34.     var _northZInstance = -1;  
  35.     _count = collision_line_list(x, y + 5, x, bbox_top, obj_z, false, true, _list, false); 
  36.     if (_count == 1)
  37.         _northZInstance = _list[| i];
  38.     else if (_count > 1)
  39.         for (var i = 0; i < _count; i++)
  40.             with(_list[| i])
  41.                 if (_northZInstance == -1 || z + height > _northZInstance.z + _northZInstance.height)
  42.                     _northZInstance = _list[| i];
  43.     ds_list_destroy(_list);    
  44.     var _northZ = _northZInstance <= 0 ? GROUND : _northZInstance.z + _northZInstance.height;
  45.        
  46.     var _southZInstance = collision_point(x, y + 6, obj_z, false, true);
  47.     var _southZ = _southZInstance <= 0 ? GROUND : _southZInstance.z + _southZInstance.height;
  48.                
  49.     var _min = min(_northZ, _southZ);
  50.     var _max = max(_northZ, _southZ);
  51.    
  52.     if (_min != _max && z == _max && _southZ == _min && _southZ != _northZ
  53.      && collision_line(_x, _y, _x, _y + 7, obj_ramp_north_16, false, true) == null)
  54.     {      
  55.         var _targetY = y + 7 & (-8); //round up to nearest 8
  56.         var _diff = _targetY - y;
  57.         y = _targetY;
  58.        
  59.         var _conveyorTile = tile_get_at_point("Conveyor", x, y - z);
  60.         if(_conveyorTile == null || tile_get_empty(_conveyorTile))
  61.             z += _diff;
  62.                
  63.         _groundZ = _min;
  64.        
  65.         if (variable_instance_exists(id, "moveDirection") && moveDirection > 0 && moveDirection < 180)
  66.             moveSpeed = 0;
  67.     }
  68.    
  69.     if (variable_instance_exists(id, "state") && state == STATE_DIVE)
  70.         _groundZ -= height;
  71.    
  72.     return _groundZ;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement