I'm fairly new to creating a 2D game in java and I'd love some help. I'm trying to create a sort of knock back effect the enemies have on you. So when you are touched by a enemy you will:
lose life
be knocked back a few pixels
I thought about saying something simple such as:
if ((player.x & player.y) == (enemy.x & enemy.y)){
player.x += 8;
player.y += 8;
}
But seeing as this will only push you back with no hope of moving while being pushed, I didn't want to use it. Is there any simple, yet effective way for going about this?