#1
by 刀流 » 4年前
C++とDxLibにて2DACTを制作しているものです。
先日、この掲示板で2DACTでの重力の実装について質問させていただき、そのトピックにて基本的なところは理解・実装できたのですが、細かいところでどうしてもわからないところがあります。
現在困っているバグは、
「『移動先の座標に進んでいいか否か』を判定する工程に問題があるらしく」
「座標の更新時に1フレームのラグが出来てしまい、1フレームだけキャラクターがめり込んで表示されてしまったり、その1フレームのラグの間にキャラクター座標が大きく移動すると、めり込んだまま戻ってこなくなってしまったりする」
というものです。
コードはこちらになります。
Gravity.cpp
コード:
int y;
double speed = 0;
// 足の衝突 頭の衝突
double Gravity(int hantei, bool hedhit) {
y += speed; //重力加速度を足しこむ
if (hantei == 0) { // 地面に足がついていないなら
speed += 0.4f; // 加速
if (hedhit == true) { // 頭が地形に当たったなら
y = y / 32 * 32 + 33; // 位置を修正
speed = 2.0f; // 加速度を遅めに固定する
}
}
if (hantei == 1) { // 地面に足がついているなら
if (jump == 1) { // ジャンプボタンがおされたなら
speed = -9.8f; // ジャンプ
}
y = y / 32 * 32 + 4 ; // 位置調整
}
if (speed > 10.2f) // 重力が最大値を超えていたら
speed = 10.2f; // 調整
return y; // y座標を返す
}
Player.h
コード:
typedef struct {
int player_x;
double player_y;
//その他、ゲーム進行に使う変数(地形判定とは無関係)
} Player_t;
extern int camera_x;
extern bool player_isabletogoright, player_isabletogoleft;
extern bool player_hedhit;
Player.cpp
コード:
int Player_maphit_x_1, Player_maphit_x_2, Player_maphit_x_3, Player_maphit_x_4, Player_maphit_y_1, Player_maphit_y_2, Player_maphit_y_3, Player_maphit_y_4;
int camera_x;
int player_hantei;
bool player_isabletogoright;
bool player_isabletogoleft;
bool player_hedhit;
void Player_Update(Player_t *Player){
Player_maphit_x_1 = Player->player_x / 32.0000 + camera_x / 32.0000 - 16 / 32.0000 + 1 / 32.0000; // 最左のx座標
Player_maphit_x_2 = Player->player_x / 32.0000 + camera_x / 32.0000 - 8 / 32.0000; // 真ん中少し左のx座標
Player_maphit_x_3 = Player->player_x / 32.0000 + camera_x / 32.0000 + 8 / 32.0000; // 真ん中少し右のx座標
Player_maphit_x_4 = Player->player_x / 32.0000 + camera_x / 32.0000 + 16 / 32.0000 - 1 / 32.0000; // 最右のx座標
Player_maphit_y_1 = Player->player_y / 32.0000 - 32 / 32.0000 + 1 / 32.0000; // 最高のy座標
Player_maphit_y_2 = Player->player_y / 32.0000 - 16 / 32.0000;// 真ん中少し上のy座標
Player_maphit_y_3 = Player->player_y / 32.0000 + 16 / 32.0000;// 真ん中少し下のy座標
Player_maphit_y_4 = Player->player_y / 32.0000 + 32 / 32.0000 - 1 / 32.0000; // 最低のy座標
if (Keyboard_Get(KEY_INPUT_LEFT) >= 1) {//左キーが押されていたら
if (player_isabletogoleft == true) {
if (Player->player_x <= 200 && camera_x >= 1)
camera_x -= 2;
else
Player->player_x -= 2;
}
}
if (Keyboard_Get(KEY_INPUT_RIGHT) >= 1) {//右キーが押されていたら
if (player_isabletogoright == true) {
if (Player->player_x < 320)
Player->player_x += 2;
else
camera_x += 2;
}
}
Player->player_y = Gravity(player_hantei, player_hedhit);
//その他、ゲーム進行に必要な処理(地形判定とは無関係)
}
Stage1.h
コード:
typedef struct {
//マップデータ
int stage1_hantei[17][131] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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他、ゲーム進行に使う変数(地形判定とは無関係)
} Stage1_t;
Stage1.cpp
コード:
void Stage1_Update(Stage1_t *stage1) {
//底部の衝突判定
if (stage1->stage1_hantei[Player_maphit_y_4][Player_maphit_x_2] != 0 || stage1->stage1_hantei[Player_maphit_y_4][Player_maphit_x_3] != 0) {
player_hantei = 1;
}
else if (stage1->stage1_hantei[Player_maphit_y_4][Player_maphit_x_2] == 0 && stage1->stage1_hantei[Player_maphit_y_4][Player_maphit_x_3] == 0) {
player_hantei = 0;
}
//頭の衝突判定
if (stage1->stage1_hantei[Player_maphit_y_1][Player_maphit_x_2] != 0 || stage1->stage1_hantei[Player_maphit_y_1][Player_maphit_x_3] != 0) {
player_hedhit = true;
}
else if (stage1->stage1_hantei[Player_maphit_y_1][Player_maphit_x_2] == 0 && stage1->stage1_hantei[Player_maphit_y_1][Player_maphit_x_3] == 0) {
player_hedhit = false;
}
//右に進めるか判定
if (stage1->stage1_hantei[Player_maphit_y_2][Player_maphit_x_4] != 0 || stage1->stage1_hantei[Player_maphit_y_3][Player_maphit_x_4] != 0) {
player_isabletogoright = false;
}
else if (stage1->stage1_hantei[Player_maphit_y_2][Player_maphit_x_4] == 0 && stage1->stage1_hantei[Player_maphit_y_3][Player_maphit_x_4] == 0) {
player_isabletogoright = true;
}
//左に進めるか判定
if (stage1->stage1_hantei[Player_maphit_y_2][Player_maphit_x_1] != 0 || stage1->stage1_hantei[Player_maphit_y_3][Player_maphit_x_1] != 0) {
player_isabletogoleft = false;
}
else if (stage1->stage1_hantei[Player_maphit_y_2][Player_maphit_x_1] == 0 && stage1->stage1_hantei[Player_maphit_y_3][Player_maphit_x_1] == 0) {
player_isabletogoleft = true;
}
Player_Update(&Player);
}//更新
なお、コードは衝突判定に関係あるところのみの記載になっております。
また、キャラクターはLoadDivGraphにて読み込んで描画しているので、Player->player_xとPlayer->player_yはそれぞれ真ん中の座標になっています。
実行に関してはStage1_Updateを呼び出して行っています。
ご解答よろしくお願いします。
C++とDxLibにて2DACTを制作しているものです。
先日、この掲示板で2DACTでの重力の実装について質問させていただき、そのトピックにて基本的なところは理解・実装できたのですが、細かいところでどうしてもわからないところがあります。
現在困っているバグは、
「『移動先の座標に進んでいいか否か』を判定する工程に問題があるらしく」
「座標の更新時に1フレームのラグが出来てしまい、1フレームだけキャラクターがめり込んで表示されてしまったり、その1フレームのラグの間にキャラクター座標が大きく移動すると、めり込んだまま戻ってこなくなってしまったりする」
というものです。
コードはこちらになります。
Gravity.cpp
[code]
int y;
double speed = 0;
// 足の衝突 頭の衝突
double Gravity(int hantei, bool hedhit) {
y += speed; //重力加速度を足しこむ
if (hantei == 0) { // 地面に足がついていないなら
speed += 0.4f; // 加速
if (hedhit == true) { // 頭が地形に当たったなら
y = y / 32 * 32 + 33; // 位置を修正
speed = 2.0f; // 加速度を遅めに固定する
}
}
if (hantei == 1) { // 地面に足がついているなら
if (jump == 1) { // ジャンプボタンがおされたなら
speed = -9.8f; // ジャンプ
}
y = y / 32 * 32 + 4 ; // 位置調整
}
if (speed > 10.2f) // 重力が最大値を超えていたら
speed = 10.2f; // 調整
return y; // y座標を返す
}
[/code]
Player.h
[code]
typedef struct {
int player_x;
double player_y;
//その他、ゲーム進行に使う変数(地形判定とは無関係)
} Player_t;
extern int camera_x;
extern bool player_isabletogoright, player_isabletogoleft;
extern bool player_hedhit;
[/code]
Player.cpp
[code]
int Player_maphit_x_1, Player_maphit_x_2, Player_maphit_x_3, Player_maphit_x_4, Player_maphit_y_1, Player_maphit_y_2, Player_maphit_y_3, Player_maphit_y_4;
int camera_x;
int player_hantei;
bool player_isabletogoright;
bool player_isabletogoleft;
bool player_hedhit;
void Player_Update(Player_t *Player){
Player_maphit_x_1 = Player->player_x / 32.0000 + camera_x / 32.0000 - 16 / 32.0000 + 1 / 32.0000; // 最左のx座標
Player_maphit_x_2 = Player->player_x / 32.0000 + camera_x / 32.0000 - 8 / 32.0000; // 真ん中少し左のx座標
Player_maphit_x_3 = Player->player_x / 32.0000 + camera_x / 32.0000 + 8 / 32.0000; // 真ん中少し右のx座標
Player_maphit_x_4 = Player->player_x / 32.0000 + camera_x / 32.0000 + 16 / 32.0000 - 1 / 32.0000; // 最右のx座標
Player_maphit_y_1 = Player->player_y / 32.0000 - 32 / 32.0000 + 1 / 32.0000; // 最高のy座標
Player_maphit_y_2 = Player->player_y / 32.0000 - 16 / 32.0000;// 真ん中少し上のy座標
Player_maphit_y_3 = Player->player_y / 32.0000 + 16 / 32.0000;// 真ん中少し下のy座標
Player_maphit_y_4 = Player->player_y / 32.0000 + 32 / 32.0000 - 1 / 32.0000; // 最低のy座標
if (Keyboard_Get(KEY_INPUT_LEFT) >= 1) {//左キーが押されていたら
if (player_isabletogoleft == true) {
if (Player->player_x <= 200 && camera_x >= 1)
camera_x -= 2;
else
Player->player_x -= 2;
}
}
if (Keyboard_Get(KEY_INPUT_RIGHT) >= 1) {//右キーが押されていたら
if (player_isabletogoright == true) {
if (Player->player_x < 320)
Player->player_x += 2;
else
camera_x += 2;
}
}
Player->player_y = Gravity(player_hantei, player_hedhit);
//その他、ゲーム進行に必要な処理(地形判定とは無関係)
}
[/code]
Stage1.h
[code]
typedef struct {
//マップデータ
int stage1_hantei[17][131] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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変数(地形判定とは無関係)
} Stage1_t;
[/code]
Stage1.cpp
[code]
void Stage1_Update(Stage1_t *stage1) {
//底部の衝突判定
if (stage1->stage1_hantei[Player_maphit_y_4][Player_maphit_x_2] != 0 || stage1->stage1_hantei[Player_maphit_y_4][Player_maphit_x_3] != 0) {
player_hantei = 1;
}
else if (stage1->stage1_hantei[Player_maphit_y_4][Player_maphit_x_2] == 0 && stage1->stage1_hantei[Player_maphit_y_4][Player_maphit_x_3] == 0) {
player_hantei = 0;
}
//頭の衝突判定
if (stage1->stage1_hantei[Player_maphit_y_1][Player_maphit_x_2] != 0 || stage1->stage1_hantei[Player_maphit_y_1][Player_maphit_x_3] != 0) {
player_hedhit = true;
}
else if (stage1->stage1_hantei[Player_maphit_y_1][Player_maphit_x_2] == 0 && stage1->stage1_hantei[Player_maphit_y_1][Player_maphit_x_3] == 0) {
player_hedhit = false;
}
//右に進めるか判定
if (stage1->stage1_hantei[Player_maphit_y_2][Player_maphit_x_4] != 0 || stage1->stage1_hantei[Player_maphit_y_3][Player_maphit_x_4] != 0) {
player_isabletogoright = false;
}
else if (stage1->stage1_hantei[Player_maphit_y_2][Player_maphit_x_4] == 0 && stage1->stage1_hantei[Player_maphit_y_3][Player_maphit_x_4] == 0) {
player_isabletogoright = true;
}
//左に進めるか判定
if (stage1->stage1_hantei[Player_maphit_y_2][Player_maphit_x_1] != 0 || stage1->stage1_hantei[Player_maphit_y_3][Player_maphit_x_1] != 0) {
player_isabletogoleft = false;
}
else if (stage1->stage1_hantei[Player_maphit_y_2][Player_maphit_x_1] == 0 && stage1->stage1_hantei[Player_maphit_y_3][Player_maphit_x_1] == 0) {
player_isabletogoleft = true;
}
Player_Update(&Player);
}//更新
[/code]
なお、コードは衝突判定に関係あるところのみの記載になっております。
また、キャラクターはLoadDivGraphにて読み込んで描画しているので、Player->player_xとPlayer->player_yはそれぞれ真ん中の座標になっています。
実行に関してはStage1_Updateを呼び出して行っています。
ご解答よろしくお願いします。