I was just able to get the code, and I’ve been looking at it. It seems a bit hard to follow and daunting to look at, even though the theory behind it is relatively simple. I think it would be good if the code were restructured so that it was easier to use.
For example, collision checking.
Here are the various collision checks:
//Right wall
collision_line(bbox_right+m_hspeed,bbox_top,bbox_right+m_hspeed,bbox_bottom,obj_block_parent,true,true)
//Left wall
collision_line(bbox_left+m_hspeed,bbox_top,bbox_left+m_hspeed,bbox_bottom,obj_block_parent,true,true)
//Ceiling
collision_line(bbox_left+m_hspeed,bbox_top-1,bbox_right+m_hspeed,bbox_top-1,obj_block_parent,true,true)
//Floor
collision_line(bbox_left,bbox_bottom+m_vspeed+1,bbox_right,bbox_bottom+m_vspeed+1,obj_block_parent,true,true)
Now, I don’t see anything wrong with these per se, but it seems like they can be combined into a function that can be more easily managed:
//Collision detection rough design (non-slope)
//Precondition: Object's X and Y coordinates exist on the map, and the object
//to check for a collision with is on the map. As well, the first object has a known
//bounding box and horizontal movement of some sort.
//Postcondition: If a collision would occur, a true will return, else false
//Argument 0: First object's ID, so the bounding box can be determined.
//Argument 1: Second object's ID, for the same reason.
//Argument 2: Which side to check on (0, 1, 2, 3 for top, right, bottom, left respectively)
obj1 = argument0;
obj2 = argument1;
sideToCheck = argument2;
collision = false;
switch (sideToCheck)
{
case 0: //Top case, so the top of the object collision code goes here
if (collision_line(obj1.bbox_left, obj1.bbox_top + obj1.m_vspeed + 1, obj1.bbox_right, obj1.bbox_top + obj1.m_vspeed + 1, obj2, true, true)) {
collision = true;
}
break;
case 1: //Right case, so the right side of the object collision code goes here
if (collision_line(obj1.bbox_right + obj1.m_hspeed, obj1.bbox_top, obj1.bbox_right + obj1.m_hspeed, obj1.bbox_bottom, obj2, true, true)) {
collision = true;
}
break;
case 2: //Bottom case, so the bottom of the object collision code goes here
if (collision_line(obj1.bbox_left, obj1.bbox_bottom + obj1.m_vspeed + 1, obj1.bbox_right, obj1.bbox_bottom + obj1.m_vspeed + 1,obj2, true, true)) {
collision = true;
}
break;
case 3: //Left case, so the left of the object collision code goes here
if (collision_line(obj1.bbox_left + obj1.m_hspeed, obj1.bbox_top, obj1.bbox_left + obj1.m_hspeed, obj1.bbox_bottom, obj2, true, true)) {
collision = true;
}
break;
}
return collision;
When I implemented this, it worked fine, using function calls such as (note I was just testing this theory, thus the name test_theory):
test_theory(obj_samus, obj_block_parent, 0)
test_theory(obj_samus, obj_block_parent, 1)
It should be theoretically possible to use this basic code for any two objects colliding provided they have the variables required. It would even be possible to define constants to TOP, RIGHT, LEFT, and DOWN to make the third parameter in entry something like
test_theory(obj_samus, obj_block_parent, LEFT)
Any thoughts? I was just bored and wanting to try and help in any way, and when I tried to use the code I was a bit waggledehooed, so I figured eh, maybe this would be helpful.
shrug