I have a code where I randomly generate enemy spawn position, but I want to exclude some areas since it's colliding with some sprites it shouldn't collide with.
This is the code where I generate the random points from where the enemy is coming from (from top,down, left and right):
int z = ran.nextInt(4);
int r1 = ran.nextInt(GameControl.CAMARA_WIDTH+1);
int r2 = ran.nextInt(GameControl.CAMARA_WIDTH+ 1);
int r3 = ran.nextInt(GameControl.CAMARA_HEIGHT+ 1);
int r4 = ran.nextInt(ControlJuego.CAMARA_HEIGHT+ 1);
I set the position of the enemy with the random variable:
if (var == 1) {
newEnemy.getSpriteEnemy().setPosition(0, r1);
} else if (var == 2) {
newEnemy.getSpriteEnemy().setPosition(GameControl.CAMARA_WIDTH, r2);
} else if (var == 3) {
newEnemy.getSpriteEnemy().setPosition(r3, 0);
} else if (var == 4) {
newEnemy.getSpriteEnemy().setPosition(r4, GameControl.CAMARA_HEIGHT);
}
Later I move the enemies to the center of the screen.
An image for better vistualizatio of the problem:
I don't want my enemies to ever spawn behind any of the corner sprites or to collide with any of the corner sprites before entering the screen. How can I solve this problem? How can I exclude this areas?
Thanks in advance for the help.