unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,AdSprites, AdSetupDlg, AdPerformanceCounter, AdDraws, AdClasses, AdTypes, AdComponents,
ExtCtrls;
type
TFigur =
class(TImageSprite)
private
protected
procedure DoMove(TimeGap:double);
override;
public
XSpeed:integer;
constructor Create(AParent:TSprite);
override;
procedure SetLine;
end;
type
TForm1 =
class(TForm)
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;
const
path = '
./resources/';
implementation
{$R *.dfm}
constructor TFigur.Create(AParent:TSprite);
begin
inherited;
X := 0;
Y := 0;
XSpeed := -150;
end;
procedure TFigur.SetLine;
begin
XSpeed := -XSpeed;
if XSpeed > 0
then
begin
AnimStart := 0;
AnimStop := 7;
X := -96;
end
else
begin
AnimStart := 8;
AnimStop := 15;
X := Engine.SurfaceRect.Right+96;
end;
Y := Random(round(Engine.SurfaceRect.Right-96));
end;
procedure TFigur.DoMove(timegap:double);
begin
inherited;
X := X + XSpeed*TimeGap;
if ((X > Engine.SurfaceRect.Right)
and (XSpeed > 0))
or
((X < -96)
and (XSpeed < 0))
then
begin
SetLine;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
AdSetupDlg:TAdSetup;
begin
adpercounter:=TAdperformancecounter.create;
AdDraw:=TAdDraw.Create(self);
// HIER TRITT DER FEHLER AUF
AdSetupDlg := TAdSetup.Create(AdDraw);
AdSetupDlg.Image := '
boy.bmp';
if AdSetupDlg.Execute
then
begin
if addraw.Initialize
then
begin
application.OnIdle:=idle;
adimagelist1.Create(addraw);
with adimagelist1.Add('
figur')
do
begin
texture.LoadGraphicFromFile(path+'
boy.bmp',true,clFuchsia);
patternwidth:=96;
patternheight:=96;
end;
adimagelist1.Restore;
adspriteengine:=Tspriteengine.Create(
nil);
adspriteengine.Surface:=addraw;
randomize;
for i := 0
to 5
do
begin
with TFigur.Create(adspriteengine)
do
begin
image:=adimagelist1.find('
figur');
animactive:=true;
animloop:=true;
xspeed:=-(random(100)+50);
AnimSpeed := Abs(XSpeed / 7.5);
SetLine;
end;
end;
end
else
begin
showmessage(addraw.GetLastError);
halt;
end;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
AdSpriteEngine.Free;
AdImageList1.Free;
AdPerCounter.Free;
AdDraw.Free
end;
procedure TForm1.Idle(Sender:TObject;
var Done:boolean);
begin
if addraw.CanDraw
then
begin
adpercounter.Calculate;
addraw.ClearSurface(clblack);
addraw.BeginScene;
adspriteengine.Move(adpercounter.TimeGap/1000);
adspriteengine.draw;
adspriteengine.Dead;
addraw.EndScene;
addraw.flip;
done:=false;
end;
end;