Hi, I need help with Python. I'm not going to be using Pygame, and I'm working on a practice assignment for comp sci. The thing is, I'm stuck on hitboxes. I've looked it up and I've tried using the abs() method and infinite while loops. I need my hitboxes to recognize when they're within 50 pixels of another image/sprite, and it's not picking it up.
I have multiple functions in my lines of code to break down what's happening, and including this I've got my keybinding to "w" "a" "s" "d". This doesn't seem to be the problem though. Below I'll place my code from then on:
def up():
jeff.seth(90)
jeff.fd(20)
def down():
jeff.seth(270)
jeff.fd(20)
def right():
jeff.seth(0)
jeff.fd(20)
def left():
jeff.seth(180)
jeff.fd(20)
bob = Turtle()
a = Turtle("
badsnake.gif")
a.pu()
a.speed(0)
a.goto(random.randint(-400,400), random.randint(-400,400))
jeff = Turtle("capybara.gif")
jeff.color("blue")
jeff.speed(2)
jeff.pu()
print(jeff.pos())
a_hitbox= Turtle()
a_hitbox.color("red")
a_hitbox.pensize(5)
a_hitbox.speed(0)
a_hitbox.pu()
a_hitbox.goto(a.xcor()-30, a.ycor()-30)
a_hitbox.seth(90)
def border():
bob.color("red")
bob.pensize(5)
bob.speed(0)
bob.pu()
bob.goto(jeff.xcor()-45, jeff.ycor()-45)
a_hitbox.pd()
for i in range(4):
bob.forward(90)
a_hitbox.fd(60)
bob.left(90)
a_hitbox.right(90)
#bob.hideturtle() #makes turtle shape disappear
window.onkey(up, "w")
window.onkey(down, "s")
window.onkey(right, "d")
window.onkey(left, "a")
while True: #declares an infinite loop
border()
if bob.pos() == a_hitbox.pos():
print("Collision")
window.listen()