You are viewing our Forum Archives. To view or take place in current topics click here.
Array dimensions and the sort
Posted:
Array dimensions and the sortPosted:
Status: Offline
Joined: Dec 23, 201013Year Member
Posts: 2,446
Reputation Power: 80
So I am "attempting" at making a console side scroller in Cpp and when using my array (the game map) it seems to think it's GameMap[y][x] shouldn't it be [x][y]?
Tl;dr array is reading dimensions backwards..
NOTE: code is probably really sloppy and broken, bear with me
Tl;dr array is reading dimensions backwards..
NOTE: code is probably really sloppy and broken, bear with me
// What am I doing?
// TODO:
/**
Add movement
Add jumping
Add gravity
Add Platforms
*/
char GameMap[250][15] = {
"##########################################################################################################################################################################################################################################################",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# @ #",
"##########################################################################################################################################################################################################################################################" };
bool quit = false;
int GameSpeed = 200;
int playerX = 5, playerY = 14;
int display(int playerX)
{
for (int x = playerX - 4; x < 24; x++)
{
std::cout << GameMap[x] << std::endl;
}
}
int getPlayerUpdates(int playerX, int playerY)
{
// Controls
if ((GetAsyncKeyState(VK_UP) != 0) || (GetAsyncKeyState('W') != 0))
{
switch (GameMap[x][y-1]
{
case ' ': // Checks if space is blank.
{
Map[x][y] = ' ';
playerY -= 1;
} break;
}
}
if ((GetAsyncKeyState(VK_DOWN) != 0) || (GetAsyncKeyState('S') != 0))
{
switch (GameMap[x][y-1]
{
case ' ':
{
Map[x][y] = ' ';
playerY += 1;
} break;
}
}
if ((GetAsyncKeyState(VK_LEFT) != 0) || (GetAsyncKeyState('A') != 0))
{
switch (GameMap[x][y-1]
{
case ' ':
{
return playerX--;
} break;
}
}
if ((GetAsyncKeyState(VK_RIGHT) != 0) || (GetAsyncKeyState('D') != 0))
{
switch (GameMap[x][y-1]
{
case ' ':
{
return playerX++;
} break;
}
}
if (GetAsyncKeyState(VK_ESCAPE) != 0)
quit = true;
}
int main()
{
while (!quit)
{
system("CLS");
display(playerX);
for (int x = 0; x < 250; x++)
{
for (int y = 0; y < 15; y++)
{
switch (GameMap[x][y])
{
case '@':
{
getCharUpdates(int playerX, int playerY);
} break;
case '#':
{
// Do something with the walls maybe?
// Check if they aren't the border and have them move or some junk...
/*
if
*/
} break;
}
}
}
Sleep(GameSpeed);
}
return 0;
}
You are viewing our Forum Archives. To view or take place in current topics click here.