dxライブラリでRPGを作ろうとしているところなのですが、何故か常に触れているという処理になってしまいます。
下のコードをどのようにすればよろしいでしょうか?
mapchip.h------------------------------
#pragma once
class mapchip
{
public:
int mapx;
int mapy;
int block[2];
int map[15][20];
int atari[15][20];
int mapgraph();
mapchip();
~mapchip();
};
mapchip.cpp--------------------
#include "mapchip.h"
#include "DxLib.h"
int mapchip::mapgraph() {
LoadDivGraph("画像/test.png", 2, 2, 1, 32, 32, block);
int map[15][20] = {
{ 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,1,1,1,1 },
{ 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1 },
{ 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1 },
{ 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1 },
{ 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1 },
{ 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1 },
{ 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1 },
{ 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1 },
{ 1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1 },
{ 1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1 },
{ 1,1,1,1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1 },
{ 1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,0,0,1,1,1 },
{ 1,1,1,1,0,0,0,0,0,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 },
};
int atari[15][20] = {
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0 },
{ 0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0 },
{ 0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0 },
{ 0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0 },
{ 0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0 },
{ 0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0 },
{ 0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0 },
{ 0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0 },
{ 0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0 },
{ 0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0 },
{ 0,0,0,0,255,255,255,255,255,255,255,0,0,0,255,255,255,0,0,0 },
{ 0,0,0,0,255,255,255,255,255,255,0,0,0,0,0,255,255,0,0,0 },
{ 0,0,0,0,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
};
for (int mapy = 0; mapy < 15; mapy++) {
for (int mapx = 0; mapx < 20; mapx++) {
DrawGraph(mapx * 32, mapy * 32, block[map[mapy][mapx]], TRUE);
}
}
return 0;
}
mapchip::mapchip()
{
}
mapchip::~mapchip()
{
}
character.h----------------------
#pragma once
#include "mapchip.h"
class character :
public mapchip
{
public:
int px;
int py;
int p;
int muki;
int wsp;
int flag;
int anim[16];
int reset();
int idou();
int tikei();
int animation();
int ALL();
character();
~character();
};
character.cpp-----------------------
#include "character.h"
#include "DxLib.h"
int character::reset() {
px = 160;
py = 320;
wsp = 4;
muki = 0;
flag = 1;
LoadDivGraph("画像/キャラクタ1.png", 16, 4, 4, 32, 32, anim);
return 0;
}
int character::tikei() {
if (muki == 0) {
if (atari[(py) / 32 - 1][(px) / 32] == 0) {
return 1;
}
}
if (muki == 1) {
if (atari[(py) / 32][(px) / 32 - 1] == 0) {
return 1;
}
}
if (muki == 2) {
if (atari[(py) / 32 + 1][(px) / 32] == 0) {
return 1;
}
}
if (muki == 3) {
if (atari[(py) / 32][(px) / 32 + 1] == 0) {
return 1;
}
}
return 0;
}
int character::idou() {
if (px % 32 == 0 && py % 32 == 0) {
flag = 1;
if (CheckHitKey(KEY_INPUT_UP) == 1) {
muki = 0;
}
if (CheckHitKey(KEY_INPUT_LEFT) == 1) {
muki = 1;
}
if (CheckHitKey(KEY_INPUT_DOWN) == 1) {
muki = 2;
}
if (CheckHitKey(KEY_INPUT_RIGHT) == 1) {
muki = 3;
}
if (CheckHitKey(KEY_INPUT_UP) == 0 && CheckHitKey(KEY_INPUT_LEFT) == 0 && CheckHitKey(KEY_INPUT_DOWN) == 0 && CheckHitKey(KEY_INPUT_RIGHT) == 0) {
flag = 0;
}
if (flag == 1) {
if (tikei()==1) {
flag = 0;
}
}
}
if (flag == 1) {
if (muki == 0) {
py--;
}
if (muki == 1) {
px--;
}
if (muki == 2) {
py++;
}
if (muki == 3) {
px++;
}
}
if (px % 32 != 0) {
px++;
}
if (py % 32 != 0) {
py++;
}
return 0;
}
int character::animation() {
p = anim[(px % 32 + py % 32) / 8 + muki * 4];
DrawBox(px, py, px + 32, py + 32, GetColor(0, 255, 0), TRUE);
DrawFormatString(0, 0, GetColor(0, 255, 0), "%d,%d", py / 32, px / 32);
DrawFormatString(0, 15, GetColor(0, 255, 0), "%d", tikei());
DrawFormatString(0, 30, GetColor(0, 255, 0), "%d", muki);
DrawGraph(px, py, p, TRUE);
return 0;
}
int character::ALL() {
tikei();
idou();
animation();
return 0;
}
character::character()
{
}
character::~character()
{
}
main.cpp------------------------------
#include "DxLib.h"
#include "mapchip.h"
#include "character.h"
mapchip map_1;
character chara_1;
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK); //ウィンドウモード変更と初期化と裏画面設定
chara_1.reset();
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0) {
map_1.mapgraph();
chara_1.ALL();
}
DxLib_End(); // DXライブラリ終了処理
return 0;
}