unit Main;
interface
uses
Windows, Dialogs, SysUtils, Graphics, Classes, Forms, AdDraws, AdClasses,
Controls, ExtCtrls, AdSprites, AdSetupDlg, AdPNG, AdPerformanceCounter;
type
TFigur =
class(TImageSprite)
private
protected
procedure DoMove(TimeGap:double);
override;
public
XSpeed:integer;
constructor Create(AParent:TSprite);
override;
procedure SetLine;
end;
TForm1 =
class(TForm)
procedure FormKeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
procedure FormKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
public
AdDraw:TAdDraw;
AdPerCounter:TAdPerformanceCounter;
AdImageList1:TAdImageList;
AdSpriteEngine:TSpriteEngine;
procedure Idle(Sender:TObject;
var Done:boolean);
{ Public-Deklarationen }
end;
var
Form1: TForm1;
x_right:boolean=false;
x_left:boolean=false;
x_up:boolean=false;
x_down:boolean=false;
const
path = '
./resources/';
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
AdSetupDlg:TAdSetup;
begin
AdPerCounter := TAdPerformanceCounter.Create;
AdDraw := TAdDraw.Create(self);
AdSetupDlg := TAdSetup.Create(AdDraw);
AdSetupDlg.Image := path+'
logo1.png';
if AdSetupDlg.Execute
then
begin
if AdDraw.Initialize
then
begin
Application.OnIdle := Idle;
AdImageList1 := TAdImageList.Create(AdDraw);
with AdImageList1.Add('
figur')
do
begin
Texture.LoadGraphicFromFile(path+'
boy.png', true, clFuchsia);
PatternWidth := 96;
PatternHeight := 96;
end;
AdImageList1.Restore;
AdSpriteEngine := TSpriteEngine.Create(
nil);
AdSpriteEngine.Surface := AdDraw;
Randomize;
with TFigur.Create(AdSpriteEngine)
do
begin
Image := AdImageList1.Find('
figur');
AnimActive := true;
AnimLoop := true;
XSpeed := -100;
AnimSpeed := Abs(XSpeed / 7.5);
SetLine;
end;
end
else
begin
ShowMessage(AdDraw.GetLastError);
halt;
end;
end
else
begin
halt;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
AdSpriteEngine.Free;
AdImageList1.Free;
AdPerCounter.Free;
AdDraw.Free;
end;
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if key=VK_RIGHT
then
x_right:=true;
if key=VK_LEFT
then
x_left:=true;
if key=VK_UP
then
x_up:=true;
if key=VK_DOWN
then
x_down:=true;
end;
procedure TForm1.FormKeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if key=VK_RIGHT
then
x_right:=false;
if key=VK_left
then
x_left:=false;
if key=VK_UP
then
x_up:=false;
if key=VK_DOWN
then
x_down:=false;
end;
procedure TForm1.Idle(Sender: TObject;
var Done: boolean);
begin
if AdDraw.CanDraw
then
begin
AdPerCounter.Calculate;
Caption := '
FPS:'+inttostr(AdPerCounter.FPS);
AdDraw.ClearSurface(clBlack);
AdDraw.BeginScene;
AdSpriteEngine.Move(AdPerCounter.TimeGap / 1000);
AdSpriteEngine.Draw;
AdSpriteEngine.Dead;
AdDraw.EndScene;
AdDraw.Flip;
Done := false;
end;
end;
{ TFigur }
constructor TFigur.Create(AParent: TSprite);
begin
inherited;
X := 0;
Y := 0;
XSpeed := -150;
end;
procedure TFigur.DoMove(TimeGap: double);
begin
inherited;
SetLine;
if (x_right
and not (x_up
or x_down))
then
begin
x:=x+0.2;
end;
if (x_left
and not (x_up
or x_down))
then
begin
x:=x-0.2;
end;
if (x_up
and not (x_right
or x_left))
then
begin
y:=y-0.2;
end;
if (x_down
and not (x_right
or x_left))
then
begin
y:=y+0.2;
end;
end;
procedure TFigur.SetLine;
begin
if x_left
then
begin
AnimStart := 8;
AnimStop := 15;
end;
if x_right
then
begin
AnimStart := 0;
AnimStop := 7;
end;
end;
end.