for (int i = 0; i < length; i++) {
- if (CheckCollisionRecs(charrect, ground[i])) {
- collrect = GetCollisionRect(charrect, ground[i]);
- if (ground[i].position.x > charrect.x) { depth.x = (int)(collrect.width) * -1; } else { depth.x = (int)(collrect.width) };
- if (ground[i].position.y > charrect.y) { depth.y = (int)(collrect.height) * -1; } else { depth.y = (int)(collrect.height) };
+ groundrect.x = ground[i].position.x;
+ groundrect.y = ground[i].position.y;
+ groundrect.width=ground[i].size.x;
+ groundrect.height=ground[i].size.y;
+ if (CheckCollisionRecs(charrect, groundrect)) {
+ collrect = GetCollisionRec(charrect, groundrect);
+ if (collrect.height > 1) {
+ if (ground[i].position.x > charrect.x) { depth.x = (int)(collrect.width) * -1; } else { depth.x = (int)(collrect.width);};
+ if (ground[i].position.y > charrect.y) { depth.y = (int)(collrect.height) * -1; } else { depth.y = (int)(collrect.height);};
+ return depth;
+ }
+ }
}
return depth;
}
{
chara->position.x += ceil(chara->velocity.x * delta);
chara->position.y += ceil(chara->velocity.y * delta);
+ struct Vector2 depth;
+ depth = infloor(chara, ground, length);
+ while ((depth.y != 0) && (depth.x != 0)) {
+ chara->position.x += depth.x;
+ chara->position.y += depth.y;
+ depth = infloor(chara, ground, length);
+ }
return 1;
}