-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
126 lines (90 loc) · 2.29 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import turtle
import random
score = 105
t = turtle.Turtle()
t.color("black")
obstacle = turtle.Turtle()
obstacle.shape("square")
obstacle.color("red")
obstacle.up()
obstacle.forward(100)
obstacle.left(90)
obstacle.forward(100)
obstacle2 = turtle.Turtle()
obstacle2.shape("square")
obstacle2.color("red")
obstacle2.up()
obstacle2.left(90)
obstacle2.forward(50)
obstacle2.right(90)
obstacle2.forward(50)
obstacle3 = turtle.Turtle()
obstacle3.shape("square")
obstacle3.color("red")
obstacle3.up()
obstacle3.left(90)
obstacle3.forward(120)
obstacle4 = turtle.Turtle()
obstacle4.shape("square")
obstacle4.color("red")
obstacle4.up()
obstacle4.forward(100)
obstacle4.goto(-50, 90)
finish = turtle.Turtle()
finish.color("green")
finish.shape("circle")
finish.up()
finish.goto(100, 150)
def win():
if t.distance(finish) < 20:
print("YOu win .. and you are amzing")
return True
def collision():
if t.distance(obstacle) < 20:
return True
elif t.distance(obstacle2) < 20:
return True
elif t.distance(obstacle3) < 20:
return True
elif t.distance(obstacle4) < 20:
return True
# for i in range(10):
# t.forward(100)
# type.right(90)
# controls
# list of obstacles
obstacles = [obstacle, obstacle2, obstacle3, obstacle4]
def movingObstacle(move):
if move % 2 == 0:
for i in obstacles:
angle = random.randint(0, 360)
displacement = random.randint(-60, 60)
i.right(angle)
i.forward(displacement)
if i.position()[0] > 200 or i.position()[0] < -200:
i.goto(0, 0)
else:
obstacle2.backward(100)
move = 0
while True:
print("a - left , w - forward , s - backwards, d - right, q - quit")
control = input("Enter :")
if control == "w":
t.forward(50)
elif control == "a":
t.left(90)
elif control == "q":
break
elif control == "s":
t.forward(-50)
elif control == "d":
t.right(90)
movingObstacle(move)
if collision():
print("You lose ")
break
if win():
print("Your score was: ",score)
break
move += 1
score -= 1