Я пишу игру Hit It! Выполняю по заданию (при необходимости я могу отправить его). Во время работы я столкнулся с проблемой "[35:8] 'Sprite' object has no attribute 'x_end'". Я не знаю, почему это произошло, пожалуйста, помогите!
from turtle import *
class Sprite(Turtle):
def __init__(self, x, y, step=10, color='black', shape='circle'):
super().__init__()
self.pu()
self.speed(0)
self.color(color)
self.shape(shape)
self.goto(x, y)
self.step = step
def move_up(self):
self.goto(self.xcor(), self.ycor() + self.step)
def move_left(self):
self.goto(self.xcor() - self.step, self.ycor())
def move_right(self):
self.goto(self.xcor() + self.step, self.ycor())
def move_down(self):
self.goto(self.xcor(), self.ycor() - self.step)
def is_collide(self, sprite):
dist = self.distance(sprite.xcor(), sprite.ycor())
if dist < 30:
return True
else:
return False
def set_move(self, x_start, y_start, x_end, y_end):
self.x_start = x_start
self.y_start = y_start
self.x_end = x_end
self.y_end = y_end
self.goto(x_start, y_start)
self.setheading(self.towards(x_end, y_end))
def make_step(self):
self.forward(self.step)
if self.distance(self.x_end, self.y_end) < self.step:
self.set_move(self.x_end, self.y_end, self.x_start, self.y_start)
score = 0
player = Sprite(0, -100, 10, 'orange', 'circle')
enemy1 = Sprite(-150, -50, 10, 'red', 'square')
enemy2 = Sprite(150, 35, 10, 'red', 'square')
goal = Sprite(0, 100, 10, 'green', 'triangle')
screen = player.getscreen()
screen.listen()
screen.onkey(player.move_up, 'Up')
screen.onkey(player.move_left, 'Left')
screen.onkey(player.move_right, 'Right')
screen.onkey(player.move_down, 'Down')
while score < 3:
enemy1.make_step()
if player.is_collide(goal):
player.goto(0, -100)
score += 1
elif player.is_collide(enemy1) or player.is_collide(enemy2):
goal.hideturtle()
break
enemy1.hideturtle()
enemy2.hideturtle()