マリオ風のジャンプが出ない。(意図したとおりにならない)
Posted: 2017年3月10日(金) 17:29
http://dixq.net/forum/viewtopic.php?f=3&t=18906の続きです。
前回は加減速を(めり込むという問題点はあるもの)なんとか実装させたのですが、今度は小ジャンプを実装しようと思います。
…ですが、何故か何もしないとジャンプしてしまい、左右に入れると落下してしまいます。
前回から変更したコードは以下のとおりです。
前回は加減速を(めり込むという問題点はあるもの)なんとか実装させたのですが、今度は小ジャンプを実装しようと思います。
…ですが、何故か何もしないとジャンプしてしまい、左右に入れると落下してしまいます。
前回から変更したコードは以下のとおりです。
int main(void) {
FreamStartTime = GetNowCount();
while (GetNowCount() - FreamStartTime < 1000 / 60) {}
system("cls");
printf("メインループ開始\n");
printf("\nPlayerX=%d,PlayerY=%d,Grav=%8.1f,DropPower=%8.1f", (int)PlayerX, (int)PlayerY, Grav,DropPower);
printf("\nMoveX=%8.1f,MoveY=%8.1f,Jump=%d", MoveX, MoveY,JumpFlag);
printf("\nCharX=%8.1f,CharY=%8.1f,CameraX=%d,CameraY=%d,ViewX=%8.1f,ViewY=%8.1f", CharX, CharY, CameraX, CameraY, ViewCharX, ViewCharY);
printf("\n現在の向き=%d\t右は1、左は0,NonVert = %d,VectX = %8.1f,JumpTimer = %d", Dir, NonVertJump, VectX,JumpTimer);
//カメラの処理を行う
CameraCheck(PlayerX, PlayerY);
//入力状態を更新
{
int i;
i = GetJoypadInputState(DX_INPUT_KEY_PAD1);
EdgeInput = i & ~Input;
Input = i;
}
//移動処理
{
float MaxVect;
int DashTimer = 8;
int ContTimer = 8;
DashCnt = 0;
ContCnt = 0;
//ベクトルを初期化し、加減速処理を行う。
if (NonVertJump == FALSE) {
MoveX = 0.0F;
VectX = 0.0F;
MaxVect = 0.0F;
}
else {
MoveX = VectX;
}
MoveY = 0.0F;
char RunButton;
//0なら移動していない、1なら右へ移動中、2なら左へ移動中
char NonVertJumpFlag = 0;
if ((Input&PAD_INPUT_2) > PAD_INPUT_ON) {
RunButton = TRUE;
}
else {
RunButton = FALSE;
}
//右へ移動
if (NonVertJump == FALSE && (Input&PAD_INPUT_RIGHT) > PAD_INPUT_ON) {
Dir = TRUE;
NonVertJumpFlag = 1;
if (RunButton == TRUE && JumpFlag == FALSE) {
MoveX = 8.0F;
}
else if (RunButton == FALSE && JumpFlag == FALSE) {
MoveX = 5.0F;
}
else {
MoveX = 3.0F;
}
}
//左に移動
if (NonVertJump == FALSE && (Input&PAD_INPUT_LEFT) > PAD_INPUT_ON) {
Dir = FALSE;
NonVertJumpFlag = 2;
if (RunButton == TRUE) {
MoveX = -8.0F;
}
else if (RunButton == FALSE && JumpFlag == FALSE) {
MoveX = -5.0F;
}
else {
MoveX = -3.0F;
}
}
if (JumpTimer < 0) {
if ((Input&PAD_INPUT_1) > PAD_INPUT_ON) {
JumpTimer++;
}
}
else {
if (JumpTimer < 10 && NonVertJumpFlag == 0) {
Grav = 0.5F;
DropPower = -5.0F;
JumpFlag = TRUE;
}
//垂直大ジャンプ
if (JumpTimer == 10 && NonVertJumpFlag == 0) {
Grav = 0.5F;
DropPower = -9.5F;
JumpFlag = TRUE;
}
//斜めへジャンプ
if (JumpFlag == FALSE && NonVertJumpFlag == 1 && (EdgeInput&PAD_INPUT_1) > PAD_INPUT_ON) {
Grav = 0.5F;
DropPower = -9.5F;
if (RunButton == TRUE) {
VectX = 8.0F;
MaxVect = 8.0F;
}
else {
VectX = 5.0F;
MaxVect = 5.0F;
}
//斜めに飛んでいることを確認
NonVertJump = TRUE;
JumpFlag = TRUE;
//コントロールカウントをリセット
ContCnt = 0;
}
if (JumpFlag == FALSE && NonVertJumpFlag == 2 && (EdgeInput&PAD_INPUT_1) > PAD_INPUT_ON) {
Grav = 0.5F;
DropPower = -9.5F;
if (RunButton == TRUE) {
VectX = -8.0F;
}
else {
VectX = -5.0F;
}
//斜めに飛んでいることを確認
NonVertJump = TRUE;
JumpFlag = TRUE;
//コントロールカウントをリセット
ContCnt = 0;
}
}
}
if (NonVertJump == TRUE && VectX == 0) {
NonVertJump = FALSE;
}
//右へジャンプしているときに左で減速
if (NonVertJump == TRUE && VectX > 0 &&(Input&PAD_INPUT_LEFT) > PAD_INPUT_ON) {
VectX -= 0.5F;
if (DropPower < 0) {
DropPower += 0.1F;
}
else {
DropPower -= 0.1F;
}
MoveX = VectX;
}
//左へジャンプしているときに右で減速
if (NonVertJump == TRUE && VectX < 0 &&(Input&PAD_INPUT_RIGHT) > PAD_INPUT_ON) {
VectX += 0.5F;
if (DropPower < 0) {
DropPower += 0.1F;
}
else {
DropPower -= 0.1F;
}
MoveX = VectX;
}
ContCnt++;
//落下処理
DropPower += Grav;
MoveY = DropPower;
//移動量に基づいて移動する。
CharMove(&PlayerX, &PlayerY, MoveX, MoveY, &DropPower, &Grav, &JumpFlag, &AirFlag, &NonVertJump, &JumpTimer ,&VectX, CHIP_SIZE);
//マップの描画
{
int i, j;
for (i = 0; i < MAP_HEIGHT; i++) {
for (j = 0; j < MAP_WIDTH; j++) {
if (MapData[i][j] == 1) {
DrawBox(j*CHIP_SIZE - CameraX, i*CHIP_SIZE - CameraY, j*CHIP_SIZE + CHIP_SIZE - CameraX, i*CHIP_SIZE + CHIP_SIZE - CameraY, GetColor(255, 255, 255), TRUE);
}
}
}
}
//キャラの描画
DrawBox((int)(ViewCharX)-(CHIP_SIZE / 2), (int)(ViewCharY)-(CHIP_SIZE / 2), (int)(ViewCharX + CHIP_SIZE) - (CHIP_SIZE / 2), (int)(ViewCharY + CHIP_SIZE) - (CHIP_SIZE / 2), GetColor(255, 0, 0), TRUE);
}