Skip to content
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

Merged
merged 3 commits into from Nov 2, 2019

Conversation

neilong31
Copy link
Contributor

@neilong31 neilong31 commented Oct 11, 2019

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.

Copy link
Owner

@a3qz a3qz left a 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.

  1. this will not actually work, get_player_x and y are functions that need to be called.
  2. 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.

@neilong31
Copy link
Contributor Author

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.

@a3qz
Copy link
Owner

a3qz commented Oct 12, 2019

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.

@neilong31
Copy link
Contributor Author

Okay, I think I understand. So before setting,

    int up_y;
    int up_x;
    int down_y;
    int down_x;

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.
Is that correct?

@a3qz
Copy link
Owner

a3qz commented Oct 12, 2019

Yes, exactly

@neilong31
Copy link
Contributor Author

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:

  1. Create Stairs
  2. Loop through enemy_list
  3. If any enemy is at that generated stairs location, regenerate stairs
  4. Point the list back to the head and loop again
  5. If it never enters the if statement the list is traversed and the stairs stay

@neilong31 neilong31 requested a review from a3qz October 19, 2019 03:54
@JohnathonNow
Copy link
Collaborator

Thanks!

@JohnathonNow JohnathonNow merged commit 6f574d2 into a3qz:master Nov 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enemies can spawn on top of you
3 participants