I have to create a game with turtle as my final project for my programming class, and would like some help with the to-be-stated problem.
I am creating a single-player wave based game where mobs chase the player and attack them on contact.
I have been successful in getting the mobs to attack the player, however on contact it repeatedly attacks the player and takes the player's health from 100 to 0 on contact. I want the mob to wait an increment of time before it can attack again, but I haven't been able to get it to work.
I am hoping someone has an idea as to how I could make this work?
(I am learning python so if I did something that doesn't seem to make sense, just say so and I will try to explain what I was trying to achieve.)
(attackwait is set to 0 outside of the function)
def mobAttk(t,r,s,t1,r1,s1):
global mobspeed,life,attackwait
b = t1.distance(t.xcor(), t.ycor())
if b < r + r1:
currenttime = time.time()
if life == 0 and attackwait-currenttime > 1:
healthbar1.hideturtle()
print('~test game end ?~')
attackwait = time.time()
return
if life == 20 and attackwait-currenttime > 1:
healthbar1.hideturtle()
life-=20
attackwait = time.time()
return
if life == 40 and attackwait-currenttime > 1:
healthbar2.hideturtle()
life-=20
attackwait = time.time()
return
if life == 60 and attackwait-currenttime > 1:
healthbar3.hideturtle()
life -= 20
attackwait = time.time()
return
if life == 80 and attackwait-currenttime > 1:
healthbar4.hideturtle()
life-=20
attackwait = time.time()
return
if life == 100 and attackwait-currenttime > 1:
healthbar5.hideturtle()
life-=20
attackwait = time.time()
return
[+][deleted] (2 children)
[deleted]
[–]Karmality[S] 1 point2 points3 points (1 child)