int MoveCamera() { int ret; D3DXVECTOR3 savepos, backpos; ret = E3DGetPos( hsid1, &savepos ); _ASSERT( !ret ); ret = E3DPosForward( hsid1, -2500.0f ); _ASSERT( !ret ); ret = E3DGetPos( hsid1, &backpos ); _ASSERT( !ret ); ret = E3DSetPos( hsid1, savepos ); _ASSERT( !ret ); D3DXVECTOR3 campos, camtarget, camup; campos = D3DXVECTOR3( backpos.x, backpos.y + 2000.0f, backpos.z ); camtarget = D3DXVECTOR3( savepos.x, savepos.y + 800.0f, savepos.z ); camup = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); ret = E3DSetCameraPos( campos ); _ASSERT( !ret ); ret = E3DSetCameraTarget( camtarget, camup ); _ASSERT( !ret ); return 0; }
int ChkConf() { int ret; int result0 = 0; // 地面とキャラクタのあたり判定 D3DXVECTOR3 adjust, n; ret = E3DChkConfGround( hsid1, hsid0, 1, 200.0f, -100.0f, &result0, &adjust, &n ); _ASSERT( !ret ); if( result0 != 0 ){ curpos = adjust; ret = E3DSetPos( hsid1, curpos ); if( ret ){ _ASSERT( 0 ); return 1; } } return 0; }
int OneTimeSceneInit() { int ret; D3DXVECTOR3 campos = D3DXVECTOR3( 53898.0f, 3000.0f, 44982.0f - 2500.0f ); ret = E3DSetCameraPos( campos ); if( ret ){ _ASSERT( 0 ); return 1; } D3DXVECTOR3 camtar = D3DXVECTOR3( 53898.0f, 2500.0f, 44982.0f ); D3DXVECTOR3 camup = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); ret = E3DSetCameraTarget( camtar, camup ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetProjection( 1000.0f, proj_far, 60.0f ); if( ret ){ _ASSERT( 0 ); return 1; } //地面データのロード char name1[MAX_PATH]; sprintf_s( name1, MAX_PATH, "%s\\g_6_20_1.bmp", szMediaDir ); char name2[MAX_PATH]; sprintf_s( name2, MAX_PATH, "%s\\8.bmp", szMediaDir ); char name3[MAX_PATH]; sprintf_s( name3, MAX_PATH, "%s\\g_river_6_20_1.bmp", szMediaDir ); char name4[MAX_PATH]; sprintf_s( name4, MAX_PATH, "%s\\BG43.bmp", szMediaDir ); float mapsize = 120000.0f; int mapdiv = 50; float mapheight = 5500.0f; ret = E3DLoadGroundBMP( name1, name2, name3, name4, mapsize, mapsize, mapdiv, mapdiv, mapheight, &hsid0 ); if( ret ){ _ASSERT( 0 ); return 1; } //モロ星人のロード char signame[MAX_PATH]; sprintf_s( signame, MAX_PATH, "%s\\morob_6_26_r3.sig", szMediaDir ); ret = E3DSigLoad( signame, 0, 1.0f, &hsid1 ); if( ret ){ _ASSERT( 0 ); return 1; } char quaname[MAX_PATH]; sprintf_s( quaname, MAX_PATH, "%s\\morob_6_26_r3.qua", szMediaDir ); int maxframe; ret = E3DAddMotion( hsid1, quaname, 1.0f, &motid1, &maxframe ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetMotionKind( hsid1, motid1 ); if( ret ){ _ASSERT( 0 ); return 1; } curpos = D3DXVECTOR3( 53898.0f, 3000.0f, 44982.0f ); befpos = curpos; ret = E3DSetPos( hsid1, curpos ); if( ret ){ _ASSERT( 0 ); return 1; } D3DXVECTOR3 deg = D3DXVECTOR3( 0.0f, 120.0f, 0.0f ); ret = E3DSetDir( hsid1, deg ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetBeforePos( hsid1 ); if( ret ){ _ASSERT( 0 ); return 1; } //木(ビルボード)の読み込みと設置 // PosOnGround 命令を使うために、ChkInViewを、あらかじめ、呼んでおく必要があります。 int state; ret = E3DChkInView( scid, hsid0, &state ); if( ret ){ _ASSERT( 0 ); return 1; } srand( 321 ); int bbcnt; for( bbcnt = 0; bbcnt < BBNUM; bbcnt++ ){ int treekind; char treename[MAX_PATH]; treekind = rand() % 3; if( treekind == 0 ){ sprintf_s( treename, MAX_PATH, "%s\\tree01S.tga", szMediaDir ); }else if( treekind == 1 ){ sprintf_s( treename, MAX_PATH, "%s\\tree02S.tga", szMediaDir ); }else{ sprintf_s( treename, MAX_PATH, "%s\\tree35S.tga", szMediaDir ); } ret = E3DCreateBillboard( treename, 2000.0f, 3000.0f, 0, 0, 0, bbid + bbcnt ); if( ret ){ _ASSERT( 0 ); return 1; } int divsize; divsize = (int)mapsize / 4; int randx, randz; randx = ( rand() % divsize ) * 4; randz = ( rand() % divsize ) * 4; ret = E3DSetBillboardOnGround( bbid[bbcnt], hsid0, mapheight, -100.0f, (float)randx, (float)randz ); if( ret ){ _ASSERT( 0 ); return 1; } } //ライト ret = E3DCreateLight( &lid1 ); if( ret ){ _ASSERT( 0 ); return 1; } D3DXVECTOR3 ldir( 0.0f, -1.0f, 2.0f ); E3DCOLOR4UC col= {255, 255, 255, 255 }; ret = E3DSetDirectionalLight( lid1, ldir, col ); if( ret ){ _ASSERT( 0 ); return 1; } //フォグ E3DCOLOR4UC fogcol = { 255, 0, 0, 255 }; ret = E3DSetLinearFogParams( 1, fogcol, 1000.0f, proj_far, -1 ); if( ret ){ _ASSERT( 0 ); return 1; } //モーションブラーの準備 //3番目の引数で何フレーム前のデータでブラーを作るかを指定 ret = E3DSetMotionBlur( hsid0, BLUR_CAMERA, 15 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetMotionBlur( hsid1, BLUR_CAMERA, 5 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetMotionBlur( -1, BLUR_CAMERA, 3 );//-1はビルボード if( ret ){ _ASSERT( 0 ); return 1; } blurdisp[0] = hsid0; blurdisp[1] = hsid1; blurdisp[2] = -1; return 0; }
int ChkConf() { int ret; //壁(hsid2)とキャラクタ(hsid1)のあたり判定 ret = E3DChkConfWall( hsid1, hsid2, 10.0f, &result1, &adj1, &n1 ); _ASSERT( !ret ); if( result1 ){ //向きを、修正する。 //面の法線と90度、ー90度の2つのベクトルを求める。 D3DXVECTOR3 kabe1, kabe2; D3DXVECTOR3 nkabe1, nkabe2; ret = E3DVec3RotateY( n1, 90.0f, &kabe1 ); _ASSERT( !ret ); ret = E3DVec3Normalize( kabe1, &nkabe1 ); _ASSERT( !ret ); ret = E3DVec3RotateY( n1, -90.0f, &kabe2 ); _ASSERT( !ret ); ret = E3DVec3Normalize( kabe2, &nkabe2 ); _ASSERT( !ret ); //キャラクターの向いている向きを求める。 ret = E3DGetPos( hsid1, &pos1 ); _ASSERT( !ret ); D3DXVECTOR3 vec, nvec; vec = D3DXVECTOR3( pos1.x - befpos1.x, 0.0f, pos1.z - befpos1.z ); ret = E3DVec3Normalize( vec, &nvec ); _ASSERT( !ret ); // 90度、ー90度の2つのベクトルのベクトルと、キャラクターの向きの内積を取り、 // 内積の大きな方を選んで、そちらに、向きを変える。 float dot, dot1, dot2; dot1 = D3DXVec3Dot( &nvec, &nkabe1 ); dot2 = D3DXVec3Dot( &nvec, &nkabe2 ); D3DXVECTOR2 nvecxz, nkabexz; int ccw; if( dot1 >= dot2 ){ nvecxz = D3DXVECTOR2( nvec.x, nvec.z ); nkabexz = D3DXVECTOR2( nkabe1.x, nkabe1.z ); dot = dot1; ret = E3DVec2CCW( nvecxz, nkabexz, &ccw ); _ASSERT( !ret ); }else{ nvecxz = D3DXVECTOR2( nvec.x, nvec.z ); nkabexz = D3DXVECTOR2( nkabe2.x, nkabe2.z ); dot = dot2; ret = E3DVec2CCW( nvecxz, nkabexz, &ccw ); _ASSERT( !ret ); } dot = min( 1.0f, dot ); dot = max( -1.0f, dot ); float newdeg; newdeg = (float)acos( dot ) * (float)PAI2DEG; if( ccw > 0 ){ newdeg *= -1.0f; } ret = E3DRotateY( hsid1, newdeg / 20.0f ); _ASSERT( !ret ); // 位置を修正する pos1 = adj1; ret = E3DSetPos( hsid1, pos1 ); _ASSERT( !ret ); } // 地面と、キャラクタのあたり判定 ret = E3DChkConfGround( hsid1, hsid0, 1, 200.0f, -1000.0f, &result2, &adj2, &n2 ); if( result2 != 0 ){ ret = E3DSetPos( hsid1, adj2 ); _ASSERT( !ret ); } return 0; }
int OneTimeSceneInit() { int ret; result1 = 0; result2 = 0; adj1 = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); adj2 = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); n1 = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); n2 = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 campos = D3DXVECTOR3( 0.0f, 2500.0f, 0.0f ); ret = E3DSetCameraPos( campos ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetCameraDeg( 180.0f, 0.0f ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetProjection( 1000.0f, 50000.0f, 60.0f ); if( ret ){ _ASSERT( 0 ); return 1; } char gname1[MAX_PATH]; char gname2[MAX_PATH]; char gname3[MAX_PATH]; char gname4[MAX_PATH]; sprintf_s( gname1, MAX_PATH, "%s\\g_6_20_1.bmp", szMediaDir ); sprintf_s( gname2, MAX_PATH, "%s\\8.bmp", szMediaDir ); sprintf_s( gname3, MAX_PATH, "%s\\g_river_6_20_1.bmp", szMediaDir ); sprintf_s( gname4, MAX_PATH, "%s\\BG43.bmp", szMediaDir ); ret = E3DLoadGroundBMP( gname1, gname2, gname3, gname4, MAPSIZE, MAPSIZE, MAPDIV, MAPDIV, MAPHEIGHT, &hsid0 ); if( ret ){ _ASSERT( 0 ); return 1; } char signame[MAX_PATH]; sprintf_s( signame, MAX_PATH, "%s\\morob_6_26_r3.sig", szMediaDir ); ret = E3DSigLoad( signame, 0, 1.0f, &hsid1 ); if( ret ){ _ASSERT( 0 ); return 1; } char motname[MAX_PATH]; sprintf_s( motname, MAX_PATH, "%s\\morob_6_26_r3.qua", szMediaDir ); ret = E3DAddMotion( hsid1, motname, 1.0f, &motid1, &maxframe1 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetMotionKind( hsid1, motid1 ); if( ret ){ _ASSERT( 0 ); return 1; } pos1.x = 53898.0f; pos1.y = 3000.0f;//初期位置は必ず地面よりも上でなければならない。 pos1.z = 44982.0; befpos1 = pos1; D3DXVECTOR3 deg1( 0.0f, 180.0f, 0.0f ); ret = E3DSetPos( hsid1, pos1 ); _ASSERT( !ret ); ret = E3DSetDir( hsid1, deg1 ); _ASSERT( !ret ); ret = E3DSetBeforePos( hsid1 );//位置を初期化した直後に必ず呼ぶこと! if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetMovableArea( gname2, MAPSIZE, MAPSIZE, MAPDIV, MAPDIV, MAPHEIGHT + 1000.0f, &hsid2 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DCreateLight( &lid1 ); if( ret ){ _ASSERT( 0 ); return 1; } D3DXVECTOR3 ldir( 0.0f, 0.0f, 1.0f ); E3DCOLOR4UC col= {255, 255, 255, 255 }; ret = E3DSetDirectionalLight( lid1, ldir, col ); if( ret ){ _ASSERT( 0 ); return 1; } E3DCOLOR4UC fogcol; fogcol.a = 255; fogcol.r = 0; fogcol.g = 0; fogcol.b = 255; ret = E3DSetLinearFogParams( 1, fogcol, 1000.0f, 50000.0f, -1 ); if( ret ){ _ASSERT( 0 ); return 1; } char bgname1[MAX_PATH]; char bgname2[MAX_PATH]; sprintf_s( bgname1, MAX_PATH, "%s\\lake.bmp", szMediaDir ); sprintf_s( bgname2, MAX_PATH, "%s\\cloud3.bmp", szMediaDir ); ret = E3DCreateBG( scid, bgname1, bgname2, 0.001f, 0.0f, 0, 50000.0f ); if( ret ){ _ASSERT( 0 ); return 1; } return 0; }
int MoveChara( int chara1, int chara2, char key1, char key2, char key3, char key4, char key5, char key6, char key7 ) { int ret; int eventno; if( ci[chara1].nagerare == 0 ){ eventno = 0; if( keybuf[key5] == 1 ) eventno = 2; if( keybuf[key6] == 1 ) eventno = 4; if( keybuf[key7] == 1 ) eventno = 8; if( (keybuf[key5] != 0) || (keybuf[key6] != 0) ){ ret = E3DPosForward( ci[chara1].hsid, 5.0f ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetPos( ci[chara1].hsid, &(ci[chara1].pos) ); if( ret ){ _ASSERT( 0 ); return 1; } } if( eventno == 0 ){ if( keybuf[key1] != 0 ){ ret = E3DPosForward( ci[chara1].hsid, 16.0f ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetPos( ci[chara1].hsid, &(ci[chara1].pos) ); if( ret ){ _ASSERT( 0 ); return 1; } eventno = 1; } if( keybuf[key2] != 0 ){ ret = E3DPosForward( ci[chara1].hsid, -16.0f ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetPos( ci[chara1].hsid, &(ci[chara1].pos) ); if( ret ){ _ASSERT( 0 ); return 1; } eventno = 1; } if( keybuf[key3] != 0 ){ ret = E3DRotateY( ci[chara1].hsid, 2.0f ); if( ret ){ _ASSERT( 0 ); return 1; } eventno = 1; } if( keybuf[key4] != 0 ){ ret = E3DRotateY( ci[chara1].hsid, -2.0f ); if( ret ){ _ASSERT( 0 ); return 1; } eventno = 1; } } if( (ci[chara1].motid == *(motionidptr + MOT_MOCHIAGE)) && (ci[chara1].nage == 0) && (ci[chara2].nagerare == 0) ){ ret = E3DDirToTheOther( ci[chara1].hsid, ci[chara2].hsid ); if( ret ){ _ASSERT( 0 ); return 1; } D3DXVECTOR3 diff; diff = ci[chara1].pos - ci[chara2].pos; float mag; mag = diff.x * diff.x + diff.y * diff.y + diff.z * diff.z; if( mag < 900000.0f ){ ci[chara1].nage = 1; ci[chara2].nagerare = 1; ci[chara2].nagevy = NAGEY; D3DXVECTOR3 bonepos; ret = E3DGetBonePos( ci[chara1].hsid, 18, 1, ci[chara1].motid, ci[chara1].frameno, &bonepos ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetDirQ2( ci[chara1].hsid, ci[chara1].qid ); if( ret ){ _ASSERT( 0 ); return 1; } D3DXVECTOR3 befvec( 0.0f, 0.0f, -1.0f ); D3DXVECTOR3 dir; ret = E3DMultQVec( ci[chara1].qid, befvec, &dir ); if( ret ){ _ASSERT( 0 ); return 1; } ci[chara2].pos.x = bonepos.x + dir.x * 300.0f; ci[chara2].pos.y = bonepos.y - 300.0f; ci[chara2].pos.z = bonepos.z + dir.z * 300.0f; ret = E3DSetPos( ci[chara2].hsid, ci[chara2].pos ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetBoneQ( ci[chara1].hsid, 18, ci[chara1].motid, ci[chara1].frameno, 2, ci[chara2].qid ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetDirQ2( ci[chara2].hsid, ci[chara2].qid ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetNewPoseByMOA( ci[chara2].hsid, 16 ); if( ret ){ _ASSERT( 0 ); return 1; } } } ret = E3DSetNewPoseByMOA( ci[chara1].hsid, eventno ); if( ret ){ _ASSERT( 0 ); return 1; } }else{ ci[chara1].nagerare += 1; if( ci[chara1].nagerare < 50 ){ ret = E3DSetNewPoseByMOA( ci[chara1].hsid, 16 ); if( ret ){ _ASSERT( 0 ); return 1; } }else{ if( ci[chara1].nagerare < 120 ){ ret = E3DGetDirQ2( ci[chara2].hsid, ci[chara2].qid ); if( ret ){ _ASSERT( 0 ); return 1; } D3DXVECTOR3 befvec2( 0.0f, 0.0f, -1.0f ); D3DXVECTOR3 dir2; ret = E3DMultQVec( ci[chara2].qid, befvec2, &dir2 ); if( ret ){ _ASSERT( 0 ); return 1; } ci[chara1].pos.x += dir2.x * 20.0f; ci[chara1].pos.z += dir2.z * 20.0f; ci[chara1].nagevy += GRAVITY; ci[chara1].pos.y += ci[chara1].nagevy; if( ci[chara1].pos.y < GROUND_HEIGHT ) ci[chara1].pos.y = GROUND_HEIGHT; ret = E3DSetPos( ci[chara1].hsid, ci[chara1].pos ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetNewPoseByMOA( ci[chara1].hsid, 32 ); if( ret ){ _ASSERT( 0 ); return 1; } }else{ ci[chara1].nagerare = 0; ci[chara2].nage = 0; ci[chara1].pos.y = GROUND_HEIGHT; ret = E3DCopyQ( ci[chara1].qid, ci[chara2].qid ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetDirQ2( ci[chara1].hsid, ci[chara1].qid ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetPos( ci[chara1].hsid, ci[chara1].pos ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetNewPoseByMOA( ci[chara1].hsid, 0 ); if( ret ){ _ASSERT( 0 ); return 1; } } } } int tempframeno; ret = E3DGetMotionFrameNo( ci[chara1].hsid, &(ci[chara1].motid), &(ci[chara1].frameno) ); if( ret ){ _ASSERT( 0 ); return 1; } if( ci[chara1].motid == 0 ){ ret = E3DGetNextMotionFrameNo( ci[chara1].hsid, 0, &(ci[chara1].motid), &tempframeno ); if( ret ){ _ASSERT( 0 ); return 1; } } return 0; }
int OneTimeSceneInit() { int ret; cameradist = 3000.0f; cameraheight = 800.0f; campos.x = (float)GROUND_SIZE * 0.5f; campos.y = (float)GROUND_HEIGHT + cameraheight; campos.z = ( (float)GROUND_SIZE * 0.5f ) - cameradist; ret = E3DSetProjection( 500.0f, 50000.0f, 60.0f ); if( ret ){ _ASSERT( 0 ); return 1; } ZeroMemory( ci, sizeof( CHARAINFO ) * CHARA_MAX ); //赤キャラ初期化 char signame[MAX_PATH]; sprintf_s( signame, MAX_PATH, "%s\\poo\\poo.sig", szMediaDir ); ret = E3DSigLoad( signame, 0, 1.0f, &(ci[CHARA_RED].hsid) ); if( ret ){ _ASSERT( 0 ); return 1; } ci[CHARA_RED].pos = D3DXVECTOR3( 1000.0f, GROUND_HEIGHT, 0.0f ); ret = E3DSetPos( ci[CHARA_RED].hsid, ci[CHARA_RED].pos ); if( ret ){ _ASSERT( 0 ); return 1; } E3DCOLOR4UC redcol = { 255, 255, 0, 0 }; ret = E3DSetToonEdge0Color( ci[CHARA_RED].hsid, -1, "dummy", redcol ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetToonEdge0Width( ci[CHARA_RED].hsid, -1, "dummy", 10.0f ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DRotateY( ci[CHARA_RED].hsid, 90.0f ); if( ret ){ _ASSERT( 0 ); return 1; } char motname[MAX_PATH]; sprintf_s( motname, MAX_PATH, "%s\\poo\\poo.moa", szMediaDir ); ret = E3DLoadMOAFile( ci[CHARA_RED].hsid, motname, 10, 1.0f ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DCreateQ( &(ci[CHARA_RED].qid) ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetBeforePos( ci[CHARA_RED].hsid ); if( ret ){ _ASSERT( 0 ); return 1; } ci[CHARA_RED].hp = HPMAX; //青きゃらの初期化 sprintf_s( signame, MAX_PATH, "%s\\poo\\poo.sig", szMediaDir ); ret = E3DSigLoad( signame, 0, 1.0f, &(ci[CHARA_BLUE].hsid) ); if( ret ){ _ASSERT( 0 ); return 1; } ci[CHARA_BLUE].pos = D3DXVECTOR3( -1000.0f, GROUND_HEIGHT, 0.0f ); ret = E3DSetPos( ci[CHARA_BLUE].hsid, ci[CHARA_BLUE].pos ); if( ret ){ _ASSERT( 0 ); return 1; } E3DCOLOR4UC bcol = { 255, 0, 0, 255 }; ret = E3DSetToonEdge0Color( ci[CHARA_BLUE].hsid, -1, "dummy", bcol ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetToonEdge0Width( ci[CHARA_BLUE].hsid, -1, "dummy", 10.0f ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DRotateY( ci[CHARA_BLUE].hsid, -90.0f ); if( ret ){ _ASSERT( 0 ); return 1; } sprintf_s( motname, MAX_PATH, "%s\\poo\\poo.moa", szMediaDir ); ret = E3DLoadMOAFile( ci[CHARA_BLUE].hsid, motname, 10, 1.0f ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DCreateQ( &(ci[CHARA_BLUE].qid) ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetBeforePos( ci[CHARA_BLUE].hsid ); if( ret ){ _ASSERT( 0 ); return 1; } ci[CHARA_BLUE].hp = HPMAX; /////////////////// E3DGetMotionNum( ci[CHARA_RED].hsid, &motnum ); motionidptr = (int*)malloc( sizeof( int ) * motnum ); if( !motionidptr ){ _ASSERT( 0 ); return 1; } ret = E3DGetMotionIDByName( ci[CHARA_RED].hsid, "idling", motionidptr + MOT_IDLING ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetMotionIDByName( ci[CHARA_RED].hsid, "walk", motionidptr + MOT_WALK ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetMotionIDByName( ci[CHARA_RED].hsid, "tsuki", motionidptr + MOT_TSUKI ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetMotionIDByName( ci[CHARA_RED].hsid, "kick", motionidptr + MOT_KICK ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetMotionIDByName( ci[CHARA_RED].hsid, "defence", motionidptr + MOT_DEFENCE ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetMotionIDByName( ci[CHARA_RED].hsid, "mochiage", motionidptr + MOT_MOCHIAGE ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetMotionIDByName( ci[CHARA_RED].hsid, "jitabata", motionidptr + MOT_JITABATA ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetMotionIDByName( ci[CHARA_RED].hsid, "nagerare", motionidptr + MOT_NAGERARE ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetMotionIDByName( ci[CHARA_RED].hsid, "tsunagi", motionidptr + MOT_TSUNAGI ); if( ret ){ _ASSERT( 0 ); return 1; } //////////////////// char bgname[MAX_PATH]; sprintf_s( bgname, MAX_PATH, "%s\\bmpfile\\a007bcg.bmp", szMediaDir ); ret = E3DCreateBG( scid, bgname, "dummy", 0.0f, 0.0f, 0, 50000.0f ); if( ret ){ _ASSERT( 0 ); return 1; } char gname[MAX_PATH]; sprintf_s( gname, MAX_PATH, "%s\\bmpfile\\gplane.mqo", szMediaDir ); ret = E3DLoadMQOFileAsGround( gname, 100.0, 0, BONETYPE_RDB2, &groundhsid ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DCreateLight( &lid1 ); if( ret ){ _ASSERT( 0 ); return 1; } D3DXVECTOR3 ldir( 0.0f, -1.0f, 1.0f ); E3DCOLOR4UC col= {255, 255, 255, 255 }; ret = E3DSetDirectionalLight( lid1, ldir, col ); if( ret ){ _ASSERT( 0 ); return 1; } confflag = 0; gameflag = 0; return 0; }
/*キャラを動かします、前後左右に動けます*/ int PlayerChara::MoveChara(){ /*変数の初期化*/ int ech = 0;//エラー確認変数 int KeyMov = 0;//キーを押してどの方向に動くかの変数 int MovOn = 0;//動いていいかのフラグ int keyin[20];//キー情報配列を作成 float WantDeg = 0;//向きたい方向の変数 float FixedMoveSpeed = 0.0f;//それぞれの状態の固定速度 D3DXVECTOR3 SubPos( 0.0, 0.0, 0.0);//キャラクターを置く場所の座標 D3DXVECTOR3 PCPos( 0.0, 0.0, 0.0);//プレイヤーキャラクターの位置の座標 /*ダッシュ操作がオンになっていないかチェック*/ /*キーによる分岐*/ System::GetKeyData(keyin);//キー情報を格納 if( keyin[0] == 1){//左 KeyMov = KeyMov +1; } if( keyin[1] == 1){//上 KeyMov = KeyMov +2; } if( keyin[2] == 1){//右 KeyMov = KeyMov +4; } if( keyin[3] == 1){//下 KeyMov = KeyMov +8; } /*キーから取得した情報を変換*/ if(KeyMov == 1){//左 WantDeg = -90.0f + Get_PC_Deg_XZ(); MovOn = 1; /*モーションを「左歩き」にする*/ Set_UnderMotion(3); } if(KeyMov == 3){//左上 WantDeg = -45.0f + Get_PC_Deg_XZ(); MovOn = 1; /*モーションを「左前進」にする*/ Set_UnderMotion(4); } if(KeyMov == 2){//上 WantDeg = Get_PC_Deg_XZ(); MovOn = 1; /*モーションを「歩行」にする*/ Set_UnderMotion(1);//通常 } if(KeyMov == 6){//右上 WantDeg = 45.0f + Get_PC_Deg_XZ(); MovOn = 1; /*モーションを「左前進」にする*/ Set_UnderMotion(5); } if(KeyMov == 4){//右 WantDeg = 90.0f + Get_PC_Deg_XZ(); MovOn = 1; /*モーションを「右歩き」にする*/ Set_UnderMotion(2); } if(KeyMov == 12){//右下 WantDeg = 135.0f + Get_PC_Deg_XZ(); MovOn = 1; /*モーションを「右後進」にする*/ Set_UnderMotion(7); } if(KeyMov == 8){//下 WantDeg = 180.0f + Get_PC_Deg_XZ(); MovOn = 1; /*モーションを「後進」にする*/ Set_UnderMotion(8); } if(KeyMov == 9){//左下 WantDeg = -135.0f + Get_PC_Deg_XZ(); MovOn = 1; /*モーションを「左後進」にする*/ Set_UnderMotion(6); } //キーが入力されていても、キック中なら if( Get_MyState() == 1) { MovOn = 0;//絶対動かない } //空中で、ダッシュ状態なら if( ( Get_AirOnPC() == 1) && ( Get_MyState() == 2)){ WantDeg = Get_PC_Deg_XZ();//まっすぐ進む MovOn = 1;//絶対動く } //左飛び状態なら if( Get_MyState() == 3) { WantDeg = -90.0f + Get_PC_Deg_XZ(); MovOn = 1;//絶対動く } //右飛び状態なら if( Get_MyState() == 4) { WantDeg = 90.0f + Get_PC_Deg_XZ(); MovOn = 1;//絶対動く } /*動く方向を決めるよ*/ if(MovOn == 1){ if( Get_MyState() == 0){//通常状態なら if( Get_AirOnPC() == 0){//空中でなければ if(Get_Attitude() == 0){//姿勢が「立っている状態」なら /*スピードを増加させる*/ Set_MoveSpeed( Get_MoveSpeed() + 0.8f); //スピードに制限をかける if( 25.0f <= Get_MoveSpeed() ){ Set_MoveSpeed( 25.0f); } //固定スピードの設定(立ち) FixedMoveSpeed = 50.0f; } if(Get_Attitude() == 1){//姿勢が「しゃがみ状態」なら /*スピードを増加させる*/ Set_MoveSpeed( Get_MoveSpeed() + 0.4f); //スピードに制限をかける if( 20.0f <= Get_MoveSpeed() ){ Set_MoveSpeed( 20.0f); } //固定スピードの設定(しゃがみ) FixedMoveSpeed = 30.0f; } } if( Get_AirOnPC() == 1){//空中にいるなら /*スピードを増加させる*/ Set_MoveSpeed(Get_MoveSpeed() + 0.3f); //スピードに制限をかける if( 10.0f <= Get_MoveSpeed() ){ Set_MoveSpeed( 10.0f); } //固定スピードの設定(しゃがみ) FixedMoveSpeed = 20.0f; } } if( Get_MyState() == 2){//ダッシュ状態なら if( Get_AirOnPC() == 0){//地上にいるなら /*スピードを増加させる*/ Set_MoveSpeed( Get_MoveSpeed() + 2.0f); //スピードに制限をかける if( 40.0f <= Get_MoveSpeed() ){ Set_MoveSpeed(40.0f); } //固定スピードの設定(しゃがみ) FixedMoveSpeed = 70.0f; } if( Get_AirOnPC() == 1){//空中にいるなら /*スピードを増加させる*/ Set_MoveSpeed( Get_MoveSpeed() + 2.0f); //スピードに制限をかける if( 40.0f <= Get_MoveSpeed() ){ Set_MoveSpeed(40.0f); } //固定スピードの設定(しゃがみ) FixedMoveSpeed = 70.0f; } } if( ( Get_MyState() == 3) || ( Get_MyState() == 4)){//左飛び状態なら /*スピードを固定*/ Set_MoveSpeed(0.0f); //固定スピードの設定(しゃがみ) FixedMoveSpeed = 90.0f; } /*ダミーモデルの座標に設定*/ ech = E3DRotateInit ( Get_DummyModel()); _ASSERT( ech != 1 );//エラーチェック ech = E3DGetPos( Get_BodyModel(), &PCPos); _ASSERT( ech != 1 );//エラーチェック ech = E3DSetPos( Get_DummyModel(), PCPos); _ASSERT( ech != 1 );//エラーチェック ech = E3DRotateY( Get_DummyModel(), WantDeg); _ASSERT( ech != 1 );//エラーチェック ech = E3DPosForward( Get_DummyModel(), (float)Get_MoveSpeed() + FixedMoveSpeed); _ASSERT( ech != 1 );//エラーチェック ech = E3DGetPos( Get_DummyModel(), &SubPos); _ASSERT( ech != 1 );//エラーチェック ech = E3DSetPos( Get_BodyModel(), SubPos); _ASSERT( ech != 1 );//エラーチェック } else{//減速をさせなければならないなら if( Get_AirOnPC() == 0){//空中にいるなら if( Get_Attitude() == 0) Set_MoveSpeed( Get_MoveSpeed() - 0.8f);//姿勢が「通常状態」なら if( Get_Attitude() == 1) Set_MoveSpeed( Get_MoveSpeed() - 1.0f);//姿勢が「しゃがみ状態」なら } if( Get_AirOnPC() == 1) Set_MoveSpeed( Get_MoveSpeed() - 0.6f);//姿勢が「しゃがみ状態」なら //スピードに制限をかける if( Get_MoveSpeed() <= 0.0 ){ Set_MoveSpeed( 0.0f); } Set_UnderMotion(0); } return 0; }