マップ移動は画面の端っこまで行ったらキャラクターは来た方向の真逆にいくようにして、その処理と同時に背景のマップを差し替えるという形にしているのですがそこで質問です。
背景を差し替える所まではいいのですが、差し替えたあと 1の部分を壁があるように当たり判定を設定しているのですが、なぜか一番最初のマップの処理が残ったままで何もないのに壁にあたってしまうという現象が起きています(T_T)
ソースコードは以下の通りなのでわかる方はなにがどう処理されて最初のマップの処理が残ってしまているのか教えてもらいたいです。
#include "DxLib.h"
#define WD 400
#define SCREEN_X (640)
#define SCREEN_Y (480)
#define MAPSIZE_X (32*25) //横マップサイズの長さ
#define MAPSIZE_Y (480) //縦マップサイズの長さ
#define CHIPSIZE (32) //一つのブロックサイズ
#define MAP_WIDTH (MAPSIZE_X/CHIPSIZE) //横のブロックの数
#define MAP_HEIGHT (MAPSIZE_Y/CHIPSIZE) //縦のブロックの数
#define MOVE_FRAME 32 // 移動にかけるフレーム数
#define MAP_TATE 45
#define MAP_YOKO 60
typedef struct{
int x,y,img,muki,walking_flag;
}ch_t;
typedef struct{
int a,b,img2,muki2,walking_flag2;
int count;
}cd_t;
int image[16];
int image2[16];
int image3[7];
int image4;
int i,j,k;
int hp=1000;
int hp_max=1000;
int green,white,black;
int count=2;
int x=0;
int y=0;
int w=0;
int map_now_x=0,map_now_y=0;
char Key[256];
ch_t ch;
cd_t cd;
void map();
void player();
void teki();
int hantei[MAP_TATE][MAP_YOKO] = {
{ 1,1,1,1,1,1,1,1,1,1,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,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{ 1,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{ 1,1,1,1,1,1,1,1,1,1,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,0,1,1,1,1,1,1,1,1,1 },
};
int IsAbleToGo(int x,int y,int muki){//進めるかを判定する
if(muki==0)//上向きなら
if(hantei[y/32-1][x/32]==1||hantei[y/32-1][x/32]==2)
return 1;//エラー
if(muki==1)//左向きなら
if(hantei[y/32][x/32-1]==1||hantei[y/32][x/32-1]==2)
return 1;
if(muki==2)//下向きなら
if(hantei[y/32+1][x/32]==1||hantei[y/32+1][x/32]==2)
return 1;
if(muki==3)//右向きなら
if(hantei[y/32][x/32+1]==1||hantei[y/32][x/32+1]==2)
return 1;
return 0;//正常
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow )
{if( ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1 ) return -1; //ウィンドウ化と初期化処理
ch.x =320;
ch.y =160;
cd.a =160;
cd.b =192;
ch.walking_flag=0;
cd.walking_flag2=0;
ch.muki=3;
cd.muki2=3;
cd.count=GetRand(30);
green=GetColor(0,255,0);
white=GetColor(255,255,255);
black=GetColor(0,0,0);
PlaySoundFile("music/Skyrim.mp3",DX_PLAYTYPE_LOOP);
SetDrawScreen(DX_SCREEN_BACK); //描画先を裏画面に設定
LoadDivGraph( "pic/char.png" , 16 , 4 , 4 , 32 , 32 , image ) ;//画像を分割してimage配列に保存
LoadDivGraph( "pic/char1.png" , 16 , 4 , 4 , 32 , 32 , image2 ) ;//画像を分割してimage配列に保存
LoadDivGraph( "pic/TileA.png" , 7 , 7 , 1 , 32 , 32 , image3 ) ;
image4=LoadGraph("pic/mainmap1.png");
while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){
//↑メッセージ処理 ↑画面をクリア ↑キーボード入力状態取得 ↑ESCが押されると終了
map();
player();
teki();
DrawFormatString( 0,0,GetColor(16,16,16),"MapDrawPoint(%d,%d)", ch.x,ch.y );
ScreenFlip();
}
DxLib_End();
return 0;
}
void map(){
/*壁を描画*/
for(i=0;i<MAP_TATE;i++){
for(j=0;j<MAP_YOKO;j++){
if(hantei[i+15*map_now_y][j+20*map_now_x]==0)
DrawGraph(j*32,i*32,image3[0],TRUE);
if(hantei[i+15*map_now_y][j+20*map_now_x]==1)
DrawGraph(j*32,i*32,image3[1],TRUE);
if(hantei[i+15*map_now_y][j+20*map_now_x]==2)
DrawGraph(j*32,i*32,image3[2],TRUE);
if(hantei[i+15*map_now_y][j+20*map_now_x]==3)
DrawGraph(j*32,i*32,image3[3],TRUE);
if(hantei[i+15*map_now_y][j+20*map_now_x]==4)
DrawGraph(j*32,i*32,image3[4],TRUE);
if(hantei[i+15*map_now_y][j+20*map_now_x]==5)
DrawGraph(j*32,i*32,image3[5],TRUE);
if(hantei[i+15*map_now_y][j+20*map_now_x]==6)
DrawGraph(j*32,i*32,image3[6],TRUE);
}
}
switch(w){
case 0:
if(ch.x<0)
ch.x=0;
if(ch.y<0)
ch.y=0;
break;
case 1:
if(ch.y<0)
ch.y=0;
break;
case 2:
if(ch.x>608)
ch.x=608;
if(ch.y<0)
ch.y=0;
break;
case 3:
if(ch.x<0)
ch.x=0;
break;
case 5:
if(ch.x>608)
ch.x=608;
break;
case 6:
if(ch.x<0)
ch.x=0;
if(ch.y>448)
ch.y=448;
break;
case 7:
if(ch.y>448)
ch.y=448;
break;
case 8:
if(ch.x>608)
ch.x=608;
if(ch.y>448)
ch.y=448;
break;
}
}
void player(){
if(ch.x>624){
ch.x=-16;
w++;
map_now_x++;
}
if(ch.x<-16){
ch.x=624;
w--;
map_now_x--;
}
if(ch.y>464){
ch.y=-16;
w+=3;
map_now_y++;
}
if(ch.y<-16){
ch.y=464;
w-=3;
map_now_y--;
}
if(ch.x%32==0 && ch.y%32==0){ //座標が32で割り切れたら入力可能
ch.walking_flag=1; //歩くフラグを立てる。
if ( Key[ KEY_INPUT_UP ] == 1 ) //上ボタンが押されたら
ch.muki=0; //上向きフラグを立てる
else if( Key[ KEY_INPUT_LEFT ] == 1 ) //左ボタンが押されたら
ch.muki=1; //左向きフラグを立てる
else if( Key[ KEY_INPUT_DOWN ] == 1 ) //下ボタンが押されたら
ch.muki=2; //下向きフラグを立てる
else if( Key[ KEY_INPUT_RIGHT] == 1 ) //右ボタンが押されたら
ch.muki=3; //右向きフラグを立てる
else //何のボタンも押されてなかったら
ch.walking_flag=0; //歩かないフラグを立てる
if(ch.walking_flag==1) //もし歩くなら
if(IsAbleToGo(ch.x,ch.y,ch.muki)==1)//行き先が歩けないなら
ch.walking_flag=0; //歩かないフラグを立てる。
/*if(hantei[ch.y/32][ch.x/32]==1){
DrawGraph(0,0,image3[5],TRUE);
DrawFormatString(420,10,black,"%d受けた!",GetRand(50)+50);
DrawBox(10,10,10+WD,30,GetColor(0,255,255),FALSE);//メーターの枠を描画
DrawBox(10,10,10+WD*hp/hp_max,30,GetColor(0,255,255),TRUE );//メーターの中身を描画
if(hp>0) hp--;
count++;
if(count>1)
DrawBox(0,0,640,480,white,TRUE);
if(count>3)
count=0;
}*/
}
if(ch.walking_flag==1){ //歩くフラグが立っていたら
if (ch.muki==0) //上向きならch.y座標を減らす
ch.y-=2;
else if(ch.muki==1) //左向きならch.x座標を減らす
ch.x-=2;
else if(ch.muki==2) //下向きならch.y座標を増やす
ch.y+=2;
else if(ch.muki==3) //右向きならch.x座標を増やす
ch.x+=2;
}
ch.img=image[(ch.x%32+ch.y%32)/8 + ch.muki*4]; //画像をセット
DrawGraph(ch.x,ch.y,ch.img,TRUE); //画像を描写
}
void teki(){
if(cd.a%32==0 && cd.b%32==0 && cd.count==0){
cd.muki2 = GetRand( 3 );
}else{
cd.walking_flag2=1;
}
if(cd.walking_flag2==1){ //歩くフラグが立っていたら
if (cd.muki2==0) //上向きならch.y座標を減らす
cd.b-=2;
else if(cd.muki2==1) //左向きならch.x座標を減らす
cd.a-=2;
else if(cd.muki2==2) //下向きならch.y座標を増やす
cd.b+=2;
else if(cd.muki2==3) //右向きならch.x座標を増やす
cd.a+=2;
if ( cd.a%32==0 && cd.b%32==0 ) {
cd.walking_flag2=0;
cd.count = GetRand(30);
}
}
if ( cd.count )
cd.count--;
cd.img2=image2[(cd.a%32+cd.b%32)/8+ cd.muki2*4];
DrawGraph(cd.a,cd.b,cd.img2,TRUE);
}