// returns the length of the created platform private PlatformObject spawnPlatform(int localIndex, ObjectLocation location, Vector3 position, Vector3 direction, bool activateImmediately) { PlatformObject platform = (PlatformObject)infiniteObjectManager.objectFromPool(localIndex, ObjectType.Platform); platform.orient(position + (direction * platformSizes[localIndex].z / 2), Quaternion.LookRotation(direction)); int objectIndex = infiniteObjectManager.localIndexToObjectIndex(localIndex, ObjectType.Platform); InfiniteObject prevTopPlatform = infiniteObjectHistory.objectSpawned(objectIndex, 0, location, ObjectType.Platform, platform); // the current platform now becames the parent of the previous top platform if (prevTopPlatform != null) { prevTopPlatform.setInfiniteObjectParent(platform); } else { infiniteObjectHistory.setBottomInfiniteObject(location, false, platform); } infiniteObjectHistory.addTotalDistance(platformSizes[localIndex].z, location, false); if (activateImmediately) { platform.activate(); } return(platform); }
// turn the player to the specified location public Vector3 changeMoveDirection(Vector3 newDirection, bool rotateRight) { if (turnPlatform[(int)ObjectLocation.Center] != null) { turnOffset += moveDirection * (turnPlatform[(int)ObjectLocation.Center].turnLengthOffset + localDistance[(int)ObjectLocation.Center]); } moveDirection = newDirection; // don't change move directions if there are still turn objects. It is about to be game over anyway since multiple turns aren't supported this closely if (infiniteObjectHistory.getBottomTurnInfiniteObject(true)) { stopObjectSpawns = true; return(turnOffset); } ObjectLocation turnLocation = (rotateRight ? ObjectLocation.Right : ObjectLocation.Left); localDistance[(int)ObjectLocation.Center] = localDistance[(int)turnLocation]; localSceneDistance[(int)ObjectLocation.Center] = localSceneDistance[(int)turnLocation]; localPlatformHeight[(int)ObjectLocation.Center] = localPlatformHeight[(int)turnLocation]; localSceneHeight[(int)ObjectLocation.Center] = localSceneHeight[(int)turnLocation]; turnPlatform[(int)ObjectLocation.Center] = turnPlatform[(int)turnLocation]; turnPlatform[(int)ObjectLocation.Right] = turnPlatform[(int)ObjectLocation.Left] = null; // The center objects and the objects in the location opposite of turn are grouped togeter with the center object being the top most object for (int i = 0; i < 2; ++i) { InfiniteObject infiniteObject = infiniteObjectHistory.getTopInfiniteObject((turnLocation == ObjectLocation.Right ? ObjectLocation.Left : ObjectLocation.Right), i == 0); // may be null if the turn only turns one direction if (infiniteObject != null) { InfiniteObject centerObject = infiniteObjectHistory.getBottomInfiniteObject(ObjectLocation.Center, i == 0); infiniteObject.setInfiniteObjectParent(centerObject); } } infiniteObjectHistory.turn(turnLocation); if (turnPlatform[(int)ObjectLocation.Center] != null) { setupPlatformTurn(); } return(turnOffset); }
// spawn a scene object at the specified location private void spawnSceneObject(int localIndex, ObjectLocation location, Vector3 position, Vector3 direction, bool activateImmediately) { SceneObject scene = (SceneObject)infiniteObjectManager.objectFromPool(localIndex, ObjectType.Scene); scene.orient(position + direction * sceneSizes[localIndex].z / 2, Quaternion.LookRotation(direction)); localSceneDistance[(int)location] += sceneSizes[localIndex].z; int assocaitedPlatformLocalIndex = infiniteObjectHistory.getFirstPlatformIndex(); PlatformObject associatedPlatform = infiniteObjectManager.localIndexToInfiniteObject(assocaitedPlatformLocalIndex, ObjectType.Platform) as PlatformObject; if (associatedPlatform.slope != PlatformSlope.None) { localSceneHeight[(int)location] += platformSizes[assocaitedPlatformLocalIndex].y; } int objectIndex = infiniteObjectManager.localIndexToObjectIndex(localIndex, ObjectType.Scene); InfiniteObject prevTopScene = infiniteObjectHistory.objectSpawned(objectIndex, 0, location, ObjectType.Scene, scene); // the current scene now becames the parent of the previous top scene if (prevTopScene != null) { prevTopScene.setInfiniteObjectParent(scene); } else { infiniteObjectHistory.setBottomInfiniteObject(location, true, scene); } infiniteObjectHistory.addTotalDistance(sceneSizes[localIndex].z, location, true); if (scene.sectionTransition) { infiniteObjectHistory.didSpawnSectionTranition(location, true); } if (activateImmediately) { scene.activate(); } }
// set everything back to 0 for a new game public void saveObjectsReset() { // save off the current objects. They will be deactivated after new objects have been sapwned if (topPlatformObjectSpawned[(int)ObjectLocation.Center] != null) { savedInfiniteObjects = topPlatformObjectSpawned[(int)ObjectLocation.Center]; for (int i = 0; i < (int)ObjectLocation.Last; ++i) { if (i != (int)ObjectLocation.Center && topPlatformObjectSpawned[i]) { topPlatformObjectSpawned[i].setInfiniteObjectParent(savedInfiniteObjects); } if (bottomPlatformObjectSpawned[i] != null) { bottomPlatformObjectSpawned[i].setInfiniteObjectParent(savedInfiniteObjects); } if (topSceneObjectSpawned[i] != null) { topSceneObjectSpawned[i].setInfiniteObjectParent(savedInfiniteObjects); } if (bottomSceneObjectSpawned[i] != null) { bottomSceneObjectSpawned[i].setInfiniteObjectParent(savedInfiniteObjects); } if (topTurnPlatformObjectSpawned != null) { topTurnPlatformObjectSpawned.setInfiniteObjectParent(savedInfiniteObjects); } } } else { // topPlatformObjectSpawned is null when the player turns the wrong way off of a turn savedInfiniteObjects = topTurnPlatformObjectSpawned; } if (bottomTurnPlatformObjectSpawned != null) { bottomTurnPlatformObjectSpawned.setInfiniteObjectParent(savedInfiniteObjects); } if (topTurnSceneObjectSpawned != null) { topTurnSceneObjectSpawned.setInfiniteObjectParent(savedInfiniteObjects); } if (bottomTurnSceneObjectSpawned != null) { bottomTurnSceneObjectSpawned.setInfiniteObjectParent(savedInfiniteObjects); } activeObjectLocation = ObjectLocation.Center; for (int i = 0; i < (int)ObjectLocation.Last; ++i) { totalDistance[i] = 0; totalSceneDistance[i] = 0; platformDistanceIndexMap[i].reset(); topPlatformObjectSpawned[i] = bottomPlatformObjectSpawned[i] = null; topSceneObjectSpawned[i] = bottomSceneObjectSpawned[i] = null; spawnedSceneSectionTransition[i] = true; spawnedPlatformSectionTransition[i] = true; previousSection = 0; for (int j = 0; j < objectSpawnIndex.Length; ++j) { objectSpawnIndex[i][j] = -1; lastObjectSpawnDistance[i][j] = 0; } for (int j = 0; j < (int)ObjectType.Last; ++j) { objectTypeSpawnIndex[i][j] = -1; lastLocalIndex[i][j] = -1; latestObjectTypeSpawnDistance[i][j] = -1; } } topTurnPlatformObjectSpawned = bottomTurnPlatformObjectSpawned = null; topTurnSceneObjectSpawned = bottomTurnSceneObjectSpawned = null; }