-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
42 lines (32 loc) · 959 Bytes
/
player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from turtle import Turtle
STARTING_POSITION = (0, -280)
MOVE_DISTANCE = 10
FINISH_LINE_Y = 280
class Player(Turtle):
def __init__(self):
super().__init__()
self.penup()
self.color("black")
self.shape("turtle")
self.setheading(90)
self.start()
def start(self):
self.goto(STARTING_POSITION)
def move_up(self):
x_new = self.xcor()
y_new = self.ycor() + MOVE_DISTANCE
self.goto((x_new, y_new))
def move_down(self):
x_new = self.xcor()
y_new = self.ycor() - MOVE_DISTANCE
self.goto((x_new, y_new))
def move_left(self):
x_new = self.xcor() - MOVE_DISTANCE
y_new = self.ycor()
self.goto((x_new, y_new))
def move_right(self):
x_new = self.xcor() + MOVE_DISTANCE
y_new = self.ycor()
self.goto((x_new, y_new))
def at_finish_line(self):
return self.ycor() > FINISH_LINE_Y