DirectXの場合はY軸は上に上がると数字がマイナスされた下にいくと数字がプラスされますが数式を使う場合はY軸はこの逆なのでそこと数式を使わない時でY軸の軸の向きを整理したいのですが当たり判定があったりと色々でどこをどうしたいいかわかりません。わかりやすい方法などありますでしょうか?
複数の場所で座標など描画など決まりごとそのものがわかりません。
Player.cpp
#include "Input.h" #include "Player.h" #include "DxLib.h" #include "Map.h" #define MOVE_SPD 5 /*コンストラクタ*/ Player::Player(const char* str, int xx, int yy) :pos{xx,yy} { LoadDivGraph(str,7,7,1,64,64,g_handle); } /*計算更新*/ void Player::Update() { input_key(); //gravity(); } /*描画更新*/ void Player::Draw_Update() { DrawFormatString(100,100,GetColor(255,255,255),"Debug"); DrawGraph(gPos_x(), gPos_y(), g_handle[0], true); } /*キー入力*/ void Player::input_key() { if (keybord(KEY_INPUT_LEFT) > 0) { sPos_x(-MOVE_SPD); } if (keybord(KEY_INPUT_RIGHT) > 0) { sPos_x(+MOVE_SPD); } /*ジャンプ*/ if (keybord(KEY_INPUT_SPACE) > 0) { if (n <= 0) { n = 0; gravity(); } sPos_y(n); n = (n - 2); } else { n = jump_range;//減った値を再設定 gravity(); } } /*重力効果*/ void Player::gravity() { bool t = Map::col(pos.x,pos.y); if (gPos_y() < 1000) { sPos_y(-2); } if (t == true) { DrawFormatString(0, 100, GetColor(255, 255, 255), "collsiion"); } } /*座標の取得と設定*/ void Player::sPos_x(int xx)//加算 { pos.x += xx; } void Player::sPos_y(int yy)//加算 { pos.y += -yy; } int& Player::gPos_x() { return pos.x; } int& Player::gPos_y() { return pos.y; }
Map.cpp
#include "Map.h" #define CELL 64 int Map::map_set[11][20] = { {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1}, }; /*マップセル取得*/ int Map::draw_mapCell(int& x, int& y) { return (int)map_set[y][x]; } int Map::get_mapCell(int& x, int& y) { return (int)map_set[y][x]; } /*描画 更新*/ void Map::Draw_Update() { for (int y = 0; y < 11; y++) { for (int x = 0; x < 20; x++) { DrawGraph(x * 64, y * 64, ghandle[draw_mapCell(x, y)], true); } } } /*計算 更新*/ void Map::Update() { } /*当たり判定 当たったらtrue*/ bool Map::col(int& px, int& py)//引数はプレイヤー座標 当たっていたらtrue { ///////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// DrawFormatString(px + 100,py,GetColor(255,255,255),"x: %d ,y %d",px,py); for (int y = 10; y >= 0; y--) { for (int x = 19; x >= 0; x--) { if (get_mapCell(x, y) == 0) { if ( (y * CELL) > py - CELL || (y * CELL) - CELL < py && (x * CELL) > px + CELL || (x * CELL) + CELL < px ) { return true; } } } } return false; ////////////////////////////////////////////////////////////////////////////////////////////// }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/29 06:43
退会済みユーザー
2019/08/12 08:11