Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.20 KB | None | 0 0
  1. ///platforming_step()
  2.  
  3. if p_grav_on && p_ground == noone && !on_wall && !on_ledge
  4. {
  5. p_vspd += p_grav*delta;
  6. }
  7.  
  8. //Set delta variables to our constant speeds
  9. dx = p_hspd*delta;
  10. dy = p_vspd*delta;
  11.  
  12.  
  13. if (p_ground != noone && p_ground.p_carry && !instance_place(x,y+1,wall_obj) && !instance_place(x,y-1,wall_obj))
  14. {
  15. dx += p_ground.p_hspd;
  16. dy += p_ground.p_vspd;
  17. }
  18.  
  19. var mask;
  20. if mask_index != -1 mask = mask_index else mask = sprite_index;
  21.  
  22. var r,tx,ty,col;
  23.  
  24.  
  25. //Get the absolute of DX
  26. r = abs(dx);
  27.  
  28. /*HORIZONTAL MOVEMENT*/
  29. while r > 0
  30. {
  31. //Get whether we are moving left or right, and store the sign in tx.
  32. if r >= 1 { tx = sign(dx); }
  33. //Also handle fractional values of r.
  34. else { tx = frac(dx); }
  35.  
  36. col = instance_place(x+tx,y,wall_obj);
  37.  
  38. //If we do not encounter a collision, or that collision is not viable,
  39. // simply move the ourselves.
  40. if col == noone or (!p_solid or !col.p_solid) or col.p_jumpthrough or (p_jumpthrough and col.bbox_bottom > bbox_top) { x += tx; }
  41. else
  42. {
  43. //If the object is pushable and we can push objects ourselves
  44. if p_push and col.p_pushable
  45. {
  46.  
  47. ds_list_clear(p_push_col_list);
  48.  
  49. var done = 0;
  50. var pushobj = col;
  51. ds_list_add(p_push_col_list,pushobj);
  52.  
  53. while !done
  54. {
  55. pushobj.x += tx+sign(dx);
  56.  
  57. with pushobj {other.p_push_col = instance_place(x,y,platforming_obj);}
  58.  
  59. //if there is no collision from the pushed
  60. if p_push_col == noone or p_push_col == id or !p_push_col.p_solid
  61. {
  62. done = true;
  63. x += tx;
  64. }
  65. else if p_push_col.p_pushable
  66. {
  67. pushobj = p_push_col;
  68. ds_list_add(p_push_col_list,p_push_col);
  69. }
  70. else
  71. {
  72. //Reverse movement for all
  73. for(var i = ds_list_size(p_push_col_list)-1;i>=0;i--)
  74. {
  75. p_push_col_list[|i].x -= tx+sign(dx);
  76. }
  77.  
  78.  
  79. //Flush all
  80.  
  81. for(var i = ds_list_size(p_push_col_list)-2;i>=0;i--)
  82. {
  83. var c_pusher = p_push_col_list[|i];
  84. var c_pushed = p_push_col_list[|i+1];
  85. var colmask;
  86.  
  87. if c_pusher.mask_index != -1 colmask = c_pusher.mask_index else colmask = c_pusher.sprite_index;
  88.  
  89. var cols = c_pusher.image_xscale;
  90. var s = c_pushed.image_xscale;
  91.  
  92.  
  93. if c_pusher.bbox_left > c_pushed.bbox_right
  94. {
  95. c_pusher.x = c_pushed.bbox_right+(sprite_get_xoffset(colmask)*cols)-(sprite_get_bbox_left(colmask)*cols)+cols;
  96. }
  97. else if c_pusher.bbox_right < c_pushed.bbox_left
  98. {
  99. c_pusher.x = c_pushed.bbox_left-(sprite_get_xoffset(colmask)*cols)+((sprite_get_width(colmask)*cols)-(sprite_get_bbox_right(colmask)*cols))-cols;
  100. }
  101.  
  102. r = 0;
  103. break;
  104. }
  105.  
  106. done = true;
  107. }
  108.  
  109. }
  110. //Move the object so we can see if it viabally collides with something.
  111.  
  112. //col.x += tx+sign(dx);
  113.  
  114. /*with col {other.p_push_col = instance_place(x,y,platforming_obj);}
  115.  
  116. //If it doesn't, then move ourselves.
  117. if p_push_col == noone or p_push_col == id or !p_push_col.p_solid { x += tx; }
  118. else
  119. {
  120. var colmask;
  121. if col.mask_index != -1 colmask = col.mask_index else colmask = col.sprite_index;
  122. col.x -= tx+sign(dx);
  123. //Round both ourselves and the object we are pushing
  124.  
  125. var cols = col.image_xscale;
  126. var s = image_xscale;
  127.  
  128. if col.bbox_left > p_push_col.bbox_right
  129. {
  130. col.x = p_push_col.bbox_right+(sprite_get_xoffset(colmask)*cols)-(sprite_get_bbox_left(colmask)*cols)+1;
  131. }
  132. else if col.bbox_right < p_push_col.bbox_left
  133. {
  134. col.x = p_push_col.bbox_left-(sprite_get_xoffset(colmask)*cols)+((sprite_get_width(colmask)*cols)-(sprite_get_bbox_right(colmask)*cols))-2;
  135. }
  136.  
  137.  
  138. if bbox_left > col.bbox_right
  139. {
  140. x = col.bbox_right+(sprite_get_xoffset(mask)*s)-(sprite_get_bbox_left(mask)*s)+1;
  141. }
  142. else if bbox_right < col.bbox_left
  143. {
  144. x = col.bbox_left-(sprite_get_xoffset(mask)*s)+((sprite_get_width(mask)*s)-(sprite_get_bbox_right(mask)*s))-2;
  145. }
  146. /*if col.bbox_left > p_push_col.bbox_right col.x = ceil(x);
  147. else if col.bbox_right < p_push_col.bbox_left col.x = floor(x);/
  148.  
  149.  
  150. //Stop our horizontal speed, and exit the loop.
  151. //p_hspd = 0;
  152. r = 0;
  153. break;
  154. }*/
  155. }
  156. else
  157. {
  158. var s = image_xscale;
  159. //Else, stop ourselves.
  160. //Round our x depending what side of the object we are on
  161. if !(p_pushable and col.p_push)
  162. {
  163. if bbox_left > col.bbox_right
  164. {
  165. //x = floor(x);
  166. x = col.bbox_right+(sprite_get_xoffset(mask)*s)-(sprite_get_bbox_left(mask)*s)+s;
  167. }
  168. else if bbox_right < col.bbox_left
  169. {
  170. //x = ceil(x);
  171. x = col.bbox_left-(sprite_get_xoffset(mask)*s)+((sprite_get_width(mask)*s)-(sprite_get_bbox_right(mask)*s))-s;
  172. }
  173. }
  174.  
  175.  
  176. //Stop our horizontal speed, and exit the loop.
  177. //p_hspd = 0;
  178. break;
  179. }
  180. }
  181.  
  182. r--;
  183. }
  184.  
  185. //Get the absolute of DY
  186. r = abs(dy);
  187.  
  188. /*VERTICAL MOVEMENT*/
  189. while r > 0
  190. {
  191. //Get whether we are moving left or right, and store the sign in tx.
  192. if r >= 1 { ty = sign(dy); }
  193. //Also handle fractional values of r.
  194. else { ty = frac(dy); }
  195.  
  196. col = instance_place(x,y+ty,platforming_obj);
  197.  
  198. //If we do not encounter a collision, or that collision is not viable,
  199. // simply move the ourselves.
  200. if col == noone or (!p_solid or !col.p_solid)
  201. or (col.p_jumpthrough and bbox_bottom >= col.bbox_top)
  202. or (p_jumpthrough and col.bbox_bottom > bbox_top)
  203. { y += ty; }
  204. else
  205. {
  206. //If the object is pushable and we can push objects ourselves
  207. if p_push and col.p_pushable
  208. {
  209. //Move the object so we can see if it viabally collides with something.
  210. col.y += ty+sign(dy);
  211. with col { other.p_push_col = instance_place(x,y,platforming_obj); }
  212.  
  213. //If it doesn't, then move ourselves.
  214. if p_push_col == noone or p_push_col == id or !p_push_col.p_solid or (p_push_col.p_jumpthrough and dy < 0) {y += ty; }
  215. else
  216. {
  217. var colmask = -1+sign(dy);
  218. if col.mask_index != -1 colmask = col.mask_index else colmask = col.sprite_index;
  219.  
  220. col.y -= ty+sign(dy);
  221. dy = 0;
  222.  
  223. var cols = col.image_yscale;
  224. var s = image_yscale;
  225.  
  226. //make sure we and the pushed object are flat against the colliding object.
  227. if col.bbox_top > p_push_col.bbox_bottom
  228. {
  229. col.y = p_push_col.bbox_bottom+(sprite_get_yoffset(colmask)*cols)-(sprite_get_bbox_top(colmask)*cols)+s;
  230. }
  231. else if col.bbox_bottom < p_push_col.bbox_top
  232. {
  233. col.y = p_push_col.bbox_top-(sprite_get_yoffset(colmask)*cols)+((sprite_get_height(colmask)*cols)-(sprite_get_bbox_bottom(colmask)*cols))-cols;
  234. }
  235.  
  236.  
  237. if bbox_top > col.bbox_bottom
  238. {
  239. y = col.bbox_bottom+(sprite_get_yoffset(mask)*s)-(sprite_get_bbox_top(mask)*s)+s;
  240. }
  241. else if bbox_bottom < col.bbox_top
  242. {
  243. y = col.bbox_top-(sprite_get_yoffset(mask)*s)+((sprite_get_height(mask)*s)-(sprite_get_bbox_bottom(mask)*s))-s;
  244. }
  245.  
  246. //Stop our horizontal speed, and exit the loop.
  247. //p_vspd = 0;
  248. break;
  249. }
  250. }
  251. else
  252. {
  253. var s = image_yscale;
  254.  
  255. //Else, stop ourselves.
  256. //Round our x depending what side of the object we are on
  257. /*if bbox_top > col.bbox_bottom y = floor(y);
  258. else if bbox_bottom < col.bbox_top y = ceil(y);*/
  259. if !(p_pushable and col.p_push)
  260. {
  261. if bbox_top > col.bbox_bottom
  262. {
  263. y = col.bbox_bottom+(sprite_get_yoffset(mask)*s)-(sprite_get_bbox_top(mask)*s)+s;
  264. }
  265. else if bbox_bottom < col.bbox_top
  266. {
  267. y = col.bbox_top-(sprite_get_yoffset(mask)*s)+((sprite_get_height(mask)*s)-(sprite_get_bbox_bottom(mask)*s))-s;
  268. }
  269. }
  270.  
  271. if col != p_ground and col.p_vspd >= 0
  272. {
  273. p_vspd = 0;
  274. }
  275.  
  276. break;
  277. }
  278. }
  279.  
  280. r--;
  281. }
  282.  
  283. /* GROUND AND CEILING*/
  284.  
  285. //Reset
  286. p_ground = noone;
  287. p_ceiling = noone;
  288.  
  289. var obj = noone;
  290.  
  291. //Are we falling or stopped?
  292. if dy >= 0
  293. {
  294. //Get the platforming object under us
  295. obj = instance_place(x,y+1,platforming_obj);
  296.  
  297. //Negate the collision,
  298. if obj != noone
  299. {
  300. if !obj.p_solid //If it's solid,
  301. or (obj.p_jumpthrough and bbox_bottom > obj.bbox_top) //If it's jump through and we're lower than the top of its bounding box.
  302. {
  303. obj = noone;
  304. }
  305. }
  306.  
  307. p_ground = obj;
  308.  
  309. }
  310. else
  311. {
  312. //Else, we must be going up.
  313.  
  314. obj = instance_place(x,y-1,platforming_obj);
  315.  
  316. //Negate the collision,
  317. if obj != noone
  318. {
  319. if !obj.p_solid or obj.p_ladder //If it's solid,
  320. //or !obj.p_jumpthrough //If it's not a jump through
  321. {
  322. obj = noone;
  323. }
  324. }
  325.  
  326. p_ceiling = obj;
  327. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement