The reason is because in your delete enemies function the first 'enemy' the bullet collides with is the 'player' 'nav' type and so it deletes the 'player' 'nav' type instance which means when the code gets to the userinput function the 'player' instance is now null so it crashes as soon as it is referred to.
What you need to do to fix it is to prevent the player's own bullets from colliding with it.
Also, if I were to give advice I would suggest not using a global type called 'player' but simply have a field within the 'nav' type object which flags whether the nav is an enemy or a player (you could even do the ball/bullet in there as well).
What you need to do to fix it is to prevent the player's own bullets from colliding with it.
Also, if I were to give advice I would suggest not using a global type called 'player' but simply have a field within the 'nav' type object which flags whether the nav is an enemy or a player (you could even do the ball/bullet in there as well).