This repository has been archived on 2024-12-25. You can view files and clone it, but cannot push or open issues or pull requests.
2024-03-10 20:32:51 +03:00

46 lines
1.3 KiB
ObjectPascal

uses Graph3D;
begin
Window.Title := 'Перемещение шара - анимация на основе кадра';
View3D.Title := 'Используйте клавиши:';
View3D.SubTitle := 'W,A,S,D,Стрелки - перемещение';
var c := Sphere(0,0,0,1,Colors.SeaGreen);
c.Direction := V3D(-1,0,0);
c.Velocity := 5;
var kl,kr,ku,kd: boolean;
BeginFrameBasedAnimationTime(dt -> begin
if kr then
c.Direction := V3D(-1,c.Direction.Y,0)
else if kl then
c.Direction := V3D(1,c.Direction.Y,0)
else c.Direction := V3D(0,c.Direction.Y,0);
if ku then
c.Direction := V3D(c.Direction.X,-1,0)
else if kd then
c.Direction := V3D(c.Direction.X,1,0)
else c.Direction := V3D(c.Direction.X,0,0);
c.MoveTime(dt);
end);
OnKeyDown := k ->
begin
case k of
Key.w,Key.Up: begin ku := true; kd := false; end;
Key.s,Key.Down: begin kd := true; ku := false; end;
Key.a,Key.Left: begin kl := true; kr := false; end;
Key.d,Key.Right: begin kr := true; kl := false; end;
end;
end;
OnKeyUp := k ->
begin
case k of
Key.w,Key.Up: ku := false;
Key.s,Key.Down: kd := false;
Key.a,Key.Left: kl := false;
Key.d,Key.Right: kr := false;
end;
end;
end.