Physics- Something that's been holding back me for a while

It’s been quite some time that I’ve been trying to get something done, but I am getting stuck on a pretty ridiculous obstacle.
All I wanted to do was a plataformer, with physics similar to Terraria (not the building/break part, just the physics). i.e 2D grid-like world with moving entities.

I think the part I’m messing up is the algorithm, can you guys help me get past this?
Here’s what I thought while writing this thread:
On each game loop:

  • Iterate through all entities
    – Update their positions based on their current motions (posX += motionX and posY += motionY)
    – Check if they collide with the grid-world (blocks) and update their positions so they don’t overlap with the blocks
  • Iterate through all entities a second time
    – Inside the current entity iteration, iterate with all entities that are not the current one
    — Check if they collided, if they do, do the following:
    ---- Teleport the entity to where the collision happened [¹]
    ---- Give damage or something, basically call some onCollidedWith method, make it invencible for 1 second or 2

I just improvised this algorithm, because I don’t have anything else in mind? What should I do to have a properly functional 2d grid world?
Btw this part: [¹] - Brings me some confusion because, since there are many entities, I think it would cause some physical bugs in case 3 entities were moving and 2 collided where there shouldn’t have a collision due to another collision that should have taken place before the previous collision.
This is very hard to explain but basically, what confuses me is the order in which the collision responses are to be executed.
Besides, my algorithm also looks very slow (iterate through all entities 3 times?).

My last resort is to humbly ask for a less poor algorithm, that would be responsive but at the same time not overwhelmingly hard to implement, this all must be very simple and the fact that I’ve been stuck past this point has been bugging me so much. Any input is appreciated.

Did you consider using a physics engine, like box2d?

I mean, it is possible to check all these entities, but you’ll really have to make sure you have a really good algorithm, and perform culling correctly in order for it to work quickly enough.

Yes but I thought these provide too much for something that should be apparently simple.
Also, I’d like to resort to the less external engine as possible.

Although I ommited on the algorithm, the entities wouldn’t iterate with the whole world, there would be array-grids holding the entities so they only iterate with those who matter. Also I don’t know what culling is :-\

Culling is when we only run updates (or in this case physics checks) upon things that we know matter.

So if youve got a box thats off camera and isnt moving, why bother slowing your algorithm with it.

Edit :

Culling (Culled)
Something picked out from others, especially something rejected because of inferior quality.

So basically just skip the entities that aren’t moving or offscreen?
Sounds simple enough I guess.