Hello, nice game !
I just noticed the non-player characters aren't turning around if you pass them and aren't jumping with you, to make the game more cooler, you may consider these parts :
- Easy difficulty -> the game as it is now.
- Medium -> add the NPC turn around firing you from your back while escaping him.
- Hard -> add the NPC jump with you.
- Realistic -> add NPC can fire multiple things or take 2 of your life points if you hit his bullet.
Some hints :
- How to know your location with respect to the NPC ?
=> Assuming you are at point 0 and the NPC at point 10 game units, then :
/**
* Positions the NPC to face the player and
* controls the NPC melee attack.
*/
void attackLoop(tpf) {
const var distance = npc.getNPCLocation() - player.getPlayerLocation();
if (distance < 0) {
npc.faceToScreenLeft();
} else if (distance > 0) {
npc.faceToScreenRight();
} else {
npc.activateMeleeAttack();
}
}
void update(tpf) {
attackLoop(tpf);
}
What this basically does, is it gets the linear distance (not 3d distance), if the distance is zero then npc activates melee attack, distance is less than zero then that means the player is before the npc so position npc facing the left of the screen, and vice versa in case of the distance bigger than zero, you can optimize this more using the math stdlib of js.
Note : i didn't look at the sources, if you are using Vector2
or threejs then you better use the distance formula = sqrt (pow(x2 - x1, 2) + pow(y2 - y1, 2));
.