Question about C ++ (Arduino wrapper): I'm writing a shoot for an Arduino game that has an LCD connected to it -
I have a base class ( Sprite), and other classes - Alien, Missileand are derived from this Player. The Alien class constructor also has a private member pMissile(a pointer to the class Missile) - an “object inside an object” would be a way to describe this, I think.
[when a Alienlaunches a rocket, it passes its own (x, y) coordinates to the rocket, and the rocket has its own way of moving, starting from the coordinates Alien]
My question is: how can I access the coordinates of a rocket through an object Alien? The ordered code is below, and I also drew a representation of the classes:
class Sprite
{
public:
Sprite(unsigned char * const spacePtrIn, unsigned int xInit, unsigned int yInit);
virtual void Move() = 0;
void Render() { display.drawBitmap(x,y, spacePtr, 5, 6, BLACK); }
unsigned int getX() const { return x; }
unsigned int getY() const { return y; }
protected:
unsigned char *spacePtr;
unsigned int x, y;
};
class Missile : public Sprite
{
public:
Missile(): Sprite(&spaceMissile[0], 0, 0) {}
virtual void Move();
};
class Alien : public Sprite
{
public:
Alien();
virtual void Move();
private:
Missile *pMissile;
};
Alien::Alien(): Sprite(&spaceAlien[0], random(5, 75), random(4, 10))
{
Missile MissileArray[MaxAmmoSize];
pMissile = &MissileArray[0];
}
void Alien::Move()
{
if( random(10) % 2 == 0 )
x += 1;
if( random(10) % 3 == 0 )
y += 1;
if( (pMissile != NULL) && (random(10) == 1) )
{
pMissile->setCoord(x, y);
pMissile->Move();
pMissile++;
}
Render();
}
Alien MONSTER;
Player HERO;
Alien *pMONSTER = &MONSTER;
void loop()
{
display.clearDisplay();
MONSTER.Move();
HERO.Move();
pMONSTER->getX();
**
delay(100);
display.display();
}

++-