What way would you suggest for placing the enemy characters in a top-down game that scrolls screen-by-screen? (I.e. the enemies are loaded anew with every new scren.)
Declaring what kinds of enemies and how many appear on every screen is pretty simple.
But how do I do their initial placement on the screen if I don't want to have them start in a fixed location?
First of all, they shouldn't be allowed to appear too close to the hero. So, when the hero enters the screen from the left, they cannot be positioned too far on the left side, so that he doesn't get hit unfairly.
Then there's the problem that they shouldn't be allowed to be placed in tiles that are walls, unless they can fly.
I have an array of 16 x 15 bytes that defines which tiles are walls and which are walking ground.
So, generating a random number from 0 to 239 isn't a problem.
After generating it, I could adjust the value and move the position up, down left or right if the character would be too close to the player's side.
And if the value points to a wall, I could simply add 1 until it doesn't anymore, but this would mean that tiles right from a wall are more likely to be picked than other tiles.
But do you know of any other, more elegant ways of choosing enemy start positions on a screen?
Declaring what kinds of enemies and how many appear on every screen is pretty simple.
But how do I do their initial placement on the screen if I don't want to have them start in a fixed location?
First of all, they shouldn't be allowed to appear too close to the hero. So, when the hero enters the screen from the left, they cannot be positioned too far on the left side, so that he doesn't get hit unfairly.
Then there's the problem that they shouldn't be allowed to be placed in tiles that are walls, unless they can fly.
I have an array of 16 x 15 bytes that defines which tiles are walls and which are walking ground.
So, generating a random number from 0 to 239 isn't a problem.
After generating it, I could adjust the value and move the position up, down left or right if the character would be too close to the player's side.
And if the value points to a wall, I could simply add 1 until it doesn't anymore, but this would mean that tiles right from a wall are more likely to be picked than other tiles.
But do you know of any other, more elegant ways of choosing enemy start positions on a screen?