-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHitboxTracker.py
47 lines (33 loc) · 1.19 KB
/
HitboxTracker.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
# During analysis, keep track of the display "hitbox" of every component in the screen
# for purposes of mouse clicking. This allows the program to know a) whether the mouse
# is clicking on anything, and b) which component is on top
#
# Methods to be called by Analysis.py and AnalysisBoard.py
import config
rects = []
ids = []
# To be called on every frame to reset rects
def reset():
rects.clear()
ids.clear()
# Blit surface to screen and store bounds for future collision-checking
def blit(ID, surface, pos):
rect = surface.get_rect().copy()
rect.x += pos[0]
rect.y += pos[1]
rects.append(rect)
ids.append(ID)
config.screen.blit(surface, pos)
# Get the ID of the surface that appears in front at location (x,y)
def at(x,y):
# Go backwards through the list, as the last element is appears in front (was the last to be blit)
for i in range(len(rects)-1,-1,-1):
if rects[i].collidepoint(x,y):
return ids[i]
return None
# Returns true if there are no rects containing (x,y)
def none(x,y):
return at(x,y) == None
def log():
for i in range(len(rects)):
print(ids[i], rects[i].topleft, rects[i].bottomright)