Hi, all. I'm have a class EnemyController with a function Spawn(...) that instantiates a new object of the appropriate type. I want to call Spawn from somewhere like my TileMap class to create a new Enemy in my tile collision method. Here's what I have so far...

class EnemyController
{
public:
    EnemyController() {}
    ~EnemyController() {}
    static void Spawn( int x, int y, EnemyType type );
    virtual void OnUpdate( Camera& cam )
    {
        int index = 0;
        for( auto i= EnemyList.begin(), end = EnemyList.end(); i != end; i++ )
        {
            EnemyList.at( index )->GetState().OnUpdate();  
            EnemyList.at( index++ )->Draw( cam );
        }
    }
public:
    static std::deque< EnemySprite* > EnemyList;
};

// Spawn(...) defined in the .cpp file

class TileMap
{
public:
    TileMap( const char* map, int mapWidth, int mapHeight, int tileWidth, int tileHeight );
    ~TileMap();
    void DoCollision( Sprite& s );
//stuff
private:
//stuff
    static EnemyController* eCon;
};

// In DoCollision(...)

if( condition )
{
    TileMap::eCon->Spawn( enemytype );
}

I keep getting "Unresolved External" link errors. I think I'm confused about static? I want the EnemyController class to spawn, keep track of, and manage all enemies, but I want to Spawn from differnt trigger points (hitting a certain tile, etc.).

6a619621f3a052655aade91b9b250670

Here you see the player has jumped under the "?" tile which triggered the tile above to display an animation showing the mushroom rising. At the end of the animation, that tile reverts to a blue tile and I want a Mushroom object to Spawn at that location. Thus, I want to call Spawn from Tile->Draw.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.