/* This function is responsible for populating our 'mySpline' object which is of type 'spline' It randomly generates points that are added to the splines linked list by calling the member function 'addPoint' */ void populatePoints(){ // Randomly generated pions float stepSize = 1.0f; // x coordinate (how spread out are the points along x-axis) float maxYHeight = 10.0f; // y cooridnate (the up and down of our roller coaster) float maxZWidth = 10.0f; // z cooridnate (how spread out is the roller coaster) for(int i = 0; i < splineSize; i++){ float randomHeight = rand_FloatRange(0,maxYHeight); float randomWidth = rand_FloatRange(0,maxZWidth); mySpline->addPoint(i*stepSize,randomHeight,randomWidth); } }
bool Spawner::SpawnInit(void* pSpawnStruct) { m_hSpawnObject = CoreObjectHandle(); m_spawnTimer = -1.0f; m_spawnTimeMin = 5.0f; m_spawnTimeMax = 5.0f; m_requiresTrigger = false; m_launchSpeed = 0.0f; SpawnableEntity* pSpawnableEnt = (SpawnableEntity*)pSpawnStruct; if(pSpawnableEnt == NULL) { return false; } CopyVec3(&m_position,&pSpawnableEnt->position); for (pugi::xml_node property = pSpawnableEnt->pProperties.child("property"); property; property = property.next_sibling("property")) { const char* propNameString = property.attribute("name").value(); const char* valueString = property.attribute("value").value(); if(strcmp(propNameString, "SpawnObject") == 0) { const u32 uniqueID = atoi(valueString); m_pEntityToSpawn = GAME->GetSpawnableEntityByTiledUniqueID(uniqueID); } else if(strcmp(propNameString, "SpawnTimeMin") == 0) { m_spawnTimeMin = atof(valueString); } else if(strcmp(propNameString, "SpawnTimeMax") == 0) { m_spawnTimeMax = atof(valueString); } else if(strcmp(propNameString, "LaunchSpeed") == 0) { m_launchSpeed = atof(valueString); } else if(strcmp(propNameString, "RequiresTrigger") == 0) { if(strcmp(valueString, "true") == 0) { m_requiresTrigger = true; } } } m_spawnTimer = rand_FloatRange(m_spawnTimeMin, m_spawnTimeMax); return false; }
void Spawner::Update(f32 timeElapsed) { if(m_requiresTrigger) { return; } vec2 posMeters; posMeters.x = m_position.x/GAME->GetPixelsPerMeter(); posMeters.y = m_position.y/GAME->GetPixelsPerMeter(); m_spawnTimer -= timeElapsed; if(m_spawnTimer < 0.0f) { m_spawnTimer = rand_FloatRange(m_spawnTimeMin, m_spawnTimeMax); CoreGameObject* pObject = (CoreGameObject*)GAME->CreateObject(m_pEntityToSpawn->type); if(pObject != NULL) { pObject->SpawnInit(m_pEntityToSpawn); if(m_launchSpeed > 0.0f) { b2Body* pBody = pObject->Box2D_GetBody(); if(pBody != NULL) { vec2 launchDir; const b2Vec2& bodyPos = pBody->GetWorldCenter(); const vec2 bodyPosVec = {bodyPos.x,bodyPos.y}; SubVec2(&launchDir,&bodyPosVec,&posMeters); TryNormalizeVec2_Self(&launchDir); ScaleVec2_Self(&launchDir, m_launchSpeed); pBody->SetLinearVelocity(b2Vec2(launchDir.x,launchDir.y)); } } } } }