I guess you want something like the following:
- if player hits top of enemy, then kill enemy
- if player hits side or bottom of enemy, then kill player
I assume you are already using a standard rectangle intersection check to determine if player + enemy collide.
If they do collide, then you can compare previous and current positions of the player’s bottom edge, with the previous and current positions of the enemy’s top edge. A bit like this in pseudo code:
if (player collides with enemy) and (player.previous.bottom.y was above enemy.previous.top.y) and (player.bottom.y is below enemy.top.y)
player has hit top of enemy, so kill enemy
else
player has hit left, right or bottom of enemy, so kill player
Note that this isn’t completely accurate, but it’s quite simple to code and has always worked well enough for me.