forked from meet-projects/meet2018y1final-proj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
final_working.py
375 lines (296 loc) · 7.89 KB
/
final_working.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
import turtle
import random
whats_up = input('hey you are going to see a river now just cross it and do something')
print(whats_up)
turtle.bgpic('backg.gif')
turtle.register_shape('adg.gif')
joe=turtle.clone()
joe.shape('adg.gif')
joe.penup()
joe.goto(0, -250)
#river location
turtle.tracer(1,0)
##river drawing
turtle.penup()
turtle.goto(0, 210)
turtle.pendown()
turtle.goto(1000,210)
turtle.goto(-1000,210)
turtle.penup()
turtle.goto(-1000, -170)
turtle.pendown()
turtle.goto(1000,-170)
scorev = 0
turtle.tracer(1,.05)
##make the bing##
turtle.register_shape("a.gif")
bin1 = turtle.clone()
bin1.shape("a.gif")
bin1.penup()
bin1.goto(-240,350)
turtle.register_shape("b.gif")
bin2 = turtle.clone()
bin2.shape("b.gif")
bin2.penup()
bin2.goto(0,350)
turtle.register_shape("c.gif")
bin3 = turtle.clone()
bin3.shape("c.gif")
bin3.penup()
bin3.goto(240,350)
def score(positionscore):
turtle.undo()
global scorev
turtle.goto(positionscore)
scorev += 1
turtle.hideturtle()
turtle.write(scorev, font=("Arial", 16, "normal"))
#turtles showness
turtle.hideturtle()
joe.penup()
#how much you move
SQUARE_SIZE=60
#directions
UP = 0
DOWN = 1
LEFT = 2
RIGHT = 3
direction = UP
#arrow keys
UP_ARROW = "Up"
LEFT_ARROW = "Left"
DOWN_ARROW = "Down"
RIGHT_ARROW = "Right"
lock = True
safe1 = turtle.clone()
safe2 = turtle.clone()
safe2 = turtle.clone()
#direction function
def up():
global direction
direction=UP
print("You pressed the up key!")
move_joe()
turtle.onkeypress(up, UP_ARROW)
#turtle.listen()
def down():
global direction
direction=DOWN
print("You pressed the down key!")
move_joe()
turtle.onkeypress(down,DOWN_ARROW)
#turtle.listen()
def left():
global direction
direction=LEFT
print("You pressed the left key!")
move_joe()
turtle.onkeypress(left, LEFT_ARROW)
#turtle.listen()
def right():
global direction
direction=RIGHT
print("You pressed the right key!")
move_joe()
turtle.onkeypress(right,RIGHT_ARROW)
turtle.listen()
turtle.penup()
def random_pos():
min_x=-int(250/SQUARE_SIZE)+1
max_x=int(250/SQUARE_SIZE)-1
min_y=-int(350/SQUARE_SIZE)-1
max_y=int(-250/SQUARE_SIZE)+1
trash_x = random.randint(min_x,max_x)*SQUARE_SIZE
trash_y = random.randint(min_y,max_y)*SQUARE_SIZE-10
return trash_x,trash_y
#make trash
def make_trash():
turtle.register_shape('e.gif')
turtle.register_shape('trash.gif')
turtle.register_shape('pe.gif')
trashes.append(turtle.clone())
trashes[-1].goto(random_pos())
trashes[-1].shape("pe.gif")
trashes[-1].showturtle()
global trash_length
trash_length +=1
trashes.append(turtle.clone())
#turtle.register_shape('papers.gif')
trashes[-1].shape("trash.gif")
trashes[-1].goto(random_pos())
trashes[-1].showturtle()
trashes.append(turtle.clone())
#turtle.register_shape('trash.gif')
trashes[-1].shape('e.gif')
trashes[-1].goto(random_pos())
trashes[-1].showturtle()
'''
def make_trash():
min_x=-int(250/SQUARE_SIZE)+1
max_x=int(250/SQUARE_SIZE)-1
min_y=-int(350/SQUARE_SIZE)-1
max_y=int(-250/SQUARE_SIZE)+1
#Pick a position that is a random multiple of SQUARE_SIZE
trash_x = random.randint(min_x,max_x)*SQUARE_SIZE
trash_y = random.randint(min_y,max_y)*SQUARE_SIZE-10
print(trash_x,trash_y)
trashes.append(turtle.clone())
trashes[-1].goto(trash_x,trash_y)
trashes[-1].showturtle()
global trash_length
trash_length +=1
'''
##make joe move
trashes = []
trash_pos = []
trash_ind = None
def move_joe():
global lock, trash_ind
if lock:
lock = False
joe_pos = joe.pos()
x_pos = joe_pos[0]
y_pos = joe_pos[1]
print(joe.pos())
if direction==RIGHT:
joe.goto(x_pos + SQUARE_SIZE, y_pos)
print("You moved right!")
elif direction==LEFT:
joe.goto(x_pos - SQUARE_SIZE, y_pos)
print("You moved left!")
elif direction==UP:
joe.goto(x_pos,y_pos+SQUARE_SIZE)
print("you moved up!")
else:
joe.goto(x_pos,y_pos-SQUARE_SIZE)
print("you moved down!")
for trash in trashes:
if joe.pos()==trash.pos():
trash_ind = trashes.index(trash)
print('lol')
if trash_ind != None:
trashes[trash_ind].goto(x_pos,y_pos)
if joe.pos() == bin1.pos():
if trash_ind != None:
if trashes[trash_ind].shape() == "trash.gif":
print('trash')
trashes[trash_ind].ht()
trash_ind = None
score((0, -400))
if joe.pos() == bin2.pos():
if trash_ind != None:
if trashes[trash_ind].shape() == "e.gif":
print('trash')
trashes[trash_ind].ht()
trash_ind = None
score((0, -400))
if joe.pos() == bin3.pos():
if trash_ind != None:
if trashes[trash_ind].shape() == "pe.gif":
print('trash')
trashes[trash_ind].ht()
trash_ind = None
score((0, -400))
lock = True
##make the logs apper randomlly
#grab trash
#turtle.register_shape('square')
##logs
pos_list = []
stamp_list = []
turtle.shape('square')
START_LENGTH = 10 #HOW LONG ARE THE LOGS
LOG_SIZE = 30
turtle.shapesize(2)
turtle.color('brown')
turtle.penup()
logs_list = []
for i in range(50):
logs_list.append(turtle.clone())
x_min = 1000
x_max = 4000
def ran_y():
y_max = 200//60
y_min = -120//60
return random.randint(y_min, y_max)*60 - 10
for log in logs_list:
x = random.randint(x_min//30,x_max//30)*30
y = ran_y()
print(y)
log.goto(x,y)
TIME_STEP = 100
for i in range(START_LENGTH):
for log in logs_list:
log_x_pos, log_y_pos=log.pos()
my_pos=(log_x_pos-LOG_SIZE,log_y_pos)
log.goto(my_pos)
pos_list.append(my_pos)
my_stamp = log.stamp()
stamp_list.append(my_stamp)
die = 0
joe_stamp = None
def move_logs():
global die, joe_stamp
joe.st()
if joe_stamp != None:
joe.clearstamp(joe_stamp)
x, y = joe.pos()
#print("joe pos:",joe.pos(),"pos list:",pos_list)
if joe.pos() in pos_list:
joe.ht()
joe_stamp = joe.stamp()
print("on log")
joe.goto(x - LOG_SIZE, y)
if trash_ind != None:
x_pos, y_pos = joe.pos()
trashes[trash_ind].goto(x_pos+5,y_pos)
elif y > -170 and y < 210:
joe.goto(0,-250)
die += 1
if die == 3:
quit()
else:
joe.goto((x//60)*60,y)
#quit()
for log in logs_list:
log_x_pos, log_y_pos = log.pos()
log.goto(log_x_pos - LOG_SIZE, log_y_pos)
my_pos=log.pos()
pos_list.append(my_pos)
#print(stamp_list)
new_stamp = log.stamp()
stamp_list.append(new_stamp)
old_stamp = stamp_list.pop(0)
log.clearstamp(old_stamp)
pos_list.pop(0)
if log_x_pos <= -1000:
log.hideturtle()
#print("Reached")
if random.randint(1,5) == 1:
log.goto(2100, log_y_pos)
log.showturtle()
turtle.ontimer(move_logs,TIME_STEP)
'''turtle.register_shape("index.gif")
bin1 = turtle.clone()
bin1.shape("index.gif")
bin1.penup()
bin1.goto(-200,345)
turtle.register_shape("RecycleBinIPyramidlid.gif")
bin2 = turtle.clone()
bin2.shape("RecycleBinIPyramidlid.gif")
bin2.penup()
bin2.goto(10,350)
turtle.register_shape("paperbin.gif")
bin3 = turtle.clone()
bin3.shape("paperbin.gif")
bin3.penup()
bin3.goto(200,350)'''
##turtle.register_shape('adg.gif')
##joe=turtle.clone()
##joe.shape('adg.gif')
#trash amaunt
trash_length= len(trashes)
while trash_length < 3:
make_trash()
move_logs()
turtle.mainloop()