Advertisement
Guest User

Untitled

a guest
Sep 1st, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. //Add to the counters, then get the h and v (pixels to move this step) from them.
  2. h_counter += hspd;
  3. v_counter += vspd;
  4. h_counter += test_h;
  5. v_counter += test_v;
  6. test_h = 0;
  7. test_v = 0;
  8. h = round( h_counter );
  9. v = round( v_counter );
  10. h_counter -= h;
  11. v_counter -= v;
  12.  
  13. //This loop will move the object based on hspd. The object will never
  14. //actually collide with a floor object, because this loop (and the next one for vspd)
  15. //will always position it right next to them without overlapping. If the
  16. //object collides with a wall, it will call one of two events:
  17. // User Event 0 - if the collision is horizontal
  18. // User Event 1 - if the collision is vertical
  19. collide = false;
  20. slope = false;
  21.  
  22. sign_h = sign(h);
  23. sign_v = sign(v);
  24.  
  25. // probably could re-write with place_meeting_left, etc.
  26. repeat (abs(h))
  27. {
  28. if (place_meeting(x + sign_h, y, obj_floor))
  29. {
  30. if (!place_meeting(x + sign_h, y - 1, obj_floor))
  31. {
  32. //Running up slopes
  33. y -= 1;
  34. x += sign_h;
  35. slope = true;
  36. }
  37. else
  38. {
  39. //Hit a wall
  40. collide = true;
  41. break;
  42. }
  43. }
  44. else
  45. {
  46. if (on_ground)
  47. {
  48. if (!place_meeting(x + sign_h, y + 1, obj_floor) && place_meeting(x + sign_h, y + 2, obj_floor))
  49. y += 1;
  50. }
  51. x += sign_h;
  52. }
  53. }
  54.  
  55. if (collide)
  56. event_perform(ev_other, ev_user0);
  57.  
  58. if (slope)
  59. hspd = approach(hspd, 0, S_SLOPE_SLOW);
  60.  
  61. collide = false;
  62. repeat (abs(v))
  63. {
  64. if (vspd <= 0)
  65. {
  66. if (place_meeting( x, y + sign_v, obj_floor))
  67. {
  68. collide = true;
  69. break;
  70. }
  71. else {
  72. y += sign_v;
  73. }
  74. }
  75. else if (check_below())
  76. {
  77. collide = true;
  78. break;
  79. }
  80. else {
  81. y += sign_v;
  82. }
  83. }
  84.  
  85. if (collide)
  86. event_perform( ev_other, ev_user1 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement