水面を表現する

水面エフェクトです。
やってることはファイアエフェクトと一緒です。
水っぽい色を使って、その色をセルオートマン的に変えてやります。
二枚の水面をフリップしているのは、コンピュータの性質上、すべてのセルの計算を同時には行えないためです。
実行画面は、トップページのアプレットを見てください。
↓汚いソース。。。インデントもおかしい。。。
   //-------------------------------
   //      水面を描写する
   //-------------------------------
    public void DrawWater()
    {
        int     x,y;
        int	flip1,flip2;
        int	depth_R;
        int	depth_G;
        int	depth_B;
        int     depth;

	//カウンタを使って、二枚の水面テーブルをフリップする。
        flip1 = gameCtr&1;	//gameCtrが奇数なら真
        flip2 = flip1^1;	//flip1が偶数なら1

        for(y=1; y<199; y++){
		for(x=1; x<199; x++){

                        //ピクセルごとに上下左右の色成分の平均を出す

                        //赤
                        depth_R =(depthTbl[flip1][x-1][y  ]&0x00ff0000)>>16; //左
                        depth_R +=(depthTbl[flip1][x  ][y-1]&0x00ff0000)>>16; //上
                        depth_R +=(depthTbl[flip1][x+1][y  ]&0x00ff0000)>>16; //右
                        depth_R +=(depthTbl[flip1][x  ][y+1]&0x00ff0000)>>16; //下
                        depth_R = depth_R>>1;
                        if((depth_R -= (depthTbl[flip2][x  ][y  ]&0x00ff0000)>>16)<0)//水面の中央を引く
			    depth_R = 0x00000000;//0以下なら0
                        if(depth_R > 0x000000ff)
                            depth_R = 0x000000ff;//飽和処理

                        //緑
                        depth_G =(depthTbl[flip1][x-1][y  ]&0x0000ff00)>>8; //左
                        depth_G +=(depthTbl[flip1][x  ][y-1]&0x0000ff00)>>8; //上
                        depth_G +=(depthTbl[flip1][x+1][y  ]&0x0000ff00)>>8; //右
                        depth_G +=(depthTbl[flip1][x  ][y+1]&0x0000ff00)>>8; //下
                        depth_G = depth_G>>1;
                        if((depth_G -= (depthTbl[flip2][x  ][y  ]&0x0000ff00)>>8) < 0)//水面の中央を引く
			    depth_G = 0x00000000;//0以下なら0
                        if(depth_G > 0x000000ff)
                            depth_G = 0x000000ff;//飽和処理

                        //青
                        depth_B =(depthTbl[flip1][x-1][y  ]&0x000000ff); //左
                        depth_B +=(depthTbl[flip1][x  ][y-1]&0x000000ff); //上
                        depth_B +=(depthTbl[flip1][x+1][y  ]&0x000000ff); //右
                        depth_B +=(depthTbl[flip1][x  ][y+1]&0x000000ff); //下
                        depth_B = depth_B>>1;
                        if((depth_B -= (depthTbl[flip2][x  ][y  ]&0x000000ff)) < 0)
			    depth_B = 0x00000000;//0以下なら0
                        if(depth_B > 0x000000ff)
                            depth_B = 0x000000ff;//飽和処理

                        //各成分を合成する
                        depth = (depth_R<<16) | (depth_G<<8) | (depth_B);

                        //色が噴出すような効果を出す(ゆらぎを与える)
                        if(time_count >= 1180){
			    if(depth<=(darkColor(texbuf3[200*y +x])&0x00777777))
                                depth= texbuf3[200*y + x]&0x00999999;
                        }

                        depth |= 0xff000000;//アルファ成分を足す
			depthTbl[flip2][x][y]=(depth);	//次回の水面に結果を代入
		}
	}

        //サーフェイスに水面を描画する
	for(y=0; y<HEIGHT; y++){
		for(x=0; x<WIDTH; x++){
			pbuf[x + y * WIDTH]   = depthTbl[flip2][x][y];
		}
	}
	gameCtr++;	//カウンタ更新
    }