forked from jfd02/TFT-OCR-BOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vec2.py
36 lines (29 loc) · 1.19 KB
/
vec2.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
"""
Vector2 that handles point screen coordinates
Transformations related to the game position & game size happen here
"""
class Vec2:
"Vector 2 class that has methods to scale screen coordinates"
screen_x_offset: int = 0
screen_y_offset: int = 0
screen_x_scale: int = 1
screen_y_scale: int = 1
def __init__(self, x_pos, y_pos, use_screen_offset: bool = True) -> None:
self.x_pos = x_pos
self.y_pos = y_pos
self.use_screen_offset: bool = use_screen_offset
def get_coords(self) -> tuple:
"""Returns screen coordinates with transformations"""
x_pos = self.x_pos * Vec2.screen_x_scale
y_pos = self.y_pos * Vec2.screen_y_scale
if self.use_screen_offset:
return (round(x_pos + Vec2.screen_x_offset),
round(y_pos + Vec2.screen_y_offset))
return (round(x_pos), round(y_pos))
@classmethod
def setup_screen(cls, x_pos: int, y_pos: int, width: int, height: int) -> None:
"""Setup for screen coordinate offset and scale"""
Vec2.screen_x_offset = x_pos
Vec2.screen_y_offset = y_pos
Vec2.screen_x_scale = width / 1920
Vec2.screen_y_scale = height / 1080