-
Notifications
You must be signed in to change notification settings - Fork 0
/
game(ver.1)
107 lines (69 loc) · 1.86 KB
/
game(ver.1)
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
import turtle
import random
speed = 1
screen = turtle.Screen()
screen.bgcolor('lightgreen')
screen.tracer(2)
myPen = turtle.Turtle()
myPen.speed(0)
myPen.penup()
myPen.setposition(-300, -300)
myPen.pendown()
myPen.pensize(3)
for i in range(4):
myPen.forward(600)
myPen.left(90)
myPen.hideturtle()
player = turtle.Turtle()
player.shape('triangle')
player.color('blue')
player.penup()
goals = []
goalCount = 6
for i in range(goalCount):
goals.append(turtle.Turtle())
goals[i].shape('circle')
goals[i].color('red')
goals[i].speed(200)
goals[i].penup()
goals[i].setposition(random.randint(-250, 250), random.randint(-250, 250))
speed = 1
score = 0
def Left():
player.left(30)
def Right():
player.right(30)
def Up():
global speed
speed += 1
def Down():
global speed
speed -= 1
turtle.listen()
turtle.onkey(Left, 'Left')
turtle.onkey(Right, 'Right')
turtle.onkey(Up, 'Up')
turtle.onkey(Down, 'Down')
while True:
player.forward(speed)
if player.xcor() > 300 or player.xcor() < -300:
player.right(180)
if player.ycor() > 300 or player.ycor() < -300:
player.right(180)
for i in range(goalCount):
if player.distance(goals[i]) < 20:
goals[i].setposition(random.randint(-280, 280), random.randint(-280, 280))
goals[i].right(random.randint(-90, 90))
myPen.undo()
myPen.penup()
myPen.hideturtle()
myPen.setposition(-290, 310)
scoreString = 'Score: %s' % score
myPen.write(scoreString, False, align='left', font=('Arial', 14, 'normal'))
score += 1
goals[i].forward(3)
if goals[i].xcor() > 300 or goals[i].xcor() < -300:
goals[i].right(180)
if goals[i].ycor() > 300 or goals[i].ycor() < -300:
goals[i].right(180)
screen.mainloop()