-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarpet.py
72 lines (61 loc) · 2.35 KB
/
carpet.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import json
from math import sqrt
from typing import List
class Action(object):
def __init__(self, id: str):
self.acceleration = [0, 0]
self.activateShield = False
self.attack = [0, 0]
self.id = id
class Target(object):
def __init__(self, carp_x, carp_y):
self.coordinates = [carp_x, carp_y] #координаты ковра (нашего)
self.health = 0
self.shieldLeftMs = 0
self.velocity = [0, 0]
class Carpet(object):
targets: List[Target] = []
def __init__(self, id: str):
self.coords = [0, 0]
self.id = id
self.action = Action(id)
self.shoot_cd = 0
self.acceleration = [0, 0]
def shoot(self, enemy_x: int, enemy_y: int, velocity_x: int, velocity_y: int):
if self.shoot_cd == 0:
self.action.attack = [enemy_x + (velocity_x * 0.3), enemy_y + (velocity_y * 0.3)]
else:
pass
def action_to_dict(self):
result = {
"acceleration":
{
"x": self.action.acceleration[0],
"y": self.action.acceleration[1]
},
"activateShield": self.action.activateShield,
"attack":
{
"x": self.action.attack[0],
"y": self.action.attack[1]
},
"id": self.id
}
return json.dumps(result)
def scan(self):
# Главная логика здесь
pass
def move(self, x: int, y: int):
now = self.coords
want = [x, y]
movement_vector = [want[0] - now[0], want[1] - now[1]] #вектор передвижения
movement_len = sqrt(movement_vector[0] ** 2 + movement_vector[1] ** 2)
if movement_len <= 10: #если нам пора замедляться то отрицательное ускорение
self.acceleration = -1 * movement_len
return
elif movement_len == 0: #если мы на месте то ускорение 0
self.acceleration = 0
return
k = 10 / movement_len #кэф масштабирования ускорения
acc_vector = [movement_vector[0] * k, movement_vector[1] * k] #вектор который пройдем за тик/секунду
self.acceleration = acc_vector