New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enemy doesn't spawn on player #105
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For two reasons, I would prefer this done differently.
- this will not actually work, get_player_x and y are functions that need to be called.
- This will result in the enemy not getting added. Instead, let's do this check in the call to enemy_add, when the x and y values are generated.
Thanks for the quick response! I totally forgot to finish the function call, thank you! Also, I switched the position of the check to be in front of enemy_add in the floor.c file. It's while loop that continues to randomize the enemies x and y position until it doesn't match the players. |
This is actually still not effective, as enemy placements are done during initialization. What we need to do actually is do this based on the location of the stairs, not the player - maybe we just want to re-calculate the stairs, if they pick a location with an enemy on them. |
Okay, I think I understand. So before setting,
which I am assuming are the coordinates for the stairs. I should check if there is an enemy spawned at those locations. If there is an enemy, then I should recalculate the coordinates. |
Yes, exactly |
Thanks for you patience with me. Hopefully this code is what you wanted and I am using list_traverse correctly. The logic goes as follows:
|
Thanks! |
Fix #92 :
Added an if statement in enemy_add to check if the x and y position passed is the same as the player's. If it is I return 0. Is this alright or would you like me to change it?
I was also thinking of writing a while loop within floor_init() before line 82 in floor.c to check of the position we give the enemy is the same as user and randomize the position until they are not the same.