Untitled
unknown
plain_text
9 months ago
1.8 kB
8
Indexable
from turtle import*
class Sprite (Turtle):
def __init__(self, x, y, step=10, shape='circle', color='black'):
Turtle.__init__(self)
self.penup()
self.speed(0)
self.color(color)
self.goto(x,y)
self.step = step
self.shape(shape)
self.points = 0
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)
def is_collide(self, sprite):
dist= self.distance(sprite.xcor(),sprite.ycor())
if dist <30:
return True
else:
return False
def move_up(self):
self.goto(self.xcor(),self.ycor()+self.step)
def move_rigth(self):
self.goto(self.xcor()+self.step,self.ycor())
player = Sprite(0, -130, 10, 'circle', 'orange')
enimigo1 = Sprite(0, 0, 15,'square', ' red ')
enimigo1.set_move(-200, 0, 200, 0)
enimigo2 = Sprite(0, 70 , 15, 'square', 'red')
enimigo2.set_move(200,70, -200,70)
objetive= Sprite(0,150,50,'triangle','green')
contador= 0
while contador < 3:
if player.is_collide(objetive):
player.goto(0,-130)
contador+= 1
if player.is_collide(enimigo1) or condicion 2:
ocultamos el objetivo
break
src = player.getscreen()
src.listen()
src.onkey(player.move_up,'Up')
src.onkey(player.move_rigth,'Right')
enimigo1.make_step()
enimigo2.make_step()
enimigo1.hideturtle()
enimigo2.hideturtle()Editor is loading...
Leave a Comment