-
Notifications
You must be signed in to change notification settings - Fork 0
/
conveyor.py
121 lines (94 loc) · 5.62 KB
/
conveyor.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
from tkinter import *
import random
from tokenize import Number
from unit import *
from stopper import *
import switch
class conveyor(object):
def __init__(self,canvas,number,xStartPos,yStartPos,thickness,xVelocity,yVelocity,totalPouches,color,switches,stopper):
self.number = number
self.units = []
self.xStartPos = xStartPos
self.yStartPos = yStartPos
self.thickness = thickness
self.xVelocity = xVelocity
self.yVelocity = yVelocity
self.totalPouches = totalPouches
self.color = color # Needs to be a list
self.switches = switches
self.stopper = stopper
for i in range(totalPouches):
self.units.append(unit(i,canvas,self,thickness,color))
def check_collision_right(self,pouch_number):
if pouch_number > 0:
# After moving, check if collision with: next unit in the list, stopper or switch
if (self.stopper!= 0):
if (self.units[pouch_number-1].coordinates[0] - self.units[pouch_number].coordinates[2]<30 or self.stopper.coordinates[0] - self.units[pouch_number].coordinates[2]<30):
self.units[pouch_number].xVelocity = 0
self.units[pouch_number].yVelocity = 0
else:
self.units[pouch_number].xVelocity = self.xVelocity
self.units[pouch_number].yVelocity = self.yVelocity
else:
if (self.units[pouch_number-1].coordinates[0] - self.units[pouch_number].coordinates[2]<30):
self.units[pouch_number].xVelocity = 0
self.units[pouch_number].yVelocity = 0
else:
self.units[pouch_number].xVelocity = self.xVelocity
self.units[pouch_number].yVelocity = self.yVelocity
def check_collision_left(self,pouch_number):
if pouch_number > 0:
# After moving, check if collision with pouch in front
if (self.stopper!= 0):
if (abs(self.units[pouch_number-1].coordinates[2] - self.units[pouch_number].coordinates[0])<30 or abs(self.stopper.coordinates[2] - self.units[pouch_number].coordinates[0])<30):
self.units[pouch_number].xVelocity = 0
self.units[pouch_number].yVelocity = 0
else:
self.units[pouch_number].xVelocity = self.xVelocity
self.units[pouch_number].yVelocity = self.yVelocity
else:
if (abs(self.units[pouch_number-1].coordinates[2] - self.units[pouch_number].coordinates[0])<30):
self.units[pouch_number].xVelocity = 0
self.units[pouch_number].yVelocity = 0
else:
self.units[pouch_number].xVelocity = self.xVelocity
self.units[pouch_number].yVelocity = self.yVelocity
def check_collision_up(self,pouch_number):
if pouch_number > 0:
# After moving, check if collision with pouch in front
if (self.stopper!= 0):
if (abs(self.units[pouch_number-1].coordinates[3] - self.units[pouch_number].coordinates[1])<30 or abs(self.stopper.coordinates[3] - self.units[pouch_number].coordinates[1])<30):
self.units[pouch_number].xVelocity = 0
self.units[pouch_number].yVelocity = 0
else:
self.units[pouch_number].xVelocity = self.xVelocity
self.units[pouch_number].yVelocity = self.yVelocity
else:
if (abs(self.units[pouch_number-1].coordinates[3] - self.units[pouch_number].coordinates[1])<30):
self.units[pouch_number].xVelocity = 0
self.units[pouch_number].yVelocity = 0
else:
self.units[pouch_number].xVelocity = self.xVelocity
self.units[pouch_number].yVelocity = self.yVelocity
def check_collision_down(self,pouch_number):
if pouch_number > 0:
# After moving, check if collision with pouch in front
if (self.stopper!= 0):
if (abs(self.units[pouch_number-1].coordinates[1] - self.units[pouch_number].coordinates[3])<30 or abs(self.stopper.coordinates[1] - self.units[pouch_number].coordinates[3])<30):
self.units[pouch_number].xVelocity = 0
self.units[pouch_number].yVelocity = 0
else:
self.units[pouch_number].xVelocity = self.xVelocity
self.units[pouch_number].yVelocity = self.yVelocity
else:
if (abs(self.units[pouch_number-1].coordinates[1] - self.units[pouch_number].coordinates[3])<30):
self.units[pouch_number].xVelocity = 0
self.units[pouch_number].yVelocity = 0
else:
self.units[pouch_number].xVelocity = self.xVelocity
self.units[pouch_number].yVelocity = self.yVelocity
def check_unit_at_switch(self,pouch_number):
divert_switch = self.units[pouch_number].destination_switch
if abs(self.units[pouch_number].coordinates[2] - self.switches[divert_switch].coordinates[2])<30:
self.units[pouch_number].needs_to_switch = TRUE
print('Unit needs to switch')