| 293 | } |
| 294 | |
| 295 | bool Entity::entityIntersectionTest(Entity* pentity, Collision& collision) |
| 296 | { |
| 297 | float al = position.x + leftPadding; |
| 298 | float area = position.x + size.x - rightPadding; |
| 299 | float ab = position.y + bottomPadding; |
| 300 | float at = position.y + size.y - topPadding; |
| 301 | float bl = pentity->position.x + pentity->leftPadding; |
| 302 | float br = pentity->position.x + pentity->size.x - pentity->rightPadding; |
| 303 | float bb = pentity->position.y + pentity->bottomPadding; |
| 304 | float bt = pentity->position.y + pentity->size.y - pentity->topPadding; |
| 305 | |
| 306 | bool xintersects = false; |
| 307 | bool yintersects = false; |
| 308 | |
| 309 | float mtd_x = 0.0f; |
| 310 | float mtd_y = 0.0f; |
| 311 | |
| 312 | if ((al < bl && area > bl)) |
| 313 | { |
| 314 | xintersects = true; |
| 315 | mtd_x = bl - area; |
| 316 | } |
| 317 | else if ((area > br && al < br)) |
| 318 | { |
| 319 | xintersects = true; |
| 320 | mtd_x = br - al; |
| 321 | } |
| 322 | else if ((al >= bl && area <= br)) |
| 323 | { |
| 324 | xintersects = true; |
| 325 | mtd_x = min(bl - area, br - al); |
| 326 | } |
| 327 | else if ((al <= bl && area >= br)) |
| 328 | { |
| 329 | xintersects = true; |
| 330 | mtd_x = min(bl - area, br - al); |
| 331 | } |
| 332 | |
| 333 | if ((ab < bb && at > bb)) |
| 334 | { |
| 335 | yintersects = true; |
| 336 | mtd_y = bb - at; |
| 337 | } |
| 338 | else if ((at > bt && ab < bt)) |
| 339 | { |
| 340 | yintersects = true; |
| 341 | mtd_y = bt - ab; |
| 342 | } |
| 343 | else if ((ab >= bb && at <= bt)) |
| 344 | { |
| 345 | yintersects = true; |
| 346 | mtd_y = min(bb - at, bt - ab); |
| 347 | } |
| 348 | else if ((ab <= bb && at >= bt)) |
| 349 | { |
| 350 | yintersects = true; |
| 351 | mtd_y = min(bb - at, bt - ab); |
| 352 | } |