-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.pas
139 lines (117 loc) · 3.2 KB
/
Player.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
unit Player;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, SDL2, Utility, Options;
type
rPlayerAction = record
MousePressed,
Left, Right, Forwards, Backwards, Up, Down,
PitchDown, PitchUp,
YawLeft, YawRight,
RollLeft, RollRight,
WireFrame,
DrawFrame,
Paused: Boolean;
mx, my: single;
end;
{ tPlayer }
tPlayer = class
private
Event: tSDL_Event;
public
Options: tOptions;
Name: string;
Action: rPlayerAction;
constructor Create(Opts: tOptions);
destructor Destroy; override;
procedure LoadProfile(FileName: string);
//character?
procedure ProcessInput;
end;
const
DefaultProfileName = 'DefaultProfile';
ProfileExt = '.xml';
implementation
uses
app;
{ tPlayer }
constructor tPlayer.Create(Opts: tOptions);
begin
Options:= Opts; //this could create problems; is in todo
end;
destructor tPlayer.Destroy;
begin
Options.Free;
inherited Destroy;
end;
procedure tPlayer.LoadProfile(FileName: string); { TODO 1 -cimprovement : change into a func }
begin
if FileExists(FileName) then
begin
//Options.Free; { TODO : Possible overlap from different profiles: needs reset }
//Options:= tOptions.Create;
WriteLog('Loading player profile ' + FileName);
Options.Load(FileName); //Secondary, overriding primary
end
else
begin { TODO : warn about missing profile }
WriteLog('Player profile is missing');
Options.WriteDefault(FileName);
end;
end;
procedure tPlayer.ProcessInput;
begin
with Action do
begin
mx:= 0;
my:= 0;
while SDL_PollEvent(@Event) = 1 do
with Event do
begin
case type_ of
SDL_MOUSEBUTTONDOWN: MousePressed:= true; // Mouse button pressed
SDL_MOUSEBUTTONUP: MousePressed:= false;
SDL_MouseMotion:
begin
mx:= motion.xrel;
my:= motion.yrel;
end;
SDL_KeyDown:
case Options.cs[eScanCode(key.keysym.scancode)] of
aLeft: Left:= true;
aRight: Right:= true;
aForward: Forwards:= true;
aBackward: Backwards:= true;
aUpward: Up:= true;
aDownward: Down:= true;
aPitchDown: PitchDown:= true;
aPitchUp: PitchUp:= true;
aYawLeft: YawLeft:= true;
aYawRight: YawRight:= true;
aRollLeft: RollLeft:= true;
aRollRight: RollRight:= true;
aEsc: Paused:= true;
end;
SDL_KeyUp:
case Options.cs[eScanCode(key.keysym.scancode)] of
aLeft: Left:= false;
aRight: Right:= false;
aForward: Forwards:= false;
aBackward: Backwards:= false;
aUpward: Up:= false;
aDownward: Down:= false;
aPitchDown: PitchDown:= false;
aPitchUp: PitchUp:= false;
aYawLeft: YawLeft:= false;
aYawRight: YawRight:= false;
aRollLeft: RollLeft:= false;
aRollRight: RollRight:= false;
end;
SDL_QuitEv: GameApp.State:= sShutDown;
else WriteLog(strf(Event.key.keysym.scancode));
end;
end;
end;
end;
end.