[
板情報
|
カテゴリランキング
]
したらばTOP
■掲示板に戻る■
全部
1-100
最新50
| |
P203までの「main.cpp」
3
:
AF
:2013/05/08(水) 14:55:56
b2Body* CreateBox(float x, float y, float w, float h, float angle,bool dynamic){
//ボディ定義
b2BodyDef bodyDef;
if(dynamic) bodyDef.type = b2_dynamicBody; //動的ボディ
else bodyDef.type = b2_staticBody; //静的ボディ
bodyDef.position.Set(x, y);
bodyDef.angle=angle;
//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;
}
//マップの読み込み
int LoadMapData(char *filepath){
int f; //ファイルハンドル
char buf[1024]; //テキスト読み込みバッファ
f = FileRead_open(filepath);
if (f==0) return -1; //読み込みエラー
//マップサイズと主人公初期位置読み込み
if(FileRead_gets( buf, 1023, f ) == -1) return -1;
float w, h, sx, sy;
sscanf_s(buf, "%f, %f, %f, %f", &w, &h, &sx, &sy);
g_stage.mapsize_w = w;
g_stage.mapsize_h = h;
//主人公キャラクター
g_stage.hero = CreateBox(PHS(sx), PHS(sy),
PHS(23), PHS(48), 0, true);
//地形オブジェクト読み込み
if(FileRead_gets( buf, 1023, f ) == -1) return -1;
int imax;
sscanf_s(buf, "%d" , &imax); //行数取得
float x, y, angle;
int id;
for(int i=0; i<imax; i++){
if(FileRead_gets( buf, 1023, f ) == -1) return -1;
sscanf_s( buf, "%f, %f, %f, %f, %f, %d",
&x, &y, &w, &h, &angle, &id);
//ボディ作成
Character ch;
ch.body = CreateBox(PHS(x), PHS(y),PHS(w/2), PHS(h/2), angle, false);
if((int)w == 48) ch.ID = WALL_48;
if((int)w == 192) ch.ID = WALL_192;
if((int)w == 284) ch.ID = WALL_284;
if((int)w == 568) ch.ID = WALL_568;
if(id == 1) ch.ID = GOAL_FLAG;
ch.used = true;
g_stage.wall[g_stage.num_mapchara] = ch;
g_stage.num_mapchara++;
}
FileRead_close(f);
return 0;
}
新着レスの表示
名前:
E-mail
(省略可)
:
※書き込む際の注意事項は
こちら
※画像アップローダーは
こちら
(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)
スマートフォン版
掲示板管理者へ連絡
無料レンタル掲示板