-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_tank.pas
111 lines (89 loc) · 1.83 KB
/
user_tank.pas
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
unit user_tank;
interface
uses
Graphics,
strategy_utils,
tanks,
world,
globals,
bonus,
weapon,
geom,
Math,
SysUtils;
const MAX_TIMER=44;
type TMovingDir=(None, Fwd, Back);
type
TUserTank=class(TTank)
public
target:TTank;
movingToPoint:boolean;
timer:integer;
user_alfa:double;
firing:boolean;
moving:TMovingDir;
procedure get_actions;override;
procedure Init; override;
function getTankColor:TColor;override;
procedure setDirection(x:double; y:double);
end;
implementation
uses Classes;
{ TMyTank }
procedure TUserTank.Init;
begin
target:=nil;
moving:=None;
firing:=false;
movingToPoint:=false;
user_alfa:=getCurrentNewAlfa;
setMaxFireDelay(MAX_FIRE_DELAY_CHEAT);
setHP(100);
timer:=0;
end;
procedure TUserTank.get_actions;
var
a:double;
begin
if assigned(target) then
if movingToPoint then
begin
if distanceTo(target)<3 then movingToPoint:=false;
moving:=None;
user_alfa:=getAlfa;
end;
if movingToPoint then
begin
turnTo(target);
a:=getAngleToObject(target.getX,target.getY)-getAlfa;
if (abs(normalize_angle_rot(a))<Pi/4) then
moving:=Fwd
else
moving:=None;
end;
if moving=None then use_breaks;
if moving=Fwd then
setAcceleration(MAX_ACCELERATION);
if moving=Back then
setAcceleration(MIN_ACCELERATION);
if not movingToPoint then
begin
rotate(user_alfa);
end;
if firing then
begin
fire;
firing:=false;
end;
end;
function TUserTank.getTankColor: TColor;
begin
Result:=$10fe22
end;
procedure TUserTank.setDirection(x, y: double);
begin
movingToPoint:=true;
if Assigned(target) then target.Free;
target:=Ttank.Create(X,Y,3,'Stupid 4');
end;
end.