home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1999 February
/
VPR9902A.BIN
/
FFILLY
/
BOID
/
boid1.tfy
< prev
next >
Wrap
Text File
|
1997-11-23
|
2KB
|
142 lines
#info IART "もりきゅう,VZF07161@niftyserve.or.jp"
#info ICMT "Boid 1"
#info INAM "Boid 1"
#info ICOP "(c)Kazuhiro.Yoshida"
#info ISBJ "Boid 1"
#info VIDO "640x480; 256"
#info GRPC "もりきゅう,VZF07161@niftyserve.or.jp"
#include "local.tfy"
main()
{
int i;
int x,y;
int sum; // 物体(岩と鳥)の数
int in; // ここまで岩。ここから鳥。
int wMain;
int pBase,pBack,pBoid,pRock;
int cBack;
int nTransColor; // 透明色
int cBoid[];
int bw2,bh2;
int nx[],ny[]; // 位置
int vx[],vy[]; // 速度
int ax[],ay[]; // 加速度
pBase = LoadPic("base.bmp");
pBoid = LoadPic("boid.bmp");
pRock = LoadPic("rock.bmp");
pBack = copyPic(pBase);
nTransColor = GetColor(pBoid,0,0);
cBack = PutCast(pBack,pBase);
wMain = OpenWin(pBase);
// ボイド表示修正用
bw2 = PicWidth(pBoid) / 2;
bh2 = PicHeight(pBoid) / 2;
sum = 10;
in = 1;
// 岩の状態
for( i=0 ; i<in ; i=i+1 )
{
nx[i] = PicWidth(pBase)/2;
ny[i] = PicHeight(pBase)/2;
vx[i] = 0;
vy[i] = 0;
ax[i] = 0;
ay[i] = 0;
cBoid[i] = PutCast(pRock,pBase,nx[i]-bw2,ny[i]-bh2,nTransColor);
}
// 鳥の状態
for( i=in ; i<sum ; i=i+1 )
{
nx[i] = Random(PicWidth(pBase));
ny[i] = Random(PicHeight(pBase));
vx[i] = Random(11)-5;
vy[i] = Random(11)-5;
ax[i] = 0;
ay[i] = 0;
cBoid[i] = PutCast(pBoid,pBase,nx[i]-bw2,ny[i]-bh2,nTransColor);
}
int mesTIME;
mes(TIME)
{
step(3)
{
// 質量中心を求める
x=0;
y=0;
for(i=0;i<sum;i=i+1)
{
x = x + nx[i];
y = y + ny[i];
}
x = x/sum;
y = y/sum;
// 規則1
// 鳥は質量中心に向かう
for(i=in;i<sum;i=i+1)
{
if ( nx[i] < x )
{
ax[i] = 1;
}
else if ( nx[i] > x )
{
ax[i] = -1;
}
if ( ny[i] < y )
{
ay[i] = 1;
}
else if ( ny[i] > y )
{
ay[i] = -1;
}
}
// 鳥の状態を変化
for(i=in;i<sum;i=i+1)
{
vx[i] = vx[i] + ax[i];
vy[i] = vy[i] + ay[i];
nx[i] = nx[i] + vx[i] / 2;
ny[i] = ny[i] + vy[i] / 2;
}
// 移動
for(i=in;i<sum;i=i+1)
{
MoveCast(cBoid[i],pBoid,nx[i]-bw2,ny[i]-bh2);
}
}
}
mesTIME = GetMesNo(0);
int pause;
pause = 0;
mes(LBUP)
{
if ( pause == 0 ) {
FreezeMes(mesTIME);
pause = 1;
} else {
ActivateMes(mesTIME);
pause = 0;
}
}
}