Howdy, Stranger!

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

Categories

Roguelike will not redraw character

Antone333Antone333 Member Posts: 1

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 Member Posts: 1
    edited June 2014

    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.