-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathplayer_command_body.py
116 lines (77 loc) · 2.81 KB
/
player_command_body.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from lib.player_command.player_command import PlayerCommand, CommandType
class PlayerBodyCommand(PlayerCommand):
body_commands = []
def type(self) -> CommandType:
pass
def str(self):
pass
# def name(self):
# pass
class PlayerMoveCommand(PlayerBodyCommand):
def __init__(self, x, y):
self._x = x
self._y = y
def str(self):
return f"(move {self._x} {self._y})"
def __repr__(self):
return "(Move To {}, {})".format(self._x, self._y)
def type(self):
return CommandType.MOVE
class PlayerDashCommand(PlayerBodyCommand):
def __init__(self, power, direction):
self._power = power
self._dir = direction
def str(self):
return f"(dash {self._power:.2f}" + (f" {self._dir:.2f})" if self._dir != 0 else ")")
def __repr__(self):
return "(Dash power:{}, dir:{})".format(self._power, self._dir)
def type(self):
return CommandType.DASH
class PlayerTurnCommand(PlayerBodyCommand):
def __init__(self, moment: float):
self._moment = moment
def str(self):
return f"(turn {self._moment:.2f})"
def __repr__(self):
return "(Turn moment:{})".format(self._moment)
def type(self):
return CommandType.TURN
class PlayerKickCommand(PlayerBodyCommand):
def __init__(self, power, rel_dir):
self._power = power
self._dir = rel_dir # relative to body angle
def str(self):
return f"(kick {self._power:.2f} {self._dir:.2f})"
def __repr__(self):
return "(Kick power:{}, dir:{})".format(self._power, self._dir)
def type(self):
return CommandType.KICK
def kick_power(self):
return self._power
def kick_dir(self):
return self._dir
class PlayerCatchCommand(PlayerBodyCommand):
def __init__(self, direction):
self._dir = direction
def str(self):
return f"(catch {self._dir})"
def __repr__(self):
return "(Catch dir:{})".format(self._dir)
def type(self):
return CommandType.CATCH
class PlayerTackleCommand(PlayerBodyCommand): # TODO Foul ...
def __init__(self, power_or_dir, foul: bool = False):
self._power_or_dir = power_or_dir
self._foul = foul
def str(self):
return f"(tackle {self._power_or_dir}" + (f" on)" if self._foul else ")")
def __repr__(self):
return "(Tackle power{}, foul{})".format(self._power_or_dir, self._foul)
def type(self):
return CommandType.TACKLE
PlayerBodyCommand.body_commands = [PlayerMoveCommand,
PlayerDashCommand,
PlayerTurnCommand,
PlayerKickCommand,
PlayerCatchCommand,
PlayerTackleCommand]