+ 1
How do I let enemies damage the player?
The Python course here has a "simple game" project at the end of object oriented programming. I decided to iterate on it further by adding more enemies as well as data for player character in a class called Player(GameObject). I figured out how to heal the player and allow us to hit ourselves. I need help writing code so that when "Hit" is used to attack the enemy, player also takes some damage. Player's health is stored self.health in Player(GameObject). How do I go about doing this? Also, I want to make it so that the program only runs while player's health is above zero. Thanks in advance!
1 Odpowiedź
+ 1
if player_hit:
eneme_health -= 10
player_health -= 5
- You can decide how much health each will lose
add inside the while loop the following:
if player_health <= 0:
break
- This should break out of the loop when the player got down to 0 and end the game
- Change the variables to match your own.
Hope this helps!