The physics engine currently works, but upon adding more things, the machine will start running slow. Here is how it currently works:
Begin looping through entities
Get the location and dimensions of the entity
Now loop through every tile.
Do the entity interesect top and bottom? Move the entity out and give it ground status
Do the entity interesect side to side? Move the entity out on the side
Now loop to see if it collides with other entities (ie boxes)
Check the type of entity and handle collision as needed
This is REALLY inefficient. It works well because it checks everything, but for a platformer, this level of collision detection is over the top. I recommend looking into AABB, Axis Aligned Bouinding Box. Axis Aligned Bounding Box works by checking only the things around the entity. It then gets the depth in the X and Y direction, checking if it has actually collided, as well as seeing how deep in each direction it has collided. Which ever depth is more shallow, you negate and push it out. This method works well and every thing in this game is easily represented as an axis aligned bounding box.
The physics engine currently works, but upon adding more things, the machine will start running slow. Here is how it currently works:
This is REALLY inefficient. It works well because it checks everything, but for a platformer, this level of collision detection is over the top. I recommend looking into AABB, Axis Aligned Bouinding Box. Axis Aligned Bounding Box works by checking only the things around the entity. It then gets the depth in the X and Y direction, checking if it has actually collided, as well as seeing how deep in each direction it has collided. Which ever depth is more shallow, you negate and push it out. This method works well and every thing in this game is easily represented as an axis aligned bounding box.