| 164 | } |
| 165 | |
| 166 | bool Entity::tileIntersectionTest(StaticObject* ptile, Collision& collision, |
| 167 | unsigned short flags) |
| 168 | { |
| 169 | float pl = position.x + leftPadding; |
| 170 | float pr = position.x + size.x - rightPadding; |
| 171 | float pb = position.y + bottomPadding; |
| 172 | float pt = position.y + size.y - topPadding; |
| 173 | float pcx = position.x + size.x * 0.5f; |
| 174 | float tl = ptile->position.x; |
| 175 | float tr = ptile->position.x + ptile->size.x; |
| 176 | float tb = ptile->position.y; |
| 177 | float tt = ptile->position.y + ptile->size.y; |
| 178 | |
| 179 | bool xintersects = false; |
| 180 | bool yintersects = false; |
| 181 | |
| 182 | float mtd_x = 0.0f; |
| 183 | float mtd_y = 0.0f; |
| 184 | |
| 185 | if ((pl < tl && pr > tl)) |
| 186 | { |
| 187 | xintersects = true; |
| 188 | mtd_x = tl - pr; |
| 189 | } |
| 190 | else if ((pr > tr && pl < tr)) |
| 191 | { |
| 192 | xintersects = true; |
| 193 | mtd_x = tr - pl; |
| 194 | } |
| 195 | else if ((pl >= tl && pr <= tr)) |
| 196 | { |
| 197 | xintersects = true; |
| 198 | mtd_x = min(tl - pr, tr - pl); |
| 199 | } |
| 200 | else if ((pl <= tl && pr >= tr)) |
| 201 | { |
| 202 | xintersects = true; |
| 203 | mtd_x = min(tl - pr, tr - pl); |
| 204 | } |
| 205 | |
| 206 | if ((pb < tb && pt > tb)) |
| 207 | { |
| 208 | yintersects = true; |
| 209 | mtd_y = tb - pt; |
| 210 | } |
| 211 | else if ((pt > tt && pb < tt)) |
| 212 | { |
| 213 | yintersects = true; |
| 214 | mtd_y = tt - pb; |
| 215 | } |
| 216 | else if ((pb >= tb && pt <= tt)) |
| 217 | { |
| 218 | yintersects = true; |
| 219 | mtd_y = min(tb - pt, tt - pb); |
| 220 | } |
| 221 | else if ((pb <= tb && pt >= tt)) |
| 222 | { |
| 223 | yintersects = true; |