Advertisement
TheSkipper1995

Mega Man Utility Spawning Script

Nov 3rd, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This script assumes Mega Man's x and y origins are centered in the sprite editor
  2. var x_check = objMegaman.x;
  3. var y_check = objMegaman.y;
  4. var dir = objMegaman.image_xscale;
  5. var block_up = noone;
  6. var block_over = noone;
  7. var block_down = noone;
  8. var depth_limit;
  9. if (objMegaman.weapon == RushJet)
  10.     depth_limit = objMegaman.y;
  11. else
  12.     depth_limit = (view_yview + view_hview);
  13. var found_landing_point = false;
  14. var utility = argument[0];
  15.  
  16. //Check up
  17. for (var i = y_check ; i <= y_check - 32; i--;) {
  18.     block_up = collision_rectangle(x_check - 4, i, x_check + 4, y_check, objSolid)) {
  19.     if (instance_exists(block_up)) {
  20.         y_check = (block_up.bbox_bottom + 1);
  21.         break;
  22.     }
  23. }
  24. if (!instance_exists(block_up))
  25.     y_check -= 32;
  26.  
  27. //Check over
  28. for (var i = x_check + (4 * -dir); i != x_check + (24 * dir); i += (1 * dir);) {
  29.     if (dir > 0)
  30.         block_over = collision_rectangle(x_check - 4, y_check, x_check + 4 + i, y_check + 8, objSolid);
  31.     else
  32.         block_over = collision_rectangle(x_check + 4 + i, y_check, x_check + 4, y_check + 8, objSolid);
  33.     if (instance_exists(block_over)) {
  34.         var box;
  35.         if (dir > 0)
  36.             box = (block_over.bbox_left - 1);
  37.         else
  38.             box = (block_over.bbox_right + 1);
  39.         x_check = box;
  40.         break;
  41.     }
  42. }
  43. if (!instance_exists(block_over))
  44.     x_check += (28 * dir);
  45.  
  46. //Check down
  47. for (var i = y_check; i <= depth_limit; i++) {
  48.     if (dir > 0)
  49.         block_down = collision_rectangle(x_check - 8, y_check, x_check, i, objSolid);
  50.     else
  51.         block_down = collision_rectangle(x_check, y_check, x_check + 8, i, objSolid);
  52.     if ((i >= depth_limit && global.weapon == Rush Jet) || (instance_exists(block_down))) {
  53.         if (global.weapon != Rush Jet) {
  54.             if (instance_exists(block_down))
  55.                 y_check = block_down.bbox_top;
  56.         }
  57.         else
  58.             y_check = depth_limit;
  59.         found_landing_point = true;
  60.         break;
  61.     }
  62. }
  63.  
  64. if (found_landing_point) {
  65.     instance_create(x_check, y_check, utility);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement