procedure TgEvo.BtStartClick(Sender: TObject);
begin
Label1.Visible:=False;
Label2.Visible:=False;
Label3.Visible:=False;
Label4.Visible:=False;
Trackbar1.Visible:=False;
Trackbar2.Visible:=False;
Trackbar3.Visible:=False;
Trackbar4.Visible:=False;
BtStart.Visible:=false;
BorderStyle:= bsNone;
///FormStyle:= fsStayOnTop;
BoundsRect:= Monitor.BoundsRect;
PaintBox.Width:= gEvo.Width;
PaintBox.Height:= gEvo.Height;
BMP.Width:= PaintBox.Width;
BMP.Height:= PaintBox.Height;
Erzeuge_und_Zeichne;
Application.OnIdle:=IdleHandler;
end;
procedure TgEvo.FormCreate(Sender: TObject);
begin
OrganismusID:=0;
ProduzentID:=0;
BMP:= TBitMap.Create;
end;
procedure TgEvo.Paint;
Var i: integer;
begin
Brush:= CreateSolidBrush(clWhite);
SelectObject(BMP.Canvas.Handle, Brush);
Pen:= CreatePen(PS_SOLID,10,clPurple);
SelectObject(BMP.Canvas.Handle, Pen);
Rectangle(BMP.Canvas.Handle,0,0,gEvo.Width,gEvo.Height);
MoveToEx(BMP.Canvas.Handle,2,2,NIL);
LineTo(BMP.Canvas.Handle,gEvo.Width-2,2);
LineTo(BMP.Canvas.Handle,gEvo.Width-2,gEvo.Height-2);
LineTo(BMP.Canvas.Handle,2,gEvo.Height-2);
LineTO(BMP.Canvas.Handle,2,2);
for i := 1 to ProduzentID do
begin
Produzent[i].Koerper;
end;
for i := 1 to OrganismusID do
begin
Organismus[i].Bewegung;
end;
for i := 1 to ProduzentID do
begin
Produzent[i].Kollision;
end;
SetBkMode(BMP.Canvas.Handle, TRANSPARENT);
TextOut(BMP.Canvas.Handle,7,7,PWChar(IntToStr(Frames)+' FpS; '+IntToStr(Sekunden)+' Sek'),10+Length(IntToStr(Frames))+Length(IntToStr(Sekunden)));
BitBlt(PaintBox.Canvas.Handle, 0, 0, BMP.Width, BMP.Height, BMP.Canvas.Handle,
0, 0, SrcCopy);
end;
procedure TgEvo.Erzeuge_und_Zeichne;
Var RanStartX, RanStartY, Ran2StartX, Ran2StartY,
RanGroesse, RanLeben, i: Integer;
begin
for I := 1 to 6 do
begin
OrganismusID:=OrganismusID + 1;
Randomize;
RanStartX:=Random(gEvo.Width-200)+100;
RanStartY:=Random(gEvo.Height-200)+100;
Organismus[OrganismusID]:= TOrganismus.Create(RanStartX,RanStartY,50,1000,Random(360),55,250,6);
end;
for I := 1 to 6 do
begin
ProduzentID:=ProduzentID + 1;
Ran2StartX:=Random(gEvo.Width-200)+100;
Ran2StartY:=Random(gEvo.Height-200)+100;
RanGroesse:=Random(70)+30;
RanLeben:=RanGroesse*20;
Produzent[ProduzentID]:= TProduzent.Create(Ran2StartX,Ran2StartY,RanGroesse,RanLeben);
end;
end;
procedure TgEvo.IdleHandler(Sender: TObject; var Done: Boolean);
begin
StartTime:= GetTickCount;
Paint;
DrawTime:= GetTickCount - StartTime;
Inc(TimeCount, DrawTime);
Inc(FrameCount);
if TimeCount >= 1000 then begin
Frames:= FrameCount;
Inc(Sekunden);
TimeCount:= TimeCount - 1000;
FrameCount:= 0;
end;
Done:= false;
end;