const
Speed = 3;
AnimSpeed = 175;
Pfad = '
.\Debug\Win32\Graphic';
procedure TForm1.FormCreate(Sender: TObject);
begin
TMoveR := TTimer.Create(self);
TMoveR.Interval := AnimSpeed;
TMoveR.OnTimer := TMoveREvent;
TMoveR.Enabled := false;
TMoveL := TTimer.Create(self);
TMoveL.Interval := AnimSpeed;
TMoveL.OnTimer := TMoveLEvent;
TMoveL.Enabled := false;
TMoveJ := TTimer.Create(self);
TMoveJ.Interval := AnimSpeed;
TMoveJ.OnTimer := TMoveJEvent;
TMoveJ.Enabled := false;
TMoveD := TTimer.Create(self);
TMoveD.Interval := AnimSpeed;
TMoveD.OnTimer := TMoveDEvent;
TMoveD.Enabled := false;
end;
procedure TForm1.TMoveREvent(Sender: TObject);
begin
Case MoveR
of
0: Player1.Picture.LoadFromFile(Pfad+'
move1R.png');
1: Player1.Picture.LoadFromFile(Pfad+'
move2R.png');
2: Player1.Picture.LoadFromFile(Pfad+'
move3R.png');
3: Player1.Picture.LoadFromFile(Pfad+'
move2R.png');
end;
MoveR := MoveR+1;
if MoveR > 3
then MoveR := 0;
TMoveR.Enabled := False;
end;
procedure TForm1.TMoveLEvent(Sender: TObject);
begin
Case MoveL
of
0: Player1.Picture.LoadFromFile(Pfad+'
move1L.png');
1: Player1.Picture.LoadFromFile(Pfad+'
move2L.png');
2: Player1.Picture.LoadFromFile(Pfad+'
move3L.png');
3: Player1.Picture.LoadFromFile(Pfad+'
move2L.png');
end;
MoveL := MoveL+1;
if MoveL > 3
then MoveL := 0;
TMoveL.Enabled := False;
end;
procedure TForm1.TMoveJEvent(Sender: TObject);
begin
Player1.Picture.LoadFromFile(Pfad+'
jump.png');
TMoveJ.Enabled := False;
end;
procedure TForm1.TMoveDEvent(Sender: TObject);
begin
if Direction = 0
then Player1.Picture.LoadFromFile(Pfad+'
duckR.png')
Else Player1.Picture.LoadFromFile(Pfad+'
duckL.png');
TMoveD.Enabled := False;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
SpeedX, SpeedY: Integer;
begin
Caption := TimeToStr(Time);
SpeedX := 0;
SpeedY := 0;
if GetAsyncKeyState(VkKeyScan('
d')) <> 0
then
begin
TMoveR.Enabled := True;
Inc(SpeedX, Speed);
Direction := 0;
end;
if GetAsyncKeyState(VkKeyScan('
a')) <> 0
then
begin
TMoveL.Enabled := True;
Dec(SpeedX, Speed);
Direction := 1;
end;
if GetAsyncKeyState(VkKeyScan('
s')) <> 0
then
begin
TMoveD.Enabled := true;
//Inc(SpeedY, Speed);
end;
if GetAsyncKeyState(VkKeyScan('
w')) <> 0
then
begin
TMoveJ.Enabled := true;
Dec(SpeedY, Speed);
end;
Player1.Left := Player1.Left + SpeedX;
Player1.Top := Player1.Top + SpeedY;
If (GetAsyncKeyState(VkKeyScan('
w')) = 0)
AND (GetAsyncKeyState(VkKeyScan('
a')) = 0)
AND (GetAsyncKeyState(VkKeyScan('
s')) = 0)
AND (GetAsyncKeyState(VkKeyScan('
d')) = 0)
then
begin
If Direction = 0
then Player1.Picture.LoadFromFile(Pfad+'
standR.png')
Else Player1.Picture.LoadFromFile(Pfad+'
standL.png');
end;
end;
end.