My roguelike game (Yeah, I've heard how the console isn't good, and system() is evil, and conio.h is old. Several times, in fact. So I don't particularly need to hear it again. This is just a little learning project for me.) has hit another snag: I can't get the menu's to change when you press keys. Here's it so far:
#include <iostream>
#include <cstdlib>
#include <conio.h>
usingnamespace std;
//screenNum == 1 - Gamescreen
//screenNum == 2 - Main Menu
//screenNum == 0 - Escape Menu
int mainBreak = 0;
int pInput;
int screenNum = 1;
int movementTimer;
int posx;
int posy;
int menuCursor;
void mainMenuFn();
void escMenuFn();
void mapFn();
void playerInput();
void menuInput();
int main()
{
movementTimer = 0;
posx = 1;
posy = 1;
for (mainBreak == 0; mainBreak == 0;)
{
playerInput();
if (screenNum == 0)
{escMenuFn();}
if (screenNum == 1)
{mapFn();}
if (screenNum == 2)
{mainMenuFn();}
pInput = getch();
system("CLS");
}
return 0;
}
void mainMenuFn()
{}
void escMenuFn()
{
int loopBreak;
menuCursor = 1;
for (loopBreak == 0; loopBreak == 0;)
{
menuInput();
// Cursor Checks
if (menuCursor < 0)
{menuCursor = 1;}
if (menuCursor > 4)
{menuCursor = 4;}
// Cursor Actions
if (menuCursor == 1)
{cout << ">Return to Game\n";}
else
{cout << " Return to Game\n";}
if (menuCursor == 2)
{cout << ">Save Game\n";}
else
{cout << " Save Game\n";}
if (menuCursor == 3)
{cout << ">Options\n";}
else
{cout << " Options\n";}
if (menuCursor == 4)
{cout << ">Exit Game\n";}
else
{cout << " Exit Game\n";}
getch();
system("CLS");
}
}
void mapFn()
{
int mapArr[20][20];
int markerX = 0;
int markerY = 0;
int x = 0;
int y = 0;
int mapTracker = 0;
for (markerX = 0; markerX < 20; markerX++)
{
for (markerY = 0; markerY < 20; markerY++)
{
mapArr[markerX][markerY] = 2;
}
}
mapArr[posx][posy] = 1;
for (y = 0; y < 20; y++)
{
for (x = 0; x < 20; x++)
{
if (mapArr[x][y] == 2)
{
cout << ".";
mapTracker++;
}
if (mapArr[x][y] == 1)
{
cout << "@";
mapTracker++;
}
if (mapTracker == 20)
{
cout << "\n";
mapTracker = 0;
}
}
}
}
void playerInput()
{
// Q - NW
if (pInput == 113)
{
posx--;
posy--;
}
// W - N
if (pInput == 119)
{
posy--;
}
// E - NE
if (pInput == 101)
{
posx++;
posy--;
}
// A - W
if (pInput == 97)
{
posx--;
}
// S - Hold
if (pInput == 115)
{
}
// D - E
if (pInput == 100)
{
posx++;
}
// Z - SW
if (pInput == 122)
{
posx--;
posy++;
}
// X - S
if (pInput == 120)
{
//posx++;
posy++;
}
// C - SE
if (pInput == 99)
{
posx++;
posy++;
}
/* Sidebar
Keys */
// esc - Menu
if (pInput == 27)
{
screenNum = 0;
}
if (posx < 0)
{posx = 0;}
if (posy < 0)
{posy = 0;}
if (posx > 19)
{posx = 19;}
if (posy > 19)
{posy = 19;}
}
void menuInput()
{
// W - Up
if (pInput == 119)
{
menuCursor--;
}
// S - Down
if (pInput == 115)
{
menuCursor++;
}
}
What's really affecting it is in the functions escMenuFn() and menuInput(). I did a test to find out what number getch() returns for each key, so I know those are accurate. If you paste that code into a compiler (I use Code::Blocks, but I don't know if which one you use makes a difference) and compile it, QWEASDZXC control the character and esc pulls up the menu. W and S should control the menus cursor, but they don't. I'm not sure why. Can anybody tell me what I'm doing wrong?