R
rawket
Guest
So I have two log objects, one vertical and one horizontal. I have made them able to roll based on their orientation but I want to make it so that pushing from the end allows you to slide them but only if they are fully on a certain type of object and there is room on that object for them to slide. Their aligned on a 16x16 grid. So for example (G means grass(grass isn't an object just a lack of the slideable object), S means slideable surface) SSSS a log could slide across this if the log was three squares long but couldn't slide across this SGSS and in the first example it couldn't slide across it if the log was 4 squares long because there isn't room. I can figure out how to push the log but I cant figure out how to make the log tell if it is fully on the slideable object and if it has room to move. I want to make a variable that when true, you can slide the log, and when false you cannot. And in order for it to be true each 16x16 square must be occupied by the slideable object under the log plus an extra 16 pixels of length to the slideablle object to give room for the log to slide.
The image I've attached should show the cases for which the log can or cannot move the brown rectangles are the slideablle surface object and the log is labelled, it's the sectioned black rectangle. In the top left, it can't move because there is no slideable object. Top right can't slide because the log isn't fully on slideable objects. Bottom left because there isn't any slideable surface beyond either end to give it room. And in the bottom right it can slide because the log is totally on a slideable surface object and there is room beyond one end. Also the slideable surface objects are merely for function, they do not move only the log moves. And the surface objects will be invisible. If there is a way to do this that's what I'm trying to do or maybe there is a better way?
Here is the code for one of those logs, specifically the horizontal one. The vertical one is pretty much identical just with variables swapped out to make it work vertically rather than horizontally.
Create Event:----------------------------------------------------------------------
logLen = ((bbox_right - bbox_left) / 16) - 1;
rolling = 0;
img = 0;
hsp = 0;
vsp = 0;
moved = 0;
Step Event:----------------------------------------------------------------------
depth = -y;
if rolling == 0
{
if (abs(bbox_top - obj_player.y) <= 1) || (abs(obj_pllayer.y - 9 - bbox_bottom) <= 1)
{
alarm[0] = 10;
rolling = 1;
}
}else if rolling == 2
{
if (moved < 16) && (vsp != 0)
{
moved++;
}
else
{
moved = 0;
vsp = 0;
rolling = 0;
}
scr_moveAndCollide();
if vsp > 0
{
if (img >6) img = 0;
img += 0.5;
}
else if vsp < 0
{
img -= 0.5;
if (img < 0) img = 6;
}
}
Draw Event:-------------------------------------------
draw_set_alpha(0.25);
draw_set_color(c_black);
draw_rectangle(bbox_left + 1, y - 1, bbox_right - 1, y + 4, 0);
draw_rectangle(bbox_left, y - 1, bbox_right, y + 3, 0);
draw_set_alpha(1);
draw_set_color(c_white);
for(i = 1; i < logLen; i++)
{
draw_sprite(spr_logMid_rollV, img, x + (i * 16) - 1, y);
}
draw_sprite(spr_logLeft_rollV, img, x, y);
for(i = 1; i < logLen; i++)
{
draw_sprite(spr_logMid_rollV, img, x + (i * 16), y);
}
draw_sprite(spr_logRight_rollV, img, x + 1 + logLen * 16, y);
Allarm 0:-----------------------------------------------------
rolling = 2;
if (abs(bbox_top - obj_player.y) <= 1) && (obj_player.key_down) && (!obj_player.key_left) && (!obj_player.key_right) && (obj_player.x > bbox_left) && (obj_player.x < bbox_right)
{
vsp = -1;
}
if (obj_player.y > y) && (obj_player.key_up) && (!obj_player.key_left) && (!obj_player.key_right) && (obj_player.x > bbox_left) && (obj_player.x < bbox_right)
{
vsp = 1;
}
The image I've attached should show the cases for which the log can or cannot move the brown rectangles are the slideablle surface object and the log is labelled, it's the sectioned black rectangle. In the top left, it can't move because there is no slideable object. Top right can't slide because the log isn't fully on slideable objects. Bottom left because there isn't any slideable surface beyond either end to give it room. And in the bottom right it can slide because the log is totally on a slideable surface object and there is room beyond one end. Also the slideable surface objects are merely for function, they do not move only the log moves. And the surface objects will be invisible. If there is a way to do this that's what I'm trying to do or maybe there is a better way?
Here is the code for one of those logs, specifically the horizontal one. The vertical one is pretty much identical just with variables swapped out to make it work vertically rather than horizontally.
Create Event:----------------------------------------------------------------------
logLen = ((bbox_right - bbox_left) / 16) - 1;
rolling = 0;
img = 0;
hsp = 0;
vsp = 0;
moved = 0;
Step Event:----------------------------------------------------------------------
depth = -y;
if rolling == 0
{
if (abs(bbox_top - obj_player.y) <= 1) || (abs(obj_pllayer.y - 9 - bbox_bottom) <= 1)
{
alarm[0] = 10;
rolling = 1;
}
}else if rolling == 2
{
if (moved < 16) && (vsp != 0)
{
moved++;
}
else
{
moved = 0;
vsp = 0;
rolling = 0;
}
scr_moveAndCollide();
if vsp > 0
{
if (img >6) img = 0;
img += 0.5;
}
else if vsp < 0
{
img -= 0.5;
if (img < 0) img = 6;
}
}
Draw Event:-------------------------------------------
draw_set_alpha(0.25);
draw_set_color(c_black);
draw_rectangle(bbox_left + 1, y - 1, bbox_right - 1, y + 4, 0);
draw_rectangle(bbox_left, y - 1, bbox_right, y + 3, 0);
draw_set_alpha(1);
draw_set_color(c_white);
for(i = 1; i < logLen; i++)
{
draw_sprite(spr_logMid_rollV, img, x + (i * 16) - 1, y);
}
draw_sprite(spr_logLeft_rollV, img, x, y);
for(i = 1; i < logLen; i++)
{
draw_sprite(spr_logMid_rollV, img, x + (i * 16), y);
}
draw_sprite(spr_logRight_rollV, img, x + 1 + logLen * 16, y);
Allarm 0:-----------------------------------------------------
rolling = 2;
if (abs(bbox_top - obj_player.y) <= 1) && (obj_player.key_down) && (!obj_player.key_left) && (!obj_player.key_right) && (obj_player.x > bbox_left) && (obj_player.x < bbox_right)
{
vsp = -1;
}
if (obj_player.y > y) && (obj_player.key_up) && (!obj_player.key_left) && (!obj_player.key_right) && (obj_player.x > bbox_left) && (obj_player.x < bbox_right)
{
vsp = 1;
}
Attachments
-
225.7 KB Views: 4
Last edited by a moderator: