Q&A
tekiの初期位置の座標を(2,2)として描画しようとしたのですが、その座標にtekiが描画されません。
環境 Windows10、visual studio 2019、DXライブラリです。
以下はコードです。
#include <stdio.h> #include <stdlib.h> #include <time.h> #include "DxLib.h" int Key[256]; int gpUpdateKey() { char tmpKey[256]; GetHitKeyStateAll(tmpKey); for (int i = 0; i < 256; i++) (tmpKey[i] == 0) ? (Key[i] = 0) : Key[i]++;//キーのフレームの習得 return 0; } 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 box[4][7][2], teki[5][5][2];//tekiの移動できる範囲の配列を表す int WINAPI WinMain(HINSTANCE hi, HINSTANCE hp, LPSTR cl, int cs) { SetGraphMode(780, 680, 32); // ウィンドウの大きさを指定 ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用 if (DxLib_Init() == -1) return -1; // DXライブラリ初期化処理 SetDrawScreen(DX_SCREEN_BACK); // 裏画面を使用する設定 //int boxColor = GetColor(160, 64, 64);//ステージの色 int nx = 2, ny = 2; // tekiのxとyでの初期位置 int px = teki[ny][nx][0], py = teki[ny][nx][1]; // tekiのx、y、zでの初期位置 int gh[12]; //グラフィックハンドル格納用配列 // 5:正面、7:右向き、2:左向き、4:上向き、3:下向き、9:移動不可 LoadDivGraph("charall.png", 12, 3, 4, 49, 66, gh); //画像読み込み int playerphoto = gh[5]; while (ProcessMessage() == 0) { gpUpdateKey(); // キーの入力状態を取得 if (Key[KEY_INPUT_RIGHT] == 10) { // 右キーが押されている if (idou[nx + 1][ny] == 0) { // 移動先が空いていれば nx++; playerphoto = gh[7]; // 右向き } } if (Key[KEY_INPUT_LEFT] == 1) { if (idou[nx - 1][ny] == 0) { // 移動先が空いていれば nx--; playerphoto = gh[2]; // 左向き } } ClearDrawScreen(); // 裏画面をクリア DrawGraph(teki[ny][nx][0], teki[ny][nx][1], playerphoto, FALSE);//tekiの画像が描画される最初の位置 ScreenFlip(); // 裏画面を表画面に反映 } DxLib_End(); // DXライブラリ使用の終了処理 return 0; // ソフトの終了 }
以上のコードを説明しますと、idouと置いた配列
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 }, };
上でtekiの移動できる配列の範囲をteki[5][5][2]として、座標nx = 2, ny = 2を考慮して関数DrawGraphを用いて
関数LoadDivGraphtekiにより12分割した画像の一部であるtekiを[ny][nx][0], teki[ny][nx][1]の座標に描画しようとしたのですが、うまく機能しませんでした。
回答1件
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2019/08/27 19:09 編集
2019/08/27 22:53
2019/08/28 03:37 編集