Advertisement
Guest User

Untitled

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