unit umainengine;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
AdDraws, AdClasses, AdTypes, ExtCtrls, AdPerformanceCounter,AdSprites,
ComCtrls, AdEvents;
type
{ TKarte }
TFigur =
class(TImageSprite)
public
constructor Create(AParent:TSprite);
override;
end;
{ TForm1 }
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ private declarations }
public
{ public declarations }
AdDraw:TAdDraw;
AdImageList: TAdImageList;
AdPerCounter:TAdPerformanceCounter;
AdSpriteEngine:TSpriteEngine;
Selected:TSprite;
Figur: TFigur;
dx,dy:integer;
procedure Idle(Sender: TObject;
var Done: boolean);
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
AdPerCounter := TAdPerformanceCounter.Create;
AdDraw := TAdDraw.Create(Self);
AdDraw.DllName := '
AndorraOGLLaz.dll';
//AdDraw.Window.Events.OnMouseDown:=@FormMouseDown;
Application.OnIdle := @Idle;
AdDraw.Initialize;
AdImageList := TAdImageList.Create(AdDraw);
AdImageList.LoadFromFile('
karten.ail');
AdSpriteEngine := TSpriteEngine.Create(AdDraw);
//AdSpriteEngine.Surface := AdDraw;
Figur := TFigur.Create(AdSpriteEngine);
with Figur
do
begin
//Dem ImageSprite ein Bild zuweisen
Image := AdImageList.Find('
caro_2');
//Die Animation aktiv schalten
AnimActive := true;
//Die Animation soll sich ständig wiederholen
AnimLoop := true;
//Die Animation soll mit 15 FPS abgespielt werden
AnimSpeed := 15;
PixelCheck:=true;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
AdImageList.Free;
AdSpriteEngine.Free;
AdPerCounter.Free;
//AdDraw.Free;
end;
//Mouse events for moving the elements
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Selected := AdSpriteEngine.GetSpriteAt(X,Y);
if (Selected <>
nil)
then
begin
dx := round(Selected.WorldX - X);
dy := round(Selected.WorldY - Y);
//TPhysicalSprite(Selected).ActivateNeighbours;
//TPhysicalSprite(Selected).Active := false;
end
else
begin
Selected :=
nil;
end;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Selected <>
nil then
begin
Selected.X := X + dx;
Selected.Y := Y + dy;
end;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Selected <>
nil then
begin
//TPhysicalSprite(Selected).Active := true;
end;
Selected :=
nil;
end;
procedure TForm1.Idle(Sender: TObject;
var Done:boolean);
begin
AdDraw.ClearSurface(clBlack);
AdDraw.BeginScene;
with AdDraw.Canvas
do
begin
AdPerCounter.Calculate;
Caption := '
FPS:'+inttostr(AdPerCounter.FPS);
Font := AdDraw.Fonts.GenerateFont('
Arial', 24, []);
TextOut(0,0,'
Andorra 2D...');
Font := AdDraw.Fonts.GenerateFont('
Arial', 10, []);
TextOut(0,30,'
...works with Lazarus too');
//AdImageList.Find('caro_2').Draw(AdDraw,50,50,0);
end;
AdSpriteEngine.Move(AdPerCounter.TimeGap / 1000);
AdSpriteEngine.Draw;
//Alle als mit "Dead" als "tot" makierten Sprites löschen
AdSpriteEngine.Dead;
AdDraw.EndScene;
AdDraw.Flip;
Done := False;
end;
{ TFigur }
constructor TFigur.Create(AParent: TSprite);
begin
inherited;
//Am Punkt (0;0) starten.
X := 0;
Y := 0;
//XSpeed auf -150 setzten
XSpeed := -150;
end;
initialization
{$I umainengine.lrs}
end.