- 環境
Windows10
visual studio 2019
DXライブラリ
#include "DxLib.h"
int Key[256]; // キーが押されているフレーム数を格納する
// キーの入力状態を更新する
int gpUpdateKey() {
char tmpKey[256]; // 現在のキーの入力状態を格納する
GetHitKeyStateAll(tmpKey); // 全てのキーの入力状態を得る
for (int i = 0; i < 256; i++) {
if (tmpKey[i] != 0) { // i番のキーコードに対応するキーが押されていたら
Key[i]++; // 加算
}
else { // 押されていなければ
Key[i] = 0; // 0にする
}
}
return 0;
}
// プログラムは WinMain から始まります
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
SetGraphMode(1600, 680, 32); // ウィンドウの大きさを指定
ChangeWindowMode(TRUE);
if (DxLib_Init() == -1) // DXライブラリ初期化処理
{
return -1; // エラーが起きたら直ちに終了
}
char key[256];
//1. 3x3マスの2次元配列
int idou[5][5] = {
{1,1,1,1,1 },
{1,0,0,0,1 },
{1,0,0,0,1 },
{1,0,0,0,1 },
{1,1,1,1,1 },
};
int playerX,playerY = (2,2); // 最初のキャラのX座playerXとY座標playerYである。配列の真ん中の0を最初の座標としたため(2,2)となる
int dx;//移動するキャラのx座標
int dy;//移動するキャラのy座標
int nx;//x移動後の新しいマスの座標
int ny;//y移動後の新しいマスの座標
//グラフィックハンドル格納用配列
int gh[12];
LoadDivGraph("charall.png", 12, 3, 4, 49, 66, gh);
//DrawGraph(playerX, playerY, gh[5], FALSE);// プレイヤーの画像を描画
SetDrawScreen(DX_SCREEN_BACK);
while (ScreenFlip() == 0 && ProcessMessage() == 0 && gpUpdateKey() == 0) {
int playerphoto;
// カーソルキーの右が押されている
if (Key[KEY_INPUT_RIGHT] == 1);
{
nx = dx + 1;
①if (idou[ny + 1][nx + 1]) {nx==0,}//紙を読む nx==0でidou[nx + 1]がidou[1]の時移動可能にして、その座標に移動する、nx==1でidou[nx + 1]がidou[2]の時移動不可能と
//①のidou[ny + 1][nx + 1]を利用してif文で書きたいのですが、idou[ny + 1][nx + 1]を単体でidou[ny + 1]として使うにはどうすればいいですか?
playerphoto = gh[9];
}
if (Key[KEY_INPUT_LEFT] == 1);
{
nx = dx - 1;
playerphoto = gh[2];
}
if (Key[KEY_INPUT_UP] == 1);
{
ny = dy + 1;
playerphoto = gh[4];
}
if (Key[KEY_INPUT_DOWN] == 1);
{
ny = dy - 1;
playerphoto = gh[3];
}
if (dx== 0 && dy == 0)
{
playerphoto = gh[7];
}
ScreenFlip();
// 画面をクリア
ClearDrawScreen();
DrawGraph(playerX, playerY, playerphoto, FALSE);
DxLib_End(); // DXライブラリ使用の終了処理
return 0; // ソフトの終了
}
その中に存在する。
if (Key[KEY_INPUT_RIGHT] == 1);
{
nx = dx + 1;
①if (idou[ny + 1][nx + 1]) {nx==0,}//紙を読む nx==0でidou[nx + 1]がidou[1]の時移動可能にして、その座標に移動する、nx==1でidou[nx + 1]がidou[2]の時移動不可能と
//①のidou[ny + 1][nx + 1]を利用してif文で書きたいのですが、idou[ny + 1][nx + 1]を単体でidou[ny + 1]として使うにはどうすればいいですか?
playerphoto = gh[9];