-
Notifications
You must be signed in to change notification settings - Fork 0
/
hitbox.py
48 lines (36 loc) · 1.11 KB
/
hitbox.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
from maps import *
from map import Map
from towers import *
from tower import Tower
import pyscreeze
import os
from functools import cache
from PIL import Image
import numpy as np
class Hitbox:
def __init__(self, tower: Tower):
self.tower = tower
self.size = tower.size
self.width = tower.width
self.height = tower.height
self.file_path = os.path.join('.', 'towers', 'hitboxes', f'{self.size}')
self.img = Image.open(self.file_path + '.png')
@cache
def data(self):
return np.array(self.img)
def save(self):
np.save(self.file_path + '.npy', self.data())
if __name__ == '__main__':
for size in SIZES:
try:
hitbox = Hitbox(size[0])
new_img = hitbox.img.convert('1')
hitbox.img = new_img
new_data = []
for val in hitbox.img.getdata():
new_data.append(not val)
hitbox.img.putdata(new_data)
hitbox.img.save(hitbox.file_path + '_test.png')
np.save(hitbox.file_path, hitbox.data())
except FileNotFoundError:
pass