0

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.).

1
Contributor
1
Reply
11
Views
3 Years
Discussion Span
Last Post by jkhippie
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.