#include "ALL.h"
int playerSpeed = 5; // 歩く速さ
int playerX = 0; // X座標
int playerY = 256; // Y座標
int playerImgIndex = 0; // 描画する画像の番号
int count = 0; // カウント
int timer;
void Player();
int WINAPI WinMain(HINSTANCE h1, HINSTANCE hp, LPSTR lpC, int nC)
{
// ウィンドウモードにする
ChangeWindowMode(TRUE);
SetGraphMode(1280, 720, 32);
// DXライブラリの初期化
if (DxLib_Init() == -1) return -1;
// 裏画面を描画対象にする
SetDrawScreen(DX_SCREEN_BACK);
// 正常にDXライブラリが処理されていて、ESCPEキーが押されているときのみループを脱出する
while (ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0)
{
// 画面消去
ClearDrawScreen();
// この中に行いたい処理を書いていく
static bool Initflag = true;
if (Initflag) {
load();
PlayerInit();
Initflag = false;
};
PlayerUpdate();
timer++;
// 画面入れ替え
ScreenFlip();
}
// DXライブラリの終了処理
DxLib_End();
return 0;
}
#include "ALL.h"
#define JPOWER 5;
//ジャンプ用変数
bool jflag = false;
bool onGround = true;
static int jcnt;
int gravity = 1;
OBJ2D Player;
void PlayerDraw(OBJ2D*p);
void PlayerMain(OBJ2D*p);
void PlayerSet(OBJ2D*p, int x, int y, int type);
void PlayerAnim();
struct PLAYER_SET_DATA
{
int x, y;
int mvAlg;
};
PLAYER_SET_DATA p_st_data[] = {
{0,658,0}
};
void PlayerInit()
{
//プレイヤーの初期設定
for (int i = 0; i < 1; i++) {
OBJ2D*p = &Player;
if (p->exist) continue;
PlayerSet(p, p_st_data[i].x, p_st_data[i].y, p_st_data[i].mvAlg);
};
};
void PlayerUpdate()
{
for (int i = 0; i < 1; i++) {
OBJ2D*p = &Player;
if (!p->exist)continue;
switch (p->mvAlg)
{
case 0:PlayerMain(p); break;
}
PlayerDraw(p);
};
};
void PlayerSet(OBJ2D*p, int x, int y, int type)
{
p->pos.x = x;
p->pos.y = y;
p->mvAlg = type;
p->exist = true;
};
void PlayerMain(OBJ2D*p)
{
p->speed.x = 0;
gravity = 1;
// カーソルキーの左が押されている
if (CheckHitKey(KEY_INPUT_LEFT)) {
p->speed.x = -5; // プレイヤーのX座標を減算
}
// カーソルキーの右が押されている
if (CheckHitKey(KEY_INPUT_RIGHT)) {
p->speed.x = 5; // プレイヤーのX座標を加算
}
if (timer == 4) {
PlayerAnim();
timer = 0;
};
//ジャンプ処理
if (jflag == true) {
jcnt++;
int cntmax = 0;
Player.speed.y -= jcnt;
cntmax = JPOWER;
if (jcnt > cntmax) {
jcnt = 0;
jflag = false;
}
}
if (onGround == true && CheckHitKey(KEY_INPUT_UP)) {
jflag = true;
}
unsigned int Color;
Color = GetColor(255, 255, 255);
DrawFormatString(0, 0, Color, "Player.pos.y:%d", Player.pos.y);
DrawFormatString(0, 15, Color, "Player.speed.y:%d", p->speed.y);
DrawFormatString(0, 30, Color, "Player.speed.x:%d", Player.speed.x);
DrawFormatString(0, 45, Color, "Player.pos.x:%d", Player.pos.x);
DrawFormatString(0, 60, Color, "jcnt:%d", jcnt);
DrawFormatString(0, 75, Color, "Count:%d", count);
DrawFormatString(0, 90, Color, "playerImgIndex:%d", playerImgIndex);
/*重力加算*/
Player.speed.y += gravity;
//位置に速度を加算して移動
p->pos.x += p->speed.x;
p->pos.y += p->speed.y;
//速度チェック
if (p->speed.y <= -15) {
p->speed.y = -15;
};
//足元判定
if (p->pos.y >= 658) {
gravity = 0;
p->speed.y = 0;
p->pos.y = 657;
onGround = true;
}
else {
onGround = false;
};
};
void PlayerDraw(OBJ2D*p)
{
DrawGraph(p->pos.x, p->pos.y, handle.image.Player[playerImgIndex], true);
};
void PlayerAnim() {
//移動アニメーション
// カーソルキーの左が押されている
if (CheckHitKey(KEY_INPUT_LEFT))
{
++count;
// 表示する画像の番号を変更
playerImgIndex = (count % 9) + 9; // countを9で割った余り +9、つまり9~17が入る
}
// カーソルキーの右が押されている
if (CheckHitKey(KEY_INPUT_RIGHT))
{
++count;
// 表示する画像の番号を変更
playerImgIndex = (count % 9) + 9; // countを9で割った余り +9、つまり9~17が入る
}
//待機アニメーション
if (CheckHitKey(KEY_INPUT_RIGHT) == false && CheckHitKey(KEY_INPUT_LEFT) == false)
{
++count;
playerImgIndex = count % 8;
};
//ジャンプアニメーション
if (jflag)
{
++count;
playerImgIndex = (count % 9) + 18;
};
};
struct position {
int x, y;
};
struct OBJ2D {
position pos;
position speed;
int mvAlg;
bool exist;
};
走りアニメーションと待機アニメーションの切り替えはできたのですがここにジャンプアニメーションを追加したところ、ジャンプアニメーションの1コマ目しか描画されない状態です。
原因と解決方法を教えてください。