-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16A-cannon.py
More file actions
49 lines (40 loc) · 844 Bytes
/
16A-cannon.py
File metadata and controls
49 lines (40 loc) · 844 Bytes
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
import turtle as t
import random
def turn_up():
t.left(2)
def turn_down():
t.right(2)
def fire():
ang=t.heading()
while t.ycor()>0:
t.forward(15)
t.right(5)
d=t.distance(target,0)
t.sety(random.randint(10,100))
if d<25:
t.color("blue")
t.write("Good!",False,"center",("",15))
else:
t.color("red")
t.write("Bad!",False,"center",("",15))
t.color("black")
t.goto(-200,10)
t.setheading(ang)
t.goto(-300,0)
t.down()
t.goto(300,0)
target=random.randint(50,150)
t.pensize(3)
t.color("green")
t.up()
t.goto(target-25,2)
t.down()
t.goto(target+25,2)
t.color("black")
t.up()
t.goto(-200,10)
t.setheading(20)
t.onkeypress(turn_up,"Up")
t.onkeypress(turn_down,"Down")
t.onkeypress(fire,"space")
t.listen()