SexyElf
03-13-2007, 08:58 AM
Hello All,
New to the forums, but glad I found them, looks like my kind of place :)
I recently started learning C++ here at university (in 1st year of robotics) and am loving it. Finally a way to code my ideas into something tangible!
We are upto Arrays and I am using them in part to create a 2d sim city strategy game. It is a simple project that I am using to expand my knowledge and skills as I learn the c++ language.
I am sure there are easier ways to approach this, but alas, I am not that advanced yet. We have just covered the basics and now are moving into some more advanced subjects (such as classes/arrays/pointers soon).
So far, in my game, I have been using 2D arrays to store data in relation to a grid in the game. Ie. ArrayTile [5][9] shows the tile type in the 9th x position and 5th y position on a 1st quadrent coordinate grid. Further 3D arrays are used to define multiple data in a single x-y position.
I don't really like arrays in this instance because they require a lot of extra coding and if one thing changes, a lot of the way the code is written must be changed.
So I designed an class that would hold all the data of each tile, and I was hoping to define an array by this class. Therefore, each array 'cell' would hold the data for that cell based on the class object.
However, when trying to initialize the array, I get the an error telling me basically that it is not possible.
Ie. Class is "Unit()" that has a blank constructor (so you can use Unit() to define an variable), Array is called "TestArray[20][20]" (2D 20x20 array).
I have "Unit TestArray[20][20];" which doesn't work. (I was thinking along the lines of "int TestArray[20][20];"
So, is there any simple, not totally complex way to achieve what I am looking for?
Basically, the Array is going to be called upon based on an x and y coordinate. The array, being part of the defined class, would then have a bunch of variables already stored in a single cell.
Thank you,
SexyElf
New to the forums, but glad I found them, looks like my kind of place :)
I recently started learning C++ here at university (in 1st year of robotics) and am loving it. Finally a way to code my ideas into something tangible!
We are upto Arrays and I am using them in part to create a 2d sim city strategy game. It is a simple project that I am using to expand my knowledge and skills as I learn the c++ language.
I am sure there are easier ways to approach this, but alas, I am not that advanced yet. We have just covered the basics and now are moving into some more advanced subjects (such as classes/arrays/pointers soon).
So far, in my game, I have been using 2D arrays to store data in relation to a grid in the game. Ie. ArrayTile [5][9] shows the tile type in the 9th x position and 5th y position on a 1st quadrent coordinate grid. Further 3D arrays are used to define multiple data in a single x-y position.
I don't really like arrays in this instance because they require a lot of extra coding and if one thing changes, a lot of the way the code is written must be changed.
So I designed an class that would hold all the data of each tile, and I was hoping to define an array by this class. Therefore, each array 'cell' would hold the data for that cell based on the class object.
However, when trying to initialize the array, I get the an error telling me basically that it is not possible.
Ie. Class is "Unit()" that has a blank constructor (so you can use Unit() to define an variable), Array is called "TestArray[20][20]" (2D 20x20 array).
I have "Unit TestArray[20][20];" which doesn't work. (I was thinking along the lines of "int TestArray[20][20];"
So, is there any simple, not totally complex way to achieve what I am looking for?
Basically, the Array is going to be called upon based on an x and y coordinate. The array, being part of the defined class, would then have a bunch of variables already stored in a single cell.
Thank you,
SexyElf