ソースは、こちらです。
#include"DXLib.h"
#include"keybord.h"
#include<math.h>
struct STAGE{
float X,Z;
}stage={20,0};
struct Player{
float X,Y,Z,flag,angleY,HP,HPMAX,HPflag,HX,HY,ang,speed;
}player={20,0.0f,200,1,0,300,100,0,0,0,0,50};
struct Camera{
float X,Y,Z,High;
}camera={0,0,0,150.0f};
static float cursor_x,cursor_y,cursor_z=150.0f;
static float Playtime,Totaltime,Totaltime0,Totaltime1,Totaltime2,Totaltime3,Totaltime4;
static int Player_mode=4;
static int STAGE,PLAYER,Light;//3Dモデルの読み込み
static int AttachIndex0=-1,AttachIndex1=-1,AttachIndex2=-1,AttachIndex3=-1,AttachIndex4=-1;
static int Attachflag_1_3=0;
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
ChangeWindowMode(TRUE),DxLib_Init(),SetDrawScreen(DX_SCREEN_BACK);
STAGE=MV1LoadModel("GAME/ネオUKシティ/model/ネオUKシティ.x");
PLAYER=MV1LoadModel("GAME/高校生.x");//プレイヤー
Light=CreatePointLightHandle(VGet(stage.X,1000.0f,stage.Z),5000.0f,0.0f,0.002f,0.0f);
/////////////////////
///テストよう視点///
///////////////////
camera.X = player.X;
camera.Y = 2600;
camera.Z = player.Z - 2394;
cursor_x = player.X;
cursor_z = player.Z - 568;
cursor_y = 2420;
//カメラの範囲
SetCameraNearFar( 2.0f, 1000000.0f );
// モデルアニメ初期化
AttachIndex4=MV1AttachAnim(PLAYER,4,-1,FALSE);
AttachIndex3=MV1AttachAnim(PLAYER,3,-1,FALSE);
AttachIndex0=MV1AttachAnim(PLAYER,0,-1,FALSE);
AttachIndex1=MV1AttachAnim(PLAYER,1,-1,FALSE);
//総再生時間取得
Totaltime4=MV1GetAttachAnimTotalTime(PLAYER,AttachIndex4);
Totaltime3=MV1GetAttachAnimTotalTime(PLAYER,AttachIndex3);
Totaltime0=MV1GetAttachAnimTotalTime(PLAYER,AttachIndex0);
Totaltime1=MV1GetAttachAnimTotalTime(PLAYER,AttachIndex1);
// 一旦アニメ2をデタッチ
MV1DetachAnim(PLAYER,AttachIndex0);
AttachIndex0=-1;
MV1DetachAnim(PLAYER,AttachIndex1);
AttachIndex1=-1;
MV1DetachAnim(PLAYER,AttachIndex3);
AttachIndex3=-1;
MV1DetachAnim(PLAYER,AttachIndex4);
AttachIndex4=-1;
Playtime=0.0f;
while(ScreenFlip()==0&&ProcessMessage()==0&&ClearDrawScreen()==0){
//移動
if(keybord_Get(KEY_INPUT_W)>0){
Playtime+=1.0f;
}
if(Player_mode==3){
int Mouse=GetMouseInput();
if(Mouse&MOUSE_INPUT_LEFT){
Playtime+=1.0f;
}
}
/////////////////////////////////
/////////モード3////////////////
///////////////////////////////
if(Player_mode==3){
int Mouse=GetMouseInput();
if(Mouse&MOUSE_INPUT_LEFT){
Attachflag_1_3=1;
}else{
Attachflag_1_3=0;
}
////////////////
///フラグOFF///
//////////////
if(Attachflag_1_3==0){
if(AttachIndex1!=-1){
Playtime=0.0f;
MV1DetachAnim(PLAYER,AttachIndex1);
AttachIndex1=-1;
}
if(AttachIndex3==-1){
AttachIndex3=MV1AttachAnim(PLAYER,3,-1,FALSE);
}
}
////////////////
///フラグON////
//////////////
if(Attachflag_1_3==1){
if(AttachIndex3!=-1){
Playtime=0.0f;
MV1DetachAnim(PLAYER,AttachIndex3);
AttachIndex3=-1;
}
if(AttachIndex1==-1){
AttachIndex1=MV1AttachAnim(PLAYER,1,-1,FALSE);
}
}
if(keybord_Get(KEY_INPUT_1)>0){
Player_mode=4;
Playtime=0.0f;
if(AttachIndex3!=-1){
MV1DetachAnim(PLAYER,AttachIndex3);
AttachIndex3=-1;
}
if(AttachIndex1!=-1){
MV1DetachAnim(PLAYER,AttachIndex1);
AttachIndex1=-1;
}
}
if(Playtime>=Totaltime3){
Playtime=0.0f;
}
}
/////////////////////////////////
/////////モード4////////////////
///////////////////////////////
if(Player_mode==4){
if(AttachIndex4==-1){
AttachIndex4=MV1AttachAnim(PLAYER,4,-1,FALSE);
}
if(keybord_Get(KEY_INPUT_2)>0){
Player_mode=0;
Playtime=0.0f;
if(AttachIndex4!=-1){
MV1DetachAnim(PLAYER,AttachIndex4);
AttachIndex4=-1;
}
}
if(Playtime>=Totaltime4){
Playtime=0.0f;
}
}
/////////////////////////////////
/////////モード0////////////////
///////////////////////////////
if(Player_mode==0){
if(AttachIndex0==-1){
AttachIndex0=MV1AttachAnim(PLAYER,0,-1,FALSE);
}
if(Playtime>=Totaltime0){
if(AttachIndex0!=-1){
MV1DetachAnim(PLAYER,AttachIndex0);
AttachIndex0=-1;
}
Player_mode=3;
Playtime=0.0f;
}else{
Playtime+=1.0f;
}
}
//再生時間セット
if(AttachIndex4!=-1){
MV1SetAttachAnimTime(PLAYER,AttachIndex4,Playtime);
}
if(AttachIndex3!=-1){
MV1SetAttachAnimTime(PLAYER,AttachIndex3,Playtime);
}
if(AttachIndex0!=-1){
MV1SetAttachAnimTime(PLAYER,AttachIndex0,Playtime);
}
if(AttachIndex1!=-1){
MV1SetAttachAnimTime(PLAYER,AttachIndex1,Playtime);
}
SetCameraPositionAndTarget_UpVecY(VGet(camera.X,camera.Y,camera.Z),VGet(cursor_x,cursor_y,cursor_z));
MV1SetPosition(STAGE,VGet(stage.X,400.0f,stage.Z));//ステージの位置
MV1SetPosition(PLAYER,VGet(player.X,player.Y,player.Z));//プレイヤーの位置
MV1SetRotationXYZ(PLAYER,VGet(0.0f,player.angleY,0.0f));//プレイヤーの回転
MV1SetScale(STAGE,VGet(1000.0f,1000.0f,1000.0f));
MV1SetScale(PLAYER,VGet(1.0f,1.0f,1.0f));
SetLightPositionHandle(Light,VGet(stage.X,1000.0f,stage.Z));
//3Dモデルの描画
MV1DrawModel(STAGE);//ステージ
MV1DrawModel(PLAYER);//プレイヤー
DrawFormatString(0,40,GetColor(0,255,255),"AttachIndex3=%d\n",AttachIndex3);
DrawFormatString(0,140,GetColor(0,255,255),"AttachIndex4=%d\n",AttachIndex4);
DrawFormatString(0,280,GetColor(0,255,255),"Totaltime3=%f\n",Totaltime3);
DrawFormatString(0,300,GetColor(0,255,255),"Totaltime4=%f\n",Totaltime4);
DrawFormatString(0,0,GetColor(0,255,255),"Playtime=%f\n",Playtime);
DrawFormatString(0,20,GetColor(0,255,255),"Player_mode=%d\n",Player_mode);
}
}
問題点は、
・左クリックで撃つアニメ、Wで走るアニメをしないといけないんですが、撃つアニメがWと左クリックをしないと再生されません。
たぶん、アタッチするフラグをONにするために左クリックでかつ再生にも左クリックなので再生されないのかなと思っています。
また、アニメを切り替えた時の初期化の仕方がわからないです。
if(W){
}else{
再生時間の初期化
}
としてもいいんですが、その場合、自動再生される切り替えのアニメの番目が再生されなくなります。
またインデントがおかしかったらすみません。
質問が多いですが、よろしくお願いします。