-
Notifications
You must be signed in to change notification settings - Fork 0
/
1st_gui_game.main.py
205 lines (166 loc) · 4.18 KB
/
1st_gui_game.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import turtle
import random
import math
delay =0
score=0
t=turtle.Screen()
t.bgcolor("black")
t.tracer(0)
#creating Boundary
ca=random.choice(["violet","darkgreen","chocolate"])
s=random.choice(["red","skyblue","yellow","lightgreen"])
p=random.choice(["gold","navy","purple","green","cyan","orange"])
k=random.choice(["gold","red","purple","green","cyan","orange"])
mybound=turtle.Turtle()
mybound.color("yellow")
mybound.penup()
mybound.setposition(-300,-300)
mybound.pendown()
mybound.pensize(10)
mybound.hideturtle()
for side in range(4):
mybound.fd(600)
mybound.left(90)
#CREATING TURTLE
a=turtle.Turtle()
#x=random.choice(["white","red","purple","green","cyan","yellow"])
a.color(s)
a.shape("arrow")
a.shapesize(2,2,2)
#placing
a.penup()
a.goto(0,-250)
#a.pendown()
#writing text 1
#pen1=turtle.Turtle()
#pen1.color("red")
#pen1.penup()
#pen1.hideturtle()
#pen1.goto(0,-300)
#pen1.write("Score had been deducted",font=("courier",8,"normal"))
#writing text 2
pen=turtle.Turtle()
pen.speed(0)
pen.color("white")
pen.penup()
pen.hideturtle()
pen.goto(00,300)
pen.write("ESCAPE LEVEL-01",align="center",font=("courier",8,"normal"))
#Warning for the gamer
# Border Color
bd_1=turtle.Turtle()
bd_1.color(p)
bd_1.shape("square")
bd_1.shapesize(35,23,20)
bd_1.penup()
bd_1.goto(-550,0)
#border color 2
bd_2=turtle.Turtle()
bd_2.color(p)
bd_2.shape("square")
bd_2.shapesize(35,23,20)
bd_2.penup()
bd_2.goto(550,0)
#Elements 1
em_1=turtle.Turtle()
em_1.color("red")
em_1.shape("circle")
em_1.shapesize(1)
em_1.penup()
em_1.speed(0)
em_1.setposition(-100,-100)
#Enemy 1
enem1=turtle.Turtle()
enem1.shape("turtle")
enem1.color(ca)
enem1.shapesize(2)
enem1.penup()
enem1.goto(-290,-40)
#ch_1=random.randint(5,9)
ch_2=random.randint(5,8)
enem1xdirection=ch_2
#Enemy 2
enem2=turtle.Turtle()
enem2.shape("classic")
enem2.color(p)
enem2.shapesize(3)
enem2.penup()
enem2.goto(-290,50)
#ch_2=random.randint(1,5)
enem2xdirection=ch_2
#enemy 3
enem3=turtle.Turtle()
enem3.shape("turtle")
enem3.color(k)
enem3.shapesize(2)
enem3.penup()
enem3.goto(-290,150)
#ch_3=random.randint(5,8)
enem3xdirection=ch_2
#movement
def f():
a.fd(30)
def l():
a.bk(30)
def r():
a.right(-90)
def b():
a.left(-90)
turtle.onkeypress(f,"Left")
turtle.onkeypress(l,"Right")
turtle.onkeypress(r,"Up")
turtle.onkeypress(b,"Down")
turtle.listen()
while True:
t.update()
#Moving The enemy
enem1.setx(enem1.xcor()+enem1xdirection)
enem2.setx(enem2.xcor()+enem2xdirection)
enem3.setx(enem3.xcor()+enem3xdirection)
if enem1.xcor()>290:
for i in range(1):
enem1.setx(-290)
if enem2.xcor()>290:
for i in range(1):
enem2.setx(-290)
if enem3.xcor()>290:
for i in range(1):
enem3.setx(-290)
if a.xcor()>300 or a.xcor()<-300:
a.rt(-90)
# else:
if a.ycor()>300 or a.ycor()<-300:
a.rt(-90)
#1st
d=math.sqrt(math.pow(enem1.xcor()-a.xcor(),2)+math.pow(enem1.ycor()-a.ycor()-a.ycor(),2))
if d<100:
enem1.hideturtle()
enem1.st()
score=score+0.25
enem1.delay=0.2
pen.clear()
pen.write("SCORE :{}".format(score),align="center",font=("arial",8,"normal"))
t.reset()
#2nd
de=math.sqrt(math.pow(enem2.xcor()-a.xcor(),2)+math.pow(enem2.ycor()-a.ycor()-a.ycor(),2))
if de<80:
enem2.hideturtle()
enem2.st()
enem2.delay=0.2
pen.clear()
pen.write("SCORE :{}".format(score),align="center",font=("arial",8,"normal"))
t.reset()
#3rd
df=math.sqrt(math.pow(em_1.xcor()-a.xcor(),2)+math.pow(em_1.ycor()-a.ycor()-a.ycor(),2))
if df<100:
em_1.setposition(random.randint(-200,300),random.randint(-200,300))
score=score+1
pen.clear()
pen.write("SCORE:{}".format(score),align="center",font=("arial",8,"normal"))
db=math.sqrt(math.pow(enem3.xcor()-a.xcor(),2)+math.pow(enem3.ycor()-a.ycor()-a.ycor(),2))
if db<100:
enem3.hideturtle()
enem3.st()
t.reset()
turtle.mainloop()
turtle.done()