#include <GConsoleLib.h>
#include <stdio.h>
//マップデータ
#define MAXWIDTH 10
#define MAXHEIGHT 7
int g_mapdata[MAXHEIGHT][MAXWIDTH] = {
// 0 1 2 3 4 5 6 7 8 9
{ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1},//0
{ 1, 0, 0, 1, 2, 0, 0, 1, 3, 1},//1
{ 1, 1, 0, 1, 1, 1, 0, 1, 0, 1},//2
{ 1, 0, 0, 0, 0, 0, 0, 1, 0, 1},//3
{ 1, 0, 1, 1, 1, 1, 1, 1, 0, 1},//4
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1},//5
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},//6
};
//マップの部品の画像
char *g_images[] = {
"C:\\GConsole追加ファイル\\sampleimg\\chap5-1-field.png",
"C:\\GConsole追加ファイル\\sampleimg\\chap5-1-wall.png",
"C:\\GConsole追加ファイル\\sampleimg\\chap5-1-goal.png",
"C:\\GConsole追加ファイル\\sampleimg\\chap5-1-key.png",
"C:\\GConsole追加ファイル\\sampleimg\\chap5-1-man.png"
};
//主人公の位置
int g_x = 1, g_y = 0;
int g_keyflag = 0; //鍵を拾ったフラグ
//関数プロトタイプ宣言
void DrawMap();
void RedrawMap(int, int, int, int);
int main(){
gcls();
gfront();
DrawMap(); //マップ全体を表示
while(1){
glocate(0,19); gcolor(128,0,0);
gprintf("コマンド(左A、上W、下S、右D)? ");
glocate(32,19);
char ch = ggetchar();
int newx=g_x, newy=g_y;
switch(ch){
case 'W':
case 'w':
newy--;
break;
case 'S':
case 's':
newy++;
break;
case 'A':
case 'a':
newx--;
break;
case 'D':
case 'd':
newx++;
break;
}
//移動チェック
if(newx >=0 && newx < MAXWIDTH && newy >=0 && newy < MAXHEIGHT){
//壁かどうかチェック
if(g_mapdata[newy][newx]!=1){
//ゴールと鍵の処理
switch(g_mapdata[new_y][new_x]){
case 3://鍵
g_keyflag = 1; //鍵フラグオン
g_mapdata[new_x][new_y] = 0; //鍵を消す
break;
case 2: //ゴール
break;
}
RedrawMap(g_x, g_y, newx, newy);
g_x = newx;
g_y = newy;
}
}
}
}
//マップ再描画
void RedrawMap(int oldx, int oldy, int newx, int newy){
gimage(g_images[g_mapdata[oldy][oldx]], oldx*62, oldy*62);
gimage(g_images[4], newx*62, newy*62);
}
//マップ表示
void DrawMap(){
for(int y=0; y<MAXHEIGHT; y++){
for(int x=0; x<MAXWIDTH; x++){
if(x == g_x && y == g_y){
//主人公表示
gimage(g_images[4], g_x*62, g_y*62);
}else{
gimage(g_images[g_mapdata[y][x]], x*62, y*62);
}
}
}
}
(70) : error C2065: 'new_x' : 定義されていない識別子です。
(73) : error C2065: 'new_x' : 定義されていない識別子です。
(73) : error C2065: 'new_y' : 定義されていない識別子です。
これらのエラーがでます。
誰かわかる人がいましたら返答お願いします。