one array equal another (rpg game map)

so i am working on a roguelike rpg game and i have all the "stuff" in the game figured out like fishing fighting what ever. all except for moving from map to map.

so what i want is for
+ to go up in the levels
and
- to go down in the levels

basically what i was trying to do is this:


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
90
91
92
#include <iostream>

using namespace std;

int level = 2;

char Level_Map;

void Level1();
void Level2();
void Level3();

char map[100][100] = Level_Map[100][100];

int main()
{
if(Level == 1) //and this is where the char map should be made to equal the map shown in Level1()
{
Level1();
for(int display=0; display<26; display++)
{
cout << map[display] << endl;
}
}
if(Level == 2) //and this is where the char map should be made to equal the map shown in Level2()
{
Level2();
for(int display=0; display<26; display++)
{
cout << map[display] << endl;
}
}
if(Level == 3) //and this is where the char map should be made to equal the map shown in Level3()
{
Level3();
for(int display=0; display<26; display++)
{
cout << map[display] << endl;
}
}

//and then the movement of the character and colision test
if(GetAsyncKeyState(VK_DOWN)) // or up or left or right but you get it
{
int y2 = y+1;
 
if(map[y2][x] == '+') // and if '-' then Level - 1;
{
Level = Level + 1;
}

}

void Level1()
{
Level[100][100] =
{
"########",
"#      #",
"# @    #",
"#      #",
"#      #",
"#    + #",
"########"
};
}
void Level2()
{
Level[100][100] =
{
"########",
"#      #",
"# @    #",
"#      #",
"#      #",
"# -  + #",
"########"
};
}
void Level3()
{
Level[100][100] =
{
"########",
"#      #",
"# @    #",
"#      #",
"#      #",
"# -    #",
"########"
};
}


Thank you so much for all the help! hope it makes sense
You're either not posting code, or this doesn't compile.
I don't know how you expect us to help you when you're only posting part of your code.

If this is all of your code...

Level1() Level2() and Level3() are accessing an array that was never declared.

You should really try to think through the logic here or at least get more practice before attempting something like this. It can be harder to make a game through the console window than it would be to just download the DirectX SDK or SFML and make a game that way( and it would have graphics too that way ).

Firstly
char Level_Map; // <-- this is a variable that contains a single char

You cannot then do this

char map[100][100] = Level_Map[100][100];

Read up more on arrays.

Secondly
if(Level == 1) // <-- this and all versions of this are invalid

Why? Well because the level variable you declared does not contain a capital L.

1
2
3
4
5
6
7
8
9
10
11
12
13
void Level1()
{
Level[100][100] =
{
"########",
"#      #",
"# @    #",
"#      #",
"#      #",
"#    + #",
"########"
};
}


Level array doesn't exist at all let alone in the scope of this function as nothing was passed in. You also need to read up on how to initialize arrays as this has a few problems in itself, even if the array existed. Also once the function returns, this array does not exist anymore as it is out of scope with no reference to it left.

It can be harder to make a game through the console window than it would be to just download the DirectX SDK or SFML and make a game that way( and it would have graphics too that way ).


@ Pindrought
I wouldn't throw Direct X at him/her or SFML . And no it wouldn't be easier for what he's/she's trying to do he/she would have to learn a hell of a lot more material before they could use either API. Graphics are not as quick and easy as you make out in this comment.

I suggest you get a good book about basic C++, read all of it, do some simpler programs like tic tac toe, and go over it until you fully understand all of the material. Everyone needs to crawl before they walk and walk before they run.

Hope this helps.
Last edited on
Topic archived. No new replies allowed.