ok well
i have a problem and hoped someone could help me fix it.
when i go into a wall it gives me the error "wall blah blah" thats ok but you can press up into the wall it does not print the caracter but you can say go into wall and go left 3 spaces and press down you will come out of wall as if by magic.
basicly i need to stop my caracter entering the wall??
thanks kempy1000
Code:
//*****************************************************************
// THE QUEST
// Name: Map Loader
// Description: Loads Maps Into an Array From An Txt File
//*****************************************************************
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
#define VK_A 0x41
#define VK_B 0x42
#define VK_C 0x43
#define VK_D 0x44
#define VK_E 0x45
#define VK_F 0x46
#define VK_G 0x47
#define VK_H 0x48 // defines for Keys
#define VK_I 0x49
#define VK_J 0x4A
#define VK_K 0x4B
#define VK_L 0x4C
#define VK_M 0x4D
#define VK_N 0x4E
#define VK_O 0x4F
#define VK_P 0x50
#define VK_Q 0x51
#define VK_R 0x52
#define VK_S 0x53
#define VK_T 0x54
#define VK_U 0x55
#define VK_V 0x56
#define VK_W 0x57
#define VK_X 0x58
#define VK_Y 0x59
#define VK_Z 0x5A
#include <cstdio>
#include <iostream>
#include <windows.h>
using namespace std;
//************* MAP *************
const int GSIZE = 20;
//*******************************
//********** OBJECTS ************
char wall = 178;
int woods = 5;
//*******************************
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}//END
char map[GSIZE][GSIZE] =
{
178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,178,178,
178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,
};
void PrintMap()
{
for(int i = 0; i < GSIZE; i++)
{
for(int j = 0; j < GSIZE; j++)
{
cout << map[j][i];
}
cout << "\n";
}
}//END
void PrintPlayer(int player_x, int player_y, int move)
{
gotoxy(player_x, player_y);
cout << (char)2;
}//END
int CheckMove(int player_x, int player_y, int move)
{
if(map[player_x][player_y] == 0)
{
PrintPlayer(player_x, player_y, move);
}
else
{
gotoxy(25,5);
cout << "There Is A Wall In The Way\n";
}
}//END
void Move(int player_x, int player_y)
{
bool endfunction = false;
do{
int move = 0;
bool endloop = false;
do{
if (KEY_DOWN(VK_UP)) // If key pressed is the UP arrow
{
endloop = true;
player_y--;
move = 1;
Sleep(200);
}
else if (KEY_DOWN(VK_DOWN)) // If key pressed is the Down arrow
{
endloop = true;
player_y++;
move = 2;
Sleep(200);
}
else if (KEY_DOWN(VK_LEFT)) // If key pressed is the LEFT arrow
{
endloop = true;
player_x--;
move = 3;
Sleep(200);
}
else if (KEY_DOWN(VK_RIGHT)) // If key pressed is the RIGHT arrow
{
endloop = true;
player_x++;
move = 4;
Sleep(200);
}
else if (KEY_DOWN(VK_RETURN)) // If key pressed is the RETURN key (Enter)
{
endloop = true;
endfunction = true;
Sleep(200);
}
}while(!endloop);
CheckMove(player_x, player_y, move);
}while(!endfunction);
}//END
int main()
{
int player_x = 5;
int player_y = 5;
int move = 0;
//LoadMap();
PrintMap();
PrintPlayer(player_x, player_y, move);
Move(player_x, player_y);
}//END