ページ 11

弾幕の弾作成

Posted: 2010年9月11日(土) 21:26
by Ultimate
真ん中の固定された敵から円形に球が100個広がるように作りたいのですが、うまくできません。
なぜうまくいかないのか教えてください。
下にソースを載せます。
まだ使ってない変数などもありますが、これからつかうものなのでそちらは気にしないでください。

#include "DxLib.h"
#include "math.h"
#define PI 3.14159265358979323846

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){
ChangeWindowMode( TRUE ) ; // ウインドウモードに変更
if( DxLib_Init() == -1 ) return -1; // DXライブラリ初期化処理 エラーが起きたら終了

//色の設定
int WHITE,BLACK,RED,GREEN,BLUE;

WHITE = GetColor(255,255,255);
BLACK = GetColor(0,0,0);
RED = GetColor(255,0,0);
GREEN = GetColor(0,255,0);
BLUE = GetColor(0,0,255);

//その他設定
SetBackgroundColor(255,255,255);//背景色


//その他変数
int i,j;
char Key[256];


//画像読み込み

int back;//背景
back=LoadGraph("back.png");

int tmain;//敵メイン
tmain=LoadGraph("teki_main.png");

//構造体作成
//メイン敵の弾1
typedef struct{
int x[100]; //X座標
int y[100]; //Y座標
int nagasa; //X座標、Y座標の基準になる長さ
double sinsin[100]; //サイン値
double coscos[100]; //コサイン値
double r[100]; //ラジアン値
int flag; //フラグ
int count; //カウント
}ch_t;
ch_t tmain1;



//初期化
//敵の弾1
tmain1.flag=0;
tmain1.nagasa=0;
for(i=0;i<=99;i++){
tmain1.x=0;
tmain1.y=0;
if(i>0){
tmain1.r=2*PI/(99/i);//100個の弾それぞれのラジアンを求める。
}
else tmain1.r=0;
}
for(i=0;i<=99;i++){
if(i>0){
tmain1.sinsin = sin(2*PI/(99/i));//100個の弾それぞれのサイン値
tmain1.coscos = cos(2*PI/(99/i));//100個の弾それぞれのコサイン値
}
else{
tmain1.sinsin = 1;
tmain1.coscos = 1;
}
}


//メインループ

SetDrawScreen( DX_SCREEN_BACK ) ; // 描画先を裏画面に設定

while(ProcessMessage()==0 && ClearDrawScreen()==0 && CheckHitKey(KEY_INPUT_ESCAPE)==0){
//↑メッセージ処理   ↑画面をクリア       ↑ESCが押されていない
ClearDrawScreen(); // 裏画面のデータを全て削除






//敵メイン攻撃
//弾の座標
tmain1.nagasa+=2;
for(i=0;i<=99;i++){
tmain1.x = (tmain1.nagasa * tmain1.coscos)+320;
tmain1.y[i] = (tmain1.nagasa * tmain1.sinsin[i])+240;
}
//描画
for(i=0;i<=99;i++){
DrawCircle(tmain1.x[i],tmain1.y[i],2,BLACK);
}


//敵メイン表示
DrawGraph(320-13,240-13,tmain,TRUE);




ScreenFlip();

}

WaitKey() ; // 結果を見るためにキー待ち(『WaitKey』を使用)
DxLib_End() ; // DXライブラリ使用の終了処理
return 0 ; // ソフトの終了
}





メインの敵は画像ですみません。

どこが原因で円形に広がらないのか教えてください。

Re:弾幕の弾作成

Posted: 2010年9月11日(土) 21:36
by Ultimate
ちなみに、画像も付けてこれを実行すると、下の画像のようになります。

Re:弾幕の弾作成

Posted: 2010年9月11日(土) 21:38
by Rom
たぶん小数型であるtmainr[/url]に代入にしてるところ
tmain1.r=2*PI/(99/i);//100個の弾それぞれのラジアンを求める。
で、2*PIだと(整数型)*(小数)で
整数に直されてるとかそんなん。
tmain1.r=2.0*PI/(99.0/(double)i);
とすればいいかもしれない。

自分もこのまえ同じ間違いしてたから
自信はないけど。

Re:弾幕の弾作成

Posted: 2010年9月11日(土) 21:44
by Ultimate
その通りでした。

ありがとうございました。

あと1か所訂正しましたので、訂正後ソースも載せておきます。


#include "DxLib.h"
#include "math.h"
#define PI 3.14159265358979323846

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){
ChangeWindowMode( TRUE ) ; // ウインドウモードに変更
if( DxLib_Init() == -1 ) return -1; // DXライブラリ初期化処理 エラーが起きたら終了

//色の設定
int WHITE,BLACK,RED,GREEN,BLUE;

WHITE = GetColor(255,255,255);
BLACK = GetColor(0,0,0);
RED = GetColor(255,0,0);
GREEN = GetColor(0,255,0);
BLUE = GetColor(0,0,255);

//その他設定
SetBackgroundColor(255,255,255);//背景色


//その他変数
int i,j;
char Key[256];


//画像読み込み

int back;//背景
back=LoadGraph("back.png");

int tmain;//敵メイン
tmain=LoadGraph("teki_main.png");

//構造体作成
//メイン敵の弾1
typedef struct{
int x[100]; //X座標
int y[100]; //Y座標
int nagasa; //X座標、Y座標の基準になる長さ
double sinsin[100]; //サイン値
double coscos[100]; //コサイン値
double r[100]; //ラジアン値
int flag; //フラグ
int count; //カウント
}ch_t;
ch_t tmain1;



//初期化
//敵の弾1
tmain1.flag=0;
tmain1.nagasa=0;
for(i=0;i<=99;i++){
tmain1.x=0;
tmain1.y=0;
if(i>0){
tmain1.r=2*PI/(99/i);//100個の弾それぞれのラジアンを求める。
}
else tmain1.r=0;
}
for(i=0;i<=99;i++){
if(i>0){
tmain1.sinsin = sin(2.0*PI/(99.0/(double)i));//100個の弾それぞれのサイン値
tmain1.coscos = cos(2.0*PI/(99.0/(double)i));//100個の弾それぞれのコサイン値
}
else{
tmain1.sinsin = 0;
tmain1.coscos = 0;
}
}


//メインループ

SetDrawScreen( DX_SCREEN_BACK ) ; // 描画先を裏画面に設定

while(ProcessMessage()==0 && ClearDrawScreen()==0 && CheckHitKey(KEY_INPUT_ESCAPE)==0){
//↑メッセージ処理   ↑画面をクリア       ↑ESCが押されていない
ClearDrawScreen(); // 裏画面のデータを全て削除






//敵メイン攻撃
//弾の座標
tmain1.nagasa+=2;
for(i=0;i<=99;i++){
tmain1.x = (tmain1.nagasa * tmain1.coscos)+320;
tmain1.y[i] = (tmain1.nagasa * tmain1.sinsin[i])+240;
}
//描画
for(i=0;i<=99;i++){
DrawCircle(tmain1.x[i],tmain1.y[i],2,BLACK);
}


//敵メイン表示
DrawGraph(320-13,240-13,tmain,TRUE);




ScreenFlip();

}

WaitKey() ; // 結果を見るためにキー待ち(『WaitKey』を使用)
DxLib_End() ; // DXライブラリ使用の終了処理
return 0 ; // ソフトの終了
}

Re:弾幕の弾作成

Posted: 2010年9月11日(土) 21:45
by Ultimate
解決しました。