Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///platforming_step()
- if p_grav_on && p_ground == noone && !on_wall && !on_ledge
- {
- p_vspd += p_grav*delta;
- }
- //Set delta variables to our constant speeds
- dx = p_hspd*delta;
- dy = p_vspd*delta;
- var mask;
- if mask_index != -1 mask = mask_index else mask = sprite_index;
- var r,tx,ty,col;
- //Get the absolute of DX
- r = abs(dx);
- /*HORIZONTAL MOVEMENT*/
- while r > 0
- {
- //Get whether we are moving left or right, and store the sign in tx.
- if r >= 1 { tx = sign(dx); }
- //Also handle fractional values of r.
- else { tx = frac(dx); }
- col = instance_place(x+tx,y,wall_obj);
- //If we do not encounter a collision, or that collision is not viable,
- // simply move the ourselves.
- 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; }
- else
- {
- //If the object is pushable and we can push objects ourselves
- if p_push and col.p_pushable
- {
- ds_list_clear(p_push_col_list);
- var done = 0;
- var pushobj = col;
- ds_list_add(p_push_col_list,pushobj);
- while !done
- {
- pushobj.x += tx+sign(dx);
- with pushobj {other.p_push_col = instance_place(x,y,platforming_obj);}
- //if there is no collision from the pushed
- if p_push_col == noone or p_push_col == id or !p_push_col.p_solid
- {
- done = true;
- x += tx;
- }
- else if p_push_col.p_pushable
- {
- pushobj = p_push_col;
- ds_list_add(p_push_col_list,p_push_col);
- }
- else
- {
- //Reverse movement for all
- for(var i = ds_list_size(p_push_col_list)-1;i>=0;i--)
- {
- p_push_col_list[|i].x -= tx+sign(dx);
- }
- //Flush all
- for(var i = ds_list_size(p_push_col_list)-2;i>=0;i--)
- {
- var c_pusher = p_push_col_list[|i];
- var c_pushed = p_push_col_list[|i+1];
- var colmask;
- if c_pusher.mask_index != -1 colmask = c_pusher.mask_index else colmask = c_pusher.sprite_index;
- var cols = c_pusher.image_xscale;
- var s = c_pushed.image_xscale;
- if c_pusher.bbox_left > c_pushed.bbox_right
- {
- c_pusher.x = c_pushed.bbox_right+(sprite_get_xoffset(colmask)*cols)-(sprite_get_bbox_left(colmask)*cols)+cols;
- }
- else if c_pusher.bbox_right < c_pushed.bbox_left
- {
- c_pusher.x = c_pushed.bbox_left-(sprite_get_xoffset(colmask)*cols)+((sprite_get_width(colmask)*cols)-(sprite_get_bbox_right(colmask)*cols))-cols;
- }
- r = 0;
- break;
- }
- done = true;
- }
- }
- //Move the object so we can see if it viabally collides with something.
- //col.x += tx+sign(dx);
- /*with col {other.p_push_col = instance_place(x,y,platforming_obj);}
- //If it doesn't, then move ourselves.
- if p_push_col == noone or p_push_col == id or !p_push_col.p_solid { x += tx; }
- else
- {
- var colmask;
- if col.mask_index != -1 colmask = col.mask_index else colmask = col.sprite_index;
- col.x -= tx+sign(dx);
- //Round both ourselves and the object we are pushing
- var cols = col.image_xscale;
- var s = image_xscale;
- if col.bbox_left > p_push_col.bbox_right
- {
- col.x = p_push_col.bbox_right+(sprite_get_xoffset(colmask)*cols)-(sprite_get_bbox_left(colmask)*cols)+1;
- }
- else if col.bbox_right < p_push_col.bbox_left
- {
- col.x = p_push_col.bbox_left-(sprite_get_xoffset(colmask)*cols)+((sprite_get_width(colmask)*cols)-(sprite_get_bbox_right(colmask)*cols))-2;
- }
- if bbox_left > col.bbox_right
- {
- x = col.bbox_right+(sprite_get_xoffset(mask)*s)-(sprite_get_bbox_left(mask)*s)+1;
- }
- else if bbox_right < col.bbox_left
- {
- x = col.bbox_left-(sprite_get_xoffset(mask)*s)+((sprite_get_width(mask)*s)-(sprite_get_bbox_right(mask)*s))-2;
- }
- /*if col.bbox_left > p_push_col.bbox_right col.x = ceil(x);
- else if col.bbox_right < p_push_col.bbox_left col.x = floor(x);/
- //Stop our horizontal speed, and exit the loop.
- //p_hspd = 0;
- r = 0;
- break;
- }*/
- }
- else
- {
- var s = image_xscale;
- //Else, stop ourselves.
- //Round our x depending what side of the object we are on
- if !(p_pushable and col.p_push)
- {
- if bbox_left > col.bbox_right
- {
- //x = floor(x);
- x = col.bbox_right+(sprite_get_xoffset(mask)*s)-(sprite_get_bbox_left(mask)*s)+s;
- }
- else if bbox_right < col.bbox_left
- {
- //x = ceil(x);
- x = col.bbox_left-(sprite_get_xoffset(mask)*s)+((sprite_get_width(mask)*s)-(sprite_get_bbox_right(mask)*s))-s;
- }
- }
- //Stop our horizontal speed, and exit the loop.
- //p_hspd = 0;
- break;
- }
- }
- r--;
- }
- //Get the absolute of DY
- r = abs(dy);
- /*VERTICAL MOVEMENT*/
- while r > 0
- {
- //Get whether we are moving left or right, and store the sign in tx.
- if r >= 1 { ty = sign(dy); }
- //Also handle fractional values of r.
- else { ty = frac(dy); }
- col = instance_place(x,y+ty,platforming_obj);
- //If we do not encounter a collision, or that collision is not viable,
- // simply move the ourselves.
- if col == noone or (!p_solid or !col.p_solid)
- or (col.p_jumpthrough and bbox_bottom >= col.bbox_top)
- or (p_jumpthrough and col.bbox_bottom > bbox_top)
- { y += ty; }
- else
- {
- //If the object is pushable and we can push objects ourselves
- if p_push and col.p_pushable
- {
- //Move the object so we can see if it viabally collides with something.
- col.y += ty+sign(dy);
- with col { other.p_push_col = instance_place(x,y,platforming_obj); }
- //If it doesn't, then move ourselves.
- 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; }
- else
- {
- var colmask = -1+sign(dy);
- if col.mask_index != -1 colmask = col.mask_index else colmask = col.sprite_index;
- col.y -= ty+sign(dy);
- dy = 0;
- var cols = col.image_yscale;
- var s = image_yscale;
- //make sure we and the pushed object are flat against the colliding object.
- if col.bbox_top > p_push_col.bbox_bottom
- {
- col.y = p_push_col.bbox_bottom+(sprite_get_yoffset(colmask)*cols)-(sprite_get_bbox_top(colmask)*cols)+s;
- }
- else if col.bbox_bottom < p_push_col.bbox_top
- {
- col.y = p_push_col.bbox_top-(sprite_get_yoffset(colmask)*cols)+((sprite_get_height(colmask)*cols)-(sprite_get_bbox_bottom(colmask)*cols))-cols;
- }
- if bbox_top > col.bbox_bottom
- {
- y = col.bbox_bottom+(sprite_get_yoffset(mask)*s)-(sprite_get_bbox_top(mask)*s)+s;
- }
- else if bbox_bottom < col.bbox_top
- {
- y = col.bbox_top-(sprite_get_yoffset(mask)*s)+((sprite_get_height(mask)*s)-(sprite_get_bbox_bottom(mask)*s))-s;
- }
- //Stop our horizontal speed, and exit the loop.
- //p_vspd = 0;
- break;
- }
- }
- else
- {
- var s = image_yscale;
- //Else, stop ourselves.
- //Round our x depending what side of the object we are on
- /*if bbox_top > col.bbox_bottom y = floor(y);
- else if bbox_bottom < col.bbox_top y = ceil(y);*/
- if !(p_pushable and col.p_push)
- {
- if bbox_top > col.bbox_bottom
- {
- y = col.bbox_bottom+(sprite_get_yoffset(mask)*s)-(sprite_get_bbox_top(mask)*s)+s;
- }
- else if bbox_bottom < col.bbox_top
- {
- y = col.bbox_top-(sprite_get_yoffset(mask)*s)+((sprite_get_height(mask)*s)-(sprite_get_bbox_bottom(mask)*s))-s;
- }
- }
- if col != p_ground and col.p_vspd >= 0
- {
- p_vspd = 0;
- }
- break;
- }
- }
- r--;
- }
- /* GROUND AND CEILING*/
- //Reset
- p_ground = noone;
- p_ceiling = noone;
- var obj = noone;
- //Are we falling or stopped?
- if dy >= 0
- {
- //Get the platforming object under us
- var checkwall = instance_place(x,y+1,wall_obj);
- obj = instance_place(x,y+1,platforming_obj);
- if (checkwall !=noone)
- {
- p_ground = checkwall;
- }
- else
- {
- //Negate the collision,
- if obj != noone
- {
- if !obj.p_solid //If it's not solid,
- 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.
- {
- obj = noone;
- }
- }
- p_ground = obj;
- }
- }
- else
- {
- //Else, we must be going up.
- obj = instance_place(x,y-1,platforming_obj);
- //Negate the collision,
- if obj != noone
- {
- if !obj.p_solid or obj.p_ladder //If it's solid,
- //or !obj.p_jumpthrough //If it's not a jump through
- {
- obj = noone;
- }
- }
- p_ceiling = obj;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement