from turtle import *
from random import randint
class Game(Turtle):
def __init__(self,x,y,step = 10, shape = "circle", color = "black"):
super().__init__()
self.penup()
self.speed(0)
self.goto(x,y)
self.color(color)
self.shape(shape)
self.step = step
def move_up(self):
self.goto(self.xcor(), self.ycor() + 10)
def move_down(self):
self.goto(self.xcor(), self.ycor() - 10)
def move_left(self):
self.goto(self.xcor() - 10, self.ycor())
def move_right(self):
self.goto(self.xcor() + 10, self.ycor())
def Kasanie(self,Sprite1,Sprite2):
dis1 = self.distance(Sprite1.xcor(), Sprite1.ycor())
dis2 = self.distance(Sprite2.xcor(), Sprite2.ycor())
if dis1 < 30 or dis2 < 30:
return True
else:
return False
def Kasanie2(self,goal):
dis1 = self.distance(goal.xcor(), goal.ycor())
if dis1 < 30:
return True
else:
return False
player = Game(0, -100, 10, 'circle', 'orange')
Sprite1 = Game(-200, 200, 10, 'square', 'red')
Sprite2 = Game(200, 100, 10, 'square', 'red')
End = Game (0, 300, 10, 'triangle', 'Lime')
scr = player.getscreen()
scr.listen()
scr.onkey(player.move_up, "w")
scr.onkey(player.move_down, "s")
scr.onkey(player.move_left, "a")
scr.onkey(player.move_right, "d")
Inf1 = player.Kasanie(Sprite1,Sprite2)
Inf2 = player.Kasanie2(End)
total_score = 0
while total_score < 3:
if Inf1:
player.goto(0,-100)
total_score += 1
if Inf2:
End.hideturtle()
break
Sprite2.hideturtle()
Sprite1.hideturtle()
player.getscreen()._root.mainloop()
player.done()