CritterModel::CritterModel(unsigned int width, unsigned int height) { if(width == 0 || height == 0) { throw myInvalidArgEx; } this->width = width; this->height = height; // allocate some space for our 2D grid grid = new Critter** [width]; for(unsigned int x = 0; x < width; x++) { grid[x] = new Critter* [height]; for(unsigned int y = 0; y < height; y++) { grid[x][y] = NULL; } } food = new bool* [width]; for(unsigned int x = 0; x < width; x++) { food[x] = new bool[height]; // createRandomFood will take care of initializing for us } moveCount = 0; createRandomFood(); addCritters(10); }
void FoodManager::logic(){ assert(m_foodGenTime > sf::Time::Zero); if(m_foodGenClock.getElapsedTime() >= m_foodGenTime){ m_foodGenClock.restart(); createRandomFood(); } }