Also how flexible do you think this code is? What if I had a map with dimensions 200*180 - could your program handle that? And if not, why not? :)
Regards, keineahnung |
If I changed the size of the array then it could handle it, but as it is I'm not sure if I can pass a multidimensional array through a function while allowing the number of elements to be changed.
I'm not going to use std:: right now as I'm new and it's a little tedious, but I will definitely implement it for the final game version if this ever gets finished.
As for using a class, I haven't much about them at all yet, but was planning to keep the map as a function. I want to add the enemies, players (yes, this will be a multiplayer game), and moving game objects as classes.
I just dropped this piece of code in the loadMap function that enables the labeling of variables:
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
|
// extract game variables from file
// (ignore notes and unused variables)
char ch;
int i = 0;
do
{
do
{
mapFile >> ch;
}
while (ch != ':' && ch != '!');
switch (i)
{
case 0:
mapFile >> xMapMax; // max x map range
break;
case 1:
mapFile >> yMapMax; // max y map range
break;
}
i++; // needed to cycle the case variables above
}
while (ch != '!');
...
|
This allows the map.txt file to be more like this:
// map.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
map x range (max): 10 - the map below needs to match this
map y range (max): 10
extra unknown variable for later: 10
another unknown variable: 10
Notes, and more notes here.
Variables must be in correct order for program
to run properly. Do not erase this message!
1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 2 2 1
1 0 2 2 2 4000000 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 2 0 0 1
1 0 0 0 0 2 2 2 0 1
1 1 1 1 1 1 1 1 1 1
|
What's the deal with pointer arrays? The reason why I thought they would be useful is because they are extremely fast and they are so easy to quickly manipulate (though could be a bad thing too I guess).
What would give me this same ability to easily extract game tiles, draw them, and test for collisions? I want the game board to be able to be manipulated very easily in many ways, such as turning the game map upside down.