PlayLoud!!

Since1997

弾幕1000発

弾幕ってほどではないのだが、弾をたくさん発射してみた。
例によって三角関数テーブルでどっちへ飛んでいくときも同じ速度になるように調整。
1000発発射してもだいぶ余裕あるな。画面から出て行く分があるから1000発出てるのか不明だけど。
こんなもんばかり作ってないで、そろそろ色々な処理ををタスク化してリスト構造にしようかと思う。
動画は15fpsなのでカクカクだが、本物は60fpsで動いているのでぬるぬるしてる。実行ファイルはこちら
ソースは以下。

#include "DxLib.h"
#include "math.h"

int count = 0;

typedef struct{
		float x,y;
        int direction,speed;
}tama;

void fps(){
    int i;
    static int t=0,ave=0,f[60];

    f[count%60]=GetNowCount()-t;
    t=GetNowCount();
    if(count%60==59){
        ave=0;
        for(i=0;i<60;i++)
            ave+=f[i];
        ave/=60;
    }
    if(ave!=0){
        DrawFormatString(0, 0,GetColor(255,255,255),"%.1fFPS",1000.0/(double)ave);
        DrawFormatString(0,20,GetColor(255,255,255),"%dms"  ,ave);
    }
    return;
}

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){
        
    char Key[256];
    tama tama[1000];
	int hayasa = 3;
	int num = 0,x,y;

    if( ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1 ) return -1; //ウィンドウ化と初期化処理

		//サイン、コサインテーブル作成
	float fsin[360],fcos[360];

	int i;
	for(i=0;i<360;i++)
	{
		fsin[i]=(float)sin(i*3.1415926535/180);
		fcos[i]=(float)cos(i*3.1415926535/180);
	}

	for(i=0;i<1000;i++)
	{
		tama[i].direction=-1;
	}


    SetDrawScreen( DX_SCREEN_BACK ) ;                                                 //描画先を裏画面に設定
	int GrHandle ;
	GrHandle = LoadGraph( "tama.bmp" ) ;

    while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){
           //↑メッセージ処理        ↑画面をクリア         ↑キーボード入力状態取得       ↑ESCが押されると終了

	for(i=0;i<1000;i++)
	{
		if(tama[i].direction==-1)
		{
			tama[i].direction=num;
			tama[i].x=320;
			tama[i].y=240;
			tama[i].speed=hayasa;
			num+=17;
			num%=360;
			hayasa +=3;
			hayasa %=10;
			if(hayasa==0)
			{
				hayasa= 3;
			}
		}
		else
		{
			tama[i].x += (fcos[tama[i].direction]) * (float)tama[i].speed;
			tama[i].y += (fsin[tama[i].direction]) * (float)tama[i].speed;
			if(tama[i].x>639||tama[i].x<0||tama[i].y>479||tama[i].y<0)
			{
				tama[i].direction=-1;
			}
		}
		if(tama[i].direction>-1)
		{
			x=(int)tama[i].x;
			y=(int)tama[i].y;
			DrawGraph( x , y , GrHandle , TRUE ) ;//[弾の画像を描画
		}
	}

		fps();
		count++;
        ScreenFlip();
    }

    DxLib_End();
    return 0;
}