-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconditions.py
More file actions
239 lines (195 loc) · 7.97 KB
/
conditions.py
File metadata and controls
239 lines (195 loc) · 7.97 KB
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
#The basic idea of a condition
class Condition(object):
def __init__(self, frameObject):
self.pastFrames = 0
self.frameObject = frameObject
self.isPlayerRule = False
def UpdatePastFrames(self):
self.pastFrames +=1
class VelocityXCondition(Condition):
def __init__(self, frameObject, velocityVal):
super(VelocityXCondition,self).__init__(frameObject)
self.spriteName = frameObject.name
self.velocityValue = velocityVal
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.spriteName==other.spriteName and self.pastFrames==other.pastFrames and self.velocityValue==other.velocityValue
else:
return False
def __ne__(self, other):
if isinstance(other, self.__class__):
return not self.__eq__(other)
else:
return True
def __hash__(self):
return hash(tuple([self.pastFrames, self.spriteName, self.velocityValue]))
def clone(self):
condition = VelocityXCondition(self.frameObject, self.velocityValue)
condition.pastFrames = self.pastFrames
condition.isPlayerRule = self.isPlayerRule
return condition
def __str__(self):
return "VelocityXCondition: "+str([self.spriteName, self.velocityValue])
class VelocityYCondition(Condition):
def __init__(self, frameObject, velocityVal):
super(VelocityYCondition,self).__init__(frameObject)
self.spriteName = frameObject.name
self.velocityValue = velocityVal
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.spriteName==other.spriteName and self.pastFrames==other.pastFrames and self.velocityValue==other.velocityValue
else:
return False
def __ne__(self, other):
if isinstance(other, self.__class__):
return not self.__eq__(other)
else:
return True
def __hash__(self):
return hash(tuple([self.pastFrames, self.spriteName, self.velocityValue]))
def clone(self):
condition = VelocityYCondition(self.frameObject, self.velocityValue)
condition.pastFrames = self.pastFrames
condition.isPlayerRule = self.isPlayerRule
return condition
def __str__(self):
return "VelocityYCondition: "+str([self.spriteName, self.velocityValue])
#Animation State and not exists
class AnimationCondition(Condition):
def __init__(self, frameObject, existsSpriteName):
super(AnimationCondition,self).__init__(frameObject)
self.spriteName = existsSpriteName
self.x = 0
self.y = 0
self.width = 0
self.height = 0
if not frameObject==None:
self.x = frameObject.x
self.y = frameObject.y
self.width = frameObject.width
self.height = frameObject.height
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.spriteName==other.spriteName and self.pastFrames==other.pastFrames and self.x==other.x and self.y==other.y
else:
return False
def __ne__(self, other):
if isinstance(other, self.__class__):
return not self.__eq__(other)
else:
return True
def __hash__(self):
return hash(tuple([self.pastFrames, self.spriteName, self.x, self.y]))
def clone(self):
condition = AnimationCondition(self.frameObject, self.spriteName)
condition.pastFrames = self.pastFrames
condition.isPlayerRule = self.isPlayerRule
return condition
def __str__(self):
return "AnimationCondition: "+str([self.spriteName, self.x, self.y, self.width, self.height])
#screen position of sprites
class SpatialCondition(Condition):
def __init__(self, frameObject, sprite1, spritePosition):
super(SpatialCondition,self).__init__(frameObject)
self.spriteName = sprite1
self.screenPosition = spritePosition
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.spriteName==other.spriteName and self.screenPosition==other.screenPosition and self.pastFrames==other.pastFrames
else:
return False
def __ne__(self, other):
if isinstance(other, self.__class__):
return not self.__eq__(other)
else:
return True
def __hash__(self):
return hash(tuple([self.pastFrames, self.spriteName, tuple(self.screenPosition)]))
def clone(self):
condition = SpatialCondition(self.frameObject, self.spriteName, self.screenPosition)
condition.pastFrames = self.pastFrames
condition.isPlayerRule = self.isPlayerRule
return condition
def __str__(self):
return "SpatialCondition: "+str([self.spriteName, self.screenPosition])
#relationships between sprites
class RelationshipConditionX(Condition):
def __init__(self, frameObject, sprite1, sprite2, connect1, connect2, relativeVectorVal):
super(RelationshipConditionX,self).__init__(frameObject)
self.spriteName = sprite1
self.sprite1Edge = connect1
self.sprite2Name = sprite2
self.sprite2Edge = connect2
self.relativeVectorVal = relativeVectorVal
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.sprite2Edge==other.sprite2Edge and self.sprite1Edge==other.sprite1Edge and self.sprite2Name==other.sprite2Name and self.spriteName==other.spriteName and self.pastFrames==other.pastFrames and self.relativeVectorVal == other.relativeVectorVal
else:
return False
def __ne__(self, other):
if isinstance(other, self.__class__):
return not self.__eq__(other)
else:
return True
def __hash__(self):
return hash(tuple([self.pastFrames, self.spriteName, self.sprite1Edge, self.sprite2Name, self.sprite2Edge, self.relativeVectorVal]))
def clone(self):
condition = RelationshipConditionX(self.frameObject, self.spriteName, self.sprite2Name, self.sprite1Edge, self.sprite2Edge, self.relativeVectorVal)
condition.pastFrames = self.pastFrames
condition.isPlayerRule = self.isPlayerRule
return condition
def __str__(self):
return "RelationshipConditionX: "+str([self.spriteName, self.sprite1Edge, self.sprite2Name, self.sprite2Edge, self.relativeVectorVal])
#relationships between sprites
class RelationshipConditionY(Condition):
def __init__(self, frameObject, sprite1, sprite2, connect1, connect2, relativeVectorVal):
super(RelationshipConditionY,self).__init__(frameObject)
self.spriteName = sprite1
self.sprite1Edge = connect1
self.sprite2Name = sprite2
self.sprite2Edge = connect2
self.relativeVectorVal = relativeVectorVal
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.sprite2Edge==other.sprite2Edge and self.sprite1Edge==other.sprite1Edge and self.sprite2Name==other.sprite2Name and self.spriteName==other.spriteName and self.pastFrames==other.pastFrames and self.relativeVectorVal == other.relativeVectorVal
else:
return False
def __ne__(self, other):
if isinstance(other, self.__class__):
return not self.__eq__(other)
else:
return True
def __hash__(self):
return hash(tuple([self.pastFrames, self.spriteName, self.sprite1Edge, self.sprite2Name, self.sprite2Edge, self.relativeVectorVal]))
def clone(self):
condition = RelationshipConditionY(self.frameObject, self.spriteName, self.sprite2Name, self.sprite1Edge, self.sprite2Edge, self.relativeVectorVal)
condition.pastFrames = self.pastFrames
condition.isPlayerRule = self.isPlayerRule
return condition
def __str__(self):
return "RelationshipConditionY: "+str([self.spriteName, self.sprite1Edge, self.sprite2Name, self.sprite2Edge, self.relativeVectorVal])
#Variable relationships
class VariableCondition(Condition):
def __init__(self, frameObject, variableName, variableValue):
super(VariableCondition,self).__init__(frameObject)
self.variableName = variableName
self.variableValue = variableValue
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.variableValue==other.variableValue and self.variableName==other.variableName and self.pastFrames==other.pastFrames
else:
return False
def __ne__(self, other):
if isinstance(other, self.__class__):
return not self.__eq__(other)
else:
return True
def __hash__(self):
return hash(tuple([self.pastFrames, self.variableName, self.variableValue]))
def clone(self):
condition = VariableCondition(self.frameObject, self.variableName, self.variableValue)
condition.pastFrames = self.pastFrames
condition.isPlayerRule = self.isPlayerRule
return condition
def __str__(self):
return "VariableCondition: "+str([self.variableName, self.variableValue])