-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
50 lines (46 loc) · 1.62 KB
/
worker.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
from ursina import *
class Worker(Entity):
currently_dragged_entity = None
def __init__(self, position=(0,0,0), cost=int, power=int):
super().__init__(
parent=scene,
model="Assets/worker.gltf",
scale=3,
origin=(0,0,0),
position=position,
collider='box',
plane_direction=(0, 1, 0)
)
self.cost = cost
self.power = power
self.dragging = False
self.tips = Tooltip(f"Cost: {self.cost}\nPower: {self.power}")
self.tips.background.color = color.hsv(0,0,0,.8)
def input(self, key):
if held_keys['shift'] and self.hovered and Worker.currently_dragged_entity is None:
if mouse.left:
Worker.currently_dragged_entity = self
self.dragging = True
elif key == 'left mouse up':
if self.dragging:
self.dragging = False
Worker.currently_dragged_entity = None
elif key == 'r' and self.hovered:
self.rotation_y += 90
elif key == 't' and self.hovered:
self.rotation_y -= 90
elif key == 'backspace' and self.hovered:
destroy(self)
self.tips.enabled = False
def update(self):
if self.dragging:
try:
self.position = Vec3(mouse.world_point.x, self.position.y, mouse.world_point.z)
except:
print("Not selected")
else:
self.dragging = False
if self.hovered:
self.tips.enabled = True
else:
self.tips.enabled = False