Simple!

Open a new Delphi app and paste this code on the form's unit
This should make a green dot that follows the mouse (prey) and a yellow
dot(predator) trying to catch the green dot.

Reminds me of my game making days!

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, ExtCtrls, AppEvnts;

type
  TForm1 = class(TForm)
    procedure PaintBox1Paint(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
    x,y,v,h,xx,yy,vv,hh : real;
    smoother : integer;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
  with (Sender as TPaintBox).Canvas do
  begin
    Pen.Color:=clYellow;
    Brush.COlor:=clYellow;
    Rectangle(trunc(x),trunc(y),trunc(x)+10,trunc(y)+10);

    Pen.Color:=clLime;
    Brush.Color:=clLime;
    Rectangle(trunc(h),trunc(v),trunc(h)+10,trunc(v)+10);

  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with TPaintBox.Create(Self) do
  begin
    Parent:=Self;
    Align:=alClient;
    OnPaint:=PaintBox1Paint;
    OnMouseMove:=PaintBox1MouseMove;
  end;

  with TTimer.Create(Self) do
  begin
    OnTimer:=Timer1Timer;
    Interval:=1;
  end;

  x:=100;
  y:=100;

  xx:=0.01;
  yy:=0.01;

  smoother:=0;

end;

procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  h:=x;
  v:=y;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  x:=x+xx;
  y:=y+yy;


  if smoother=5 then
  begin
    invalidate;
    smoother:=0;
  end;

  inc(smoother);

  if (x<h) and (xx<3) then xx:=xx+0.1;
  if (x>h) and (xx>-3) then xx:=xx-0.1;
  if (y<v) and (yy<3) then yy:=yy+0.1;
  if (y>v) and (yy>-3) then yy:=yy-0.1;

  if (x<0) or (trunc(x)>clientwidth) then xx:=-xx;
  if (y<0) or (trunc(y)>clientheight) then yy:=-yy;

end;

end.

Jangita.
http://www.jangita.com
mailto:[EMAIL PROTECTED]
 

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf
Of Christian Labrie
Sent: 05 December 2005 1:57 a
To: [email protected]
Subject: Re: [delphi-en] Re: Looking for a prey-predator simulation.

No I would like a grid and 2 spots on it, chasing each others.

No need for a 3D animation simulation or anything complex.

Just a simple grid with the prey, the preadtor and the algorithm.

Thanks a lot

----- Original Message -----
From: "fishsqzr" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Sunday, December 04, 2005 5:37 PM
Subject: [delphi-en] Re: Looking for a prey-predator simulation.


> --- In [email protected], Christian Labrie
> <[EMAIL PROTECTED]> wrote:
> >
> > Anyone,
> >
> > any source code would be very helpful.
> >
> > Thanks a lot.
> >
> Are you talking about wildlife biology simulations for predator-prey or
> something totally different?  I might be able to locatate something
> since I work for wildlife agancy but it probably won't be in Delphi, if
> I can locate the source code at all.  Let me know at
> [EMAIL PROTECTED]
>
>
>
>
>
>
>
> -----------------------------------------------------
> Home page: http://groups.yahoo.com/group/delphi-en/
> To unsubscribe: [EMAIL PROTECTED]
> Yahoo! Groups Links
>
>
>
>
>
>
>





-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links



 





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/KIlPFB/vlQLAA/TtwFAA/i7folB/TM
--------------------------------------------------------------------~-> 

-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to