-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollisionManager.py
77 lines (65 loc) · 2.12 KB
/
CollisionManager.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
'''
Created on Feb 6, 2015
@author: SIU853541579
'''
import pygame
import random
from Constants import *
class CollisionManager:
def check_hit_direction(self, one, two):
result = [0,0]
dTop = abs(one.y - (two.y + two.height))
dBot = abs((one.y+one.height) - two.y)
dRight = abs((one.x + one.width) - two.x)
dLeft = abs(one.x - (two.x+two.width))
if((dTop <= dRight) and (dTop <= dLeft) and (dTop < dBot)):
# Top
if(dTop == dRight): # Right Corner
result[0] = 1
elif(dTop == dLeft): # Left Corner
result[0] = -1
result[1] = -1
elif((dBot <= dRight) and (dBot <= dLeft)):
# Bottom
if(dBot == dRight): # Right Corner
result[0] = 1
elif(dBot == dLeft): # Left Corner
result[0] = -1
result[1] = 1
elif(dRight < dLeft):
# Right
result[0] = 1
else:
# Left
result[0] = -1
return result
def handleBoxHit(self, one, two, hit):
"""
1,1 0,1 -1,1
1,0 -1,0
1,-1 0,-1 -1,-1
"""
if(one.facing != 'LSTOP' or one.facing != 'RSTOP'):
# Right Edge
if(hit[0] == -1):
one.x = two.x + two.width
one.x += 1
# Left Edge
elif(hit[0] == 1):
one.x = two.x - one.width
one.x -= 1
# Bottom Edge
if(hit[1] == -1):
one.y = two.y + two.height
one.y += 5
# Top Edge
elif(hit[1] == 1):
one.y = two.y - one.height
def check_collision(self, one, two):
if(one.x <= (two.x+two.width)) and (two.x <= (one.x+one.width)):
if(one.y <= (two.y+two.height)) and (two.y <= (one.y+one.height)):
return True
else:
return False
else:
return False