Roguelike rpg

Key:
# = wall
@ = player
M = Mountain
W = Water
T = Tree
w = Random weapon
B = Bank
D = Door
A = Anvil
a = Ax
p = Pic Ax
f = Fishing Pole

and the problem
+ = next level

so now what i have is it draws the world but i want to be able to display a different map based on what the variable Level equals. but with having the char map1 in the if statement my code doesn't read it for some reason.

the character actions are done in a way like this

1
2
3
4
5
6
7
8
9
if(GetAsyncKeyState(VK_DOWN))
         {
              int y2 = y+1;
              
              //i need to change something with the
              if(map1[y2][x] == '+') //map1[][] here dont i?
              {
                   Level = Level + 1;
              }


and want to add
- = previous level

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
if(Level == 1)
         {

char map1[100][100] = 
     {
     "###############################################",
     "#@                                          WW#",
     "#            WWW       w                    WW#",
     "#            WWWW           a              WW #",
     "#           WWW                   #        WW #",
     "#                                # #      WW  #",
     "#                     T         #   #    WW   #",
     "#   T            f              #A B#   WW    #",
     "#      MM                       ##D##  WW     #",
     "#     MMMM               h              WW    #",
     "#                                  T    WW    #",
     "#                   T            T       WW   #",
     "#     T                       T       T  WW   #",
     "#               T              T T T    WW    #",
     "#                                  T  TWW T   #",
     "#  p            W                T     TWW    #",
     "#             WWWW             T    T T WWT   #",
     "#      T     WWWW            T     T WWWWWW   #",
     "# +           W               T   WWWWWWWWWWWW#",
     "#                                WWWWWWWWWWWWW#",
     "###############################################"
     };

              for(int display=0; display<26; display++)
              {
                   cout << map1[display] << endl;
              }
         }
closed account (2UD8vCM9)
Yeah man nobody is going to be able to tell you how to fix it if that's all the code you post.
if your on windows or ms-dos the
getch(); function is a better for keyboard input that GetAsyncKeyState
or if your on linux/unix/bsd
the ncurses libary have its own getch() function or
if you want to use standerd c and dont mind the key presses not being instantaneous then just use getchar();

also learn your ASCII values it helps in games like these
Last edited on

For starters, the map is 21 down by 48 across, and not 100 by 100. Anyway, just create a char map[21][48]; and depending on the level you just simply copy the contents of Map1, Map2 etc., that way you can modify the playing map without altering the original.

I.e. if you were playing from Map1 and you collected a key (as an example) you would then remove the key from the map.. what happens when the player wants to play again.. the lookup data was altered in the last game and the key would be missing from the map.

For example...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

#include <iostream>
using namespace std;

int main()
{

	// two example maps, these ideally should go in a header
	// out the way so that your not cluttering your source.

	char map1[21][48] =
	{
		"###############################################",
		"#@                                          WW#",
		"#            WWW       w                    WW#",
		"#            WWWW           a              WW #",
		"#           WWW                   #        WW #",
		"#                                # #      WW  #",
		"#                     T         #   #    WW   #",
		"#   T            f              #A B#   WW    #",
		"#      MM                       ##D##  WW     #",
		"#     MMMM               h              WW    #",
		"#                                  T    WW    #",
		"#                   T            T       WW   #",
		"#     T                       T       T  WW   #",
		"#               T              T T T    WW    #",
		"#                                  T  TWW T   #",
		"#  p            W                T     TWW    #",
		"#             WWWW             T    T T WWT   #",
		"#      T     WWWW            T     T WWWWWW   #",
		"# +           W               T   WWWWWWWWWWWW#",
		"#                                WWWWWWWWWWWWW#",
		"###############################################"
	};

	char map2[21][48] =
	{
		"###############################################",
		"#@     T                                    WW#",
		"#     TTT    WWW       w      WWWWW  WWWW   WW#",
		"#            WWWW           a              WW #",
		"#    WWWW   WWW                   #        WW #",
		"#        WWWWW                   # #      WW  #",
		"#                     T   WW    #   #    WW   #",
		"#   T            f         W    #A B#   WW    #",
		"#      MM                       ##D##  WW     #",
		"#     MMMM               h              WW    #",
		"#                                  T    WW    #",
		"#   T        WW     T     W      T       WW   #",
		"#   TTT                 W     T       T  WW   #",
		"#    T          T        W     T T T    WW    #",
		"#       WWWW           WWWW        T  TWW T   #",
		"#  p            W                T     TWW    #",
		"#             WWWW             T    T T WWT   #",
		"#      T     WWWW            T     T WWWWWW   #",
		"# +           W               T   WWWWWWWWWWWW#",
		"#                                WWWWWWWWWWWWW#",
		"###############################################"
	};

	// playing area map, this is where out map1..map2 lookup
	// data is copied to depending on what level we are on.
	// nb. try changing currentLevel to 2 and the map will 
	// change as expected.

	char map[21][48];	    // playing area
	int currentLevel = 1;   // what level we are on
	
	// what level are we playing...?
	switch (currentLevel)
	{
		case 1:
			memcpy(map, map1, sizeof(map1));  // copy map1 to map 
		break;
		case 2:
			memcpy(map, map2, sizeof(map2));  // copy map2 to map
		break;
	}

	// ok show map level
	for (int down = 0; down < 21; down++) {
		for (int across = 0; across < 48; across++)
			cout << map[down][across];
		cout << endl;
	}
	
	return 0;
}


Topic archived. No new replies allowed.