Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Roguelike will not redraw character

Antone333Antone333 Posts: 1Member

if you compile this program and test out the arrow keys it appears like nothing is happening. but pay attention to how many presses you make and move the character towards a + or a -. when you touch one then it takes you to the next map. but the character does not get shown moving.

please help me understand what i am doing wrong.

If i do a similar code except have char Map[100][100] = (And then put the map here) and keep it out of a function and leave out char Level then it works ok just i cant draw a new map with it. or at least dont know how without rewriting the entire code for the new map

`

include

include "windows.h"

using namespace std;

int World1();
int World2();
int World3();

char Map[100][100];
char Level[100][100];

int x = 1;
int y = 1;

int Level_Sel = 2;

int Enter_Level = 0;

bool Game_Running = true;

int main()
{
while(Game_Running)
{
system("cls");

    if(Level_Sel == 1)
{
World1();
}
else if(Level_Sel == 2)
{
World2();
}
else if(Level_Sel == 3)
{
World3();
}

if(GetAsyncKeyState(VK_DOWN))
{
int y2 = y+1;

if(Map[y2][x] == '+')
{
Level_Sel = Level_Sel + 1;
Enter_Level = 0;
}
else if(Map[y2][x] == '-')
{
Level_Sel = Level_Sel - 1;
Enter_Level = 0;
}
else if(Map[y2][x] == ' ')
{
Map[y][x] = ' ';
y++;
Map[y][x] = '@';
}
}

if(GetAsyncKeyState(VK_UP))
{
int y2 = y-1;

if(Map[y2][x] == '+')
{
Level_Sel = Level_Sel + 1;
Enter_Level = 0;
}
else if(Map[y2][x] == '-')
{
Level_Sel = Level_Sel - 1;
Enter_Level = 0;
}
else if(Map[y2][x] == ' ')
{
Map[y][x] = ' ';
y--;
Map[y][x] = '@';
}
}
if(GetAsyncKeyState(VK_RIGHT))
{
int x2 = x+1;

if(Map[y][x2] == '+')
{
Level_Sel = Level_Sel + 1;
Enter_Level = 0;
}
else if(Map[y][x2] == '-')
{
Level_Sel = Level_Sel - 1;
Enter_Level = 0;
}
else if(Map[y][x2] == ' ')
{
Map[y][x] = ' ';
x++;
Map[y][x] = '@';
}
}

if(GetAsyncKeyState(VK_LEFT))
{
int x2 = x-1;

if(Map[y][x2] == '+')
{
Level_Sel = Level_Sel + 1;
Enter_Level = 0;
}
else if(Map[y][x2] == '-')
{
Level_Sel = Level_Sel - 1;
Enter_Level = 0;
}
else if(Map[y][x2] == ' ')
{
Map[y][x] = ' ';
x--;
Map[y][x] = '@';
}
}
}

system("PAUSE");
return 0;

}

int World1()
{
if(Enter_Level == 0)
{
x = 1;
y = 1;
Enter_Level = 1;
}

char Level[100][100] =
{
"##########",
"#@ #",
"# #",
"# #",
"# + #",
"##########"
};
memcpy(Map, Level, sizeof(Level));

for(int display=0; display<10; display++)
{
cout << Map[display] << endl;
}

system("pause>nul");

}

int World2()
{
if(Enter_Level == 0)
{
x = 1;
y = 1;
Enter_Level = 1;
}

char Level[100][100] =
{
"##########",
"#@ #",
"# #",
"# #",
"# - + #",
"##########"
};
memcpy(Map, Level, sizeof(Level));

for(int display=0; display<10; display++)
{
cout << Map[display] << endl;
}

system("pause>nul");

}

int World3()
{
if(Enter_Level == 0)
{
x = 1;
y = 1;
Enter_Level = 1;
}

char Level[100][100] =
{
"##########",
"#@ #",
"# #",
"# #",
"# - #",
"##########"
};
memcpy(Map, Level, sizeof(Level));

for(int display=0; display<10; display++)
{
cout << Map[display] << endl;
}

system("pause>nul");

}
`

Comments

  • Antone333Antone333 Posts: 1Member
    edited June 3

    ok the top part is supposed to be as follows

    include "iostream"

    include "windows.h"

    //why wont it let me put iostream in <>

    using namespace std;

    int World1();
    int World2();
    int World3();

    char Map[100][100];
    char Level[100][100];

    int x = 1;
    int y = 1;

    int Level_Sel = 2;

    int Enter_Level = 0;

    bool Game_Running = true;

Sign In or Register to comment.