void Level1::CreateAreas() { Random r; float x; float y; for (int i = 0; i < CFG_GETI("LEVEL_1_NUM_SLOW_AREAS"); ++i) { x = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_X"), CFG_GETF("LEVEL_1_MAX_X")); y = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_Y"), CFG_GETF("LEVEL_1_MAX_Y")); EntityFactory::CreateSlowArea(Vector(x, y)); } for (int i = 0; i < CFG_GETI("LEVEL_1_NUM_FAST_AREAS"); ++i) { x = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_X"), CFG_GETF("LEVEL_1_MAX_X")); y = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_Y"), CFG_GETF("LEVEL_1_MAX_Y")); EntityFactory::CreateFastArea(Vector(x, y)); } for (int i = 0; i < CFG_GETI("LEVEL_1_NUM_VITAMIN_AREAS"); ++i) { x = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_X"), CFG_GETF("LEVEL_1_MAX_X")); y = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_Y"), CFG_GETF("LEVEL_1_MAX_Y")); EntityFactory::CreateVitaminArea(Vector(x, y)); } for (int i = 0; i < CFG_GETI("LEVEL_1_NUM_ACID_AREAS"); ++i) { x = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_X"), CFG_GETF("LEVEL_1_MAX_X")); y = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_Y"), CFG_GETF("LEVEL_1_MAX_Y")); EntityFactory::CreateAcidArea(Vector(x, y)); } }
void Level1::Update() { LOG_D("[Level1] Updating"); auto cells = Engine::GetInstance().GetAllEntitiesWithComponentOfClass("GrowthComponent"); for (int i = cells.size(); i < CFG_GETI("LEVEL_1_INITIAL_NUM_CELLS"); ++i) { Random r; float x = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_X"), CFG_GETF("LEVEL_1_MAX_X")); float y = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_Y"), CFG_GETF("LEVEL_1_MAX_Y")); auto cell = EntityFactory::CreateCell(Vector(x, y)); auto growthComponent = std::static_pointer_cast<GrowthComponent>(Engine::GetInstance().GetEntityManager()->GetSingleComponentOfClass(cell, "GrowthComponent")); if (r.GenerateFloat() < 0.1) growthComponent->SetLevel(2); Engine::GetInstance().AddComponent( std::make_shared<AIComponent>("EatableComponent"), cell); } if (finished) { ZoomOutEffect(); } else { if (!Engine::GetInstance().HasEntityWithComponentOfClass("PlayerComponent")) { Engine::GetInstance().SetNextLevel(std::make_shared<LoseLevel>()); SetFinished(); } else { auto playerEntity = Engine::GetInstance().GetEntityWithComponentOfClass("PlayerComponent"); auto growthComponent = std::static_pointer_cast<GrowthComponent>(Engine::GetInstance().GetEntityManager()->GetSingleComponentOfClass(playerEntity, "GrowthComponent")); if (growthComponent->GetLevel() == CFG_GETI("LEVEL_1_GOAL_SIZE")) { finished = true; Engine::GetInstance().DeleteSystem("GrowthSystem"); } } } }
void Level1::CreateBacteria() { Random r; float x; float y; for (int i = 0; i < CFG_GETI("LEVEL_1_INITIAL_NUM_BACTERIA"); ++i) { x = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_X"), CFG_GETF("LEVEL_1_MAX_X")); y = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_Y"), CFG_GETF("LEVEL_1_MAX_Y")); EntityFactory::CreateBacterium(Vector(x, y)); } }
void Level1::CreateCells() { Random r; float x; float y; std::shared_ptr<Entity> cell; for (int i = 0; i < CFG_GETI("LEVEL_1_INITIAL_NUM_CELLS"); ++i) { x = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_X"), CFG_GETF("LEVEL_1_MAX_X")); y = r.GenerateFloat(CFG_GETF("LEVEL_1_MIN_Y"), CFG_GETF("LEVEL_1_MAX_Y")); cell = EntityFactory::CreateCell(Vector(x, y)); Engine::GetInstance().AddComponent( std::make_shared<AIComponent>("EatableComponent"), cell); } }
int main() { Random *r = new Random(); cout<<"Random integers\n"; cout<<"--------------------------\n"; int i = 9; while(i) { cout<<"\t"<<r->GenerateInt()<<"\n"; i--; } cout<<"Random integers between 0-20\n"; cout<<"--------------------------\n"; i = 9; while(i) { cout<<"\t"<<r->GenerateInt(2, 20)<<"\n"; i--; } cout<<"Random floating point values\n"; cout<<"--------------------------\n"; i = 9; while(i) { cout<<"\t"<<r->GenerateFloat()<<"\n"; i--; } cout<<"Random text of length 20\n"; cout<<"--------------------------\n"; i = 9; while(i) { cout<<"\t"<<r->GenerateText(20)<<"\n"; i--; } return 0; }