-
Notifications
You must be signed in to change notification settings - Fork 0
/
player_widget.py
29 lines (24 loc) · 964 Bytes
/
player_widget.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
from kivy.uix.label import Label
from kivy.uix.behaviors import DragBehavior
import cfg
import numpy as np
player_width, player_height = 40, 40
class PlayerWidget(DragBehavior, Label):
def __init__(self, player, field, *args, **kwargs):
self.field, self.player_state_ = field, player
self.label = player.label
self.angle_mode = False
pos = self.pos2pix(player.pos)
super().__init__(text=self.label, pos=pos, *args, **kwargs)
self.width, self.height = player_width, player_width
@property
def player_state(self):
return self.field.state.get_player(self.player_state_)
def pix2pos(self):
offset = player_width / 2
pos = self.field.pix2pos(self.x, self.y, offset)
return pos
def pos2pix(self, pos):
y, x = cfg.field_width_m - pos[0], pos[1]
pos = (np.array([x, y]) * self.field.scale - (player_width / 2)).astype(int).tolist()
return pos