#1
by Ouxiy » 4年前
コード:
#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] = {
{00,10,20,30,40 },
{01,11,21,31,41 },
{02,12,22,32,42 },
{03,13,23,33,43 },
{04,14,24,34,44 },
};
int playerX = 300; // キャラのX座標
int playerY = 300; // キャラのY座表
//グラフィックハンドル格納用配列
int gh[12];
LoadDivGraph("charall.png", 12, 3, 4, 49, 66, gh);
//DrawGraph(playerX, playerY, gh[5], FALSE);// プレイヤーの画像を描画
while (ScreenFlip() == 0 && ProcessMessage() == 0 && gpUpdateKey() == 0) {
int 加算 = 40;
int b = 40;
// カーソルキーの右が押されている
if (Key[KEY_INPUT_RIGHT] == 1) {
//for (int i = 0; i < 3; i++) {
playerX = playerX + 加算;
// 画面に出力
ScreenFlip();
// 画面をクリア
ClearDrawScreen();
// プレイヤーの画像を描画
DrawGraph(playerX, playerY, gh[6], FALSE);//DrawGraphにより何も押されていない静止時は12分割された配列の一つである、gh[6]を描画できる関数である。
}
else { while (DrawGraph(playerX, playerY, gh[5], FALSE)); }//右を押されて加算されていく中で、もし加算されない間はキャラの描画はgh[8]にする。elseを付けることで条件を否定できる。
if (Key[KEY_INPUT_UP] == 1) {
playerY = playerY - b; // プレイヤーのY座標を加算
// 画面に出力
ScreenFlip();
// 画面をクリア
ClearDrawScreen();
// プレイヤーの画像を描画
DrawGraph(playerX, playerY, gh[8], FALSE);
}
if (Key[KEY_INPUT_LEFT] == 1) {
playerX = playerX - 加算; // プレイヤーのX座標を加算
// 画面をクリア
ClearDrawScreen();
// プレイヤーの画像を描画
DrawGraph(playerX, playerY, gh[10], FALSE);
}
if (Key[KEY_INPUT_DOWN] == 1) {
playerY = playerY + b; // プレイヤーのY座標を加算
// 画面に出力
ScreenFlip();
// 画面をクリア
ClearDrawScreen();
// プレイヤーの画像を描画
DrawGraph(playerX, playerY, gh[2], FALSE);
}
}
DxLib_End(); // DXライブラリ使用の終了処理
return 0; // ソフトの終了
}
について、
コード:
int idou[5][5] = {
{00,10,20,30,40 },
{01,11,21,31,41 },
{02,12,22,32,42 },
{03,13,23,33,43 },
{04,14,24,34,44 },
};
の配列の座標{00,10,20,30,40 },01,41,02,42,03,43,{04,14,24,34,44 },は壁として定義して、
たとえば 座標32がキャラのいる座標としてidou[y+1][x+1]により、その24から右に+1移動しすると42(壁)となり移動できませんが、前もって配列の座標42は移動できないと定義して移動できないようにすることは出来なんでしょうか?
できれば、配列の座標{00,10,20,30,40 },01,41,02,42,03,43,{04,14,24,34,44 },は壁と前もって定義して、idou[y+1][x+1]により、前もって定義した壁には移動できないとしたいのですが、iキャラ移動に使うdou[y+1][x+1]は移動できるか否かを判断できないため、使えないと言われました。しかし、移動できない座標を前もって定義すれば3*3マスの座標内でdou[y+1][x+1]を使って移動できるのではないかと未だに思っています。
どうか私の勘違いや間違いがなんなのか教えてください。
どうかよろしくお願いいたします。
[code]#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] = {
{00,10,20,30,40 },
{01,11,21,31,41 },
{02,12,22,32,42 },
{03,13,23,33,43 },
{04,14,24,34,44 },
};
int playerX = 300; // キャラのX座標
int playerY = 300; // キャラのY座表
//グラフィックハンドル格納用配列
int gh[12];
LoadDivGraph("charall.png", 12, 3, 4, 49, 66, gh);
//DrawGraph(playerX, playerY, gh[5], FALSE);// プレイヤーの画像を描画
while (ScreenFlip() == 0 && ProcessMessage() == 0 && gpUpdateKey() == 0) {
int 加算 = 40;
int b = 40;
// カーソルキーの右が押されている
if (Key[KEY_INPUT_RIGHT] == 1) {
//for (int i = 0; i < 3; i++) {
playerX = playerX + 加算;
// 画面に出力
ScreenFlip();
// 画面をクリア
ClearDrawScreen();
// プレイヤーの画像を描画
DrawGraph(playerX, playerY, gh[6], FALSE);//DrawGraphにより何も押されていない静止時は12分割された配列の一つである、gh[6]を描画できる関数である。
}
else { while (DrawGraph(playerX, playerY, gh[5], FALSE)); }//右を押されて加算されていく中で、もし加算されない間はキャラの描画はgh[8]にする。elseを付けることで条件を否定できる。
if (Key[KEY_INPUT_UP] == 1) {
playerY = playerY - b; // プレイヤーのY座標を加算
// 画面に出力
ScreenFlip();
// 画面をクリア
ClearDrawScreen();
// プレイヤーの画像を描画
DrawGraph(playerX, playerY, gh[8], FALSE);
}
if (Key[KEY_INPUT_LEFT] == 1) {
playerX = playerX - 加算; // プレイヤーのX座標を加算
// 画面をクリア
ClearDrawScreen();
// プレイヤーの画像を描画
DrawGraph(playerX, playerY, gh[10], FALSE);
}
if (Key[KEY_INPUT_DOWN] == 1) {
playerY = playerY + b; // プレイヤーのY座標を加算
// 画面に出力
ScreenFlip();
// 画面をクリア
ClearDrawScreen();
// プレイヤーの画像を描画
DrawGraph(playerX, playerY, gh[2], FALSE);
}
}
DxLib_End(); // DXライブラリ使用の終了処理
return 0; // ソフトの終了
}[/code]
について、[code]int idou[5][5] = {
{00,10,20,30,40 },
{01,11,21,31,41 },
{02,12,22,32,42 },
{03,13,23,33,43 },
{04,14,24,34,44 },
};[/code]
の配列の座標{00,10,20,30,40 },01,41,02,42,03,43,{04,14,24,34,44 },は壁として定義して、
たとえば 座標32がキャラのいる座標としてidou[y+1][x+1]により、その24から右に+1移動しすると42(壁)となり移動できませんが、前もって配列の座標42は移動できないと定義して移動できないようにすることは出来なんでしょうか?
できれば、配列の座標{00,10,20,30,40 },01,41,02,42,03,43,{04,14,24,34,44 },は壁と前もって定義して、idou[y+1][x+1]により、前もって定義した壁には移動できないとしたいのですが、iキャラ移動に使うdou[y+1][x+1]は移動できるか否かを判断できないため、使えないと言われました。しかし、移動できない座標を前もって定義すれば3*3マスの座標内でdou[y+1][x+1]を使って移動できるのではないかと未だに思っています。
どうか私の勘違いや間違いがなんなのか教えてください。
どうかよろしくお願いいたします。