I'm currently trying to access a variable contained within a base object from another completely different object and I continually get error messages. I'll attempt to put up the important code since it's contained within fairly large classes.
From the Base .cpp file. ObjectPosition:
1 2 3 4 5 6 7 8 9 10 11 12
|
void ObjectPosition::init(float x,float y, float speed, int boundx, int boundy, float hit, int lives, bool live)
{
ObjectPosition::x = x;
ObjectPosition::y = y;
ObjectPosition::speed = speed;
ObjectPosition::boundx = boundx;
ObjectPosition::boundy = boundy;
ObjectPosition::hit = hit;
ObjectPosition::lives = lives;
ObjectPosition::live = live;
}
|
This is the initialization function for the BaseObject. All objects are inheriting these variables which are Protected within the ObjectPosition class.
Then they are initialized within the Pig class thus wise:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
void Pig::binit(float sx,float sy, ALLEGRO_BITMAP *simage)
{
//Sets all ObjectPosition Variables
ObjectPosition::init(800,900,10,80,40,40,10,true);
smaxFrame = 4;
scurFrame = 0;
sframeCount = 0;
sframeDelay = 2;
sframeWidth = 250;
sframeHeight = 140;
sanimationColumns = 4;
sanimationWalk = 0;
sanimationRows = 2;
sanimationDirection = 1;
sdirectionChange = 0;
simage = simage;
//Bear::TakeLife = &TakeLife;
}
|
So far so good all variables are being inherited fine. Pig functions correctly and so does the Bear.
Ok Now hear is where I'm having my issue. I have a separate class for the Player who interacts with the Pig to have an armor when activated sets the Pig's boundx to 0. Whenever I place it within the function I get an error. I have a bear written as a struct which works fine. And I can access the Object Position boundx with no problem, but that doesn't effect the pigs boundx.
Here's the function where I want the Pigs boundx set to 0. It's written within the Armor.h/.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
void Armor::Collided(Dave &warrior, Bear bear[], Directions &direction, Pig *aPig)
{
{
if(slive == true)
{
bear[1].boundx = 0;
aPig->pinitx();
samurai.armor--;
}
else if (slive == false)
bear[1].boundx = 200;
warrior.armor = 5;
}
}
|
I tried to initialize the boundx through the pig via pinitx but I get errors and I can't access through the pig to the object position to the boundx.
The warrior is written as a struct works fine.