a3qz / hag

An ncurses procedurally generated roguelike dungeon crawler
Other
20 stars 18 forks source link

Enemy doesn't spawn on player #105

Closed neilong31 closed 5 years ago

neilong31 commented 5 years ago

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.

neilong31 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

Yes, exactly

neilong31 commented 5 years ago

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
JohnathonNow commented 5 years ago

Thanks!