したらばTOP ■掲示板に戻る■ 全部 1-100 最新50 | |

C言語

21AF:2013/05/02(木) 14:34:15
chap4のmain.cppの完成版ソース その3
--------------------------------------------------
//ステージ初期化
void InitStage(){
//ゲームデータ全体のゼロ初期化
ZeroMemory(&g_stage, sizeof(g_stage));
//全ボディ・ジョイント削除
DeleteAllBody();

//ボールを追加
b2Body* ball = CreateDynamicBall(PHS(300), PHS(0), PHS(40));
g_stage.wall = CreateBox(PHS(320), PHS(400),
PHS(200), PHS(20), false);
g_stage.hero = CreateBox(PHS(140), PHS(300),
PHS(23), PHS(48), true);

//ゲーム開始時刻の記録
g_stage.gamestarttime = g_lasttime;
}


//ゲームクリア画面描画
void GoGameClear(){
g_gamestate = GAME_CLEAR;
g_stage.timerstart = g_lasttime;
}
void DrawGameClear(){
//5秒経ったらタイトル画面へ
if(g_lasttime - g_stage.timerstart > 5000) GoGameTitle();
}
//ゲームオーバー画面描画
void GoGameOver(){
g_gamestate = GAME_OVER;
g_stage.timerstart = g_lasttime;
}
void DrawGameOver(){
//5秒経ったらタイトル画面へ
if(g_lasttime - g_stage.timerstart > 5000) GoGameTitle();
}

b2Body* CreateDynamicBall(float x, float y, float radius){
//ボディ定義
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody; //動的ボディ
bodyDef.position.Set(x, y);
//ボディ作成
b2Body* body = g_world.CreateBody(&bodyDef);
//シェイプ作成
b2CircleShape dynamicBall;
dynamicBall.m_radius = radius;
//フィクスチャ定義
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBall;
fixtureDef.density = 4.0f; //密度
fixtureDef.restitution = 0.7f; //反発力
body->CreateFixture(&fixtureDef);
return body;
}

b2Body* CreateBox(float x, float y, float w, float h, bool dynamic){
//ボディ定義
b2BodyDef bodyDef;
if(dynamic) bodyDef.type = b2_dynamicBody; //動的ボディ
else bodyDef.type = b2_staticBody; //静的ボディ
bodyDef.position.Set(x, y);
//bodyDef.angle = 0.1f;
//ボディ作成
b2Body* body = g_world.CreateBody(&bodyDef);
//シェイプ作成
b2PolygonShape staticBox;
staticBox.SetAsBox(w, h);
//フィクスチャ定義
b2FixtureDef fixtureDef;
fixtureDef.shape = &staticBox;
fixtureDef.density = 4.0f; //密度
fixtureDef.restitution = 0.2f; //反発力
fixtureDef.friction = 0.2f; //摩擦係数
body->CreateFixture(&fixtureDef);
return body;
}


新着レスの表示


名前: E-mail(省略可)

※書き込む際の注意事項はこちら

※画像アップローダーはこちら

(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)

掲示板管理者へ連絡 無料レンタル掲示板