internal override bool ParseNodeBodyElement(string id, VRMLParser parser) { if (id == "groundAngle") { GroundAngle.AddRange(parser.ParseSFFloatOrMFFloatValue()); } else if (id == "groundColor") { GroundColor.AddRange(parser.ParseSFColorOrMFColorValue()); } else if (id == "backUrl") { BackUrl.AddRange(parser.ParseSFStringOrMFStringValue()); } else if (id == "bottomUrl") { BottomUrl.AddRange(parser.ParseSFStringOrMFStringValue()); } else if (id == "frontUrl") { FrontUrl.AddRange(parser.ParseSFStringOrMFStringValue()); } else if (id == "leftUrl") { LeftUrl.AddRange(parser.ParseSFStringOrMFStringValue()); } else if (id == "rightUrl") { RightUrl.AddRange(parser.ParseSFStringOrMFStringValue()); } else if (id == "topUrl") { TopUrl.AddRange(parser.ParseSFStringOrMFStringValue()); } else if (id == "skyAngle") { SkyAngle.AddRange(parser.ParseSFFloatOrMFFloatValue()); } else if (id == "skyColor") { if (wasSkyColor) { SkyColor.AddRange(parser.ParseSFColorOrMFColorValue()); } else { SkyColor = parser.ParseSFColorOrMFColorValue(); } wasSkyColor = true; } else if (id == "transparency") { // since X3D Node Spec and VRML Classic Coding Spec disagree on the fieldType List <double> values = parser.ParseSFFloatOrMFFloatValue(); if (values.Count != 0) { Transparency = values[0]; } } else { return(false); } return(true); }
void FixedUpdate() { float xPos = gameObject.transform.position.x; if (modulesUntilNextBiome <= 0) { currentBiome = GetNextBiome(); UpdateGenerationVariables(); } GenerateBackground(); if (xPos * 0.05f > noOfSpawnedModules) { float moduleXPosition = (Mathf.RoundToInt(xPos * 0.05f) + modulesBeforeWorld) * 20; //instantiate a ground module. GroundAngle angle = (GroundAngle)Random.Range(0, 3); //choose a random angle. if (currentModuleHeight >= maximumModuleHeight && angle == GroundAngle.incline) //switch from incline to either flat or decline if already at or above max height to avoid exceeding it. { angle = (GroundAngle)Random.Range(1, 3); } else if (currentModuleHeight <= 0 && angle == GroundAngle.decline)//switch from decline to either flat or incline if already at or below 0 height { angle = (GroundAngle)Random.Range(0, 2); } switch (angle) { case GroundAngle.incline: Instantiate(currentBiomeGeneration.inclineGroundModules[Random.Range(0, currentBiomeGeneration.inclineGroundModules.Count)], new Vector2(moduleXPosition, currentModuleHeight * 5f), Quaternion.identity); currentModuleHeight++; //instantiate a random incline module and increase the current height by one break; case GroundAngle.flat: Instantiate(currentBiomeGeneration.flatGroundModules[Random.Range(0, currentBiomeGeneration.flatGroundModules.Count)], new Vector2(moduleXPosition, currentModuleHeight * 5f), Quaternion.identity); break; case GroundAngle.decline: Instantiate(currentBiomeGeneration.declineGroundModules[Random.Range(0, currentBiomeGeneration.declineGroundModules.Count)], new Vector2(moduleXPosition, currentModuleHeight * 5f), Quaternion.identity); currentModuleHeight--; //instantiate a random decline module and decrease the current height by one break; } bool spawnProp = Random.Range(0f, 1f) < currentBiomeGeneration.propChance; float groundHeight = GroundPosition(moduleXPosition).y; if (spawnProp) { int noOfProps = Random.Range(1, 3); for (int i = 0; i < noOfProps; i++) { Instantiate(currentBiomeGeneration.propModules[Random.Range(0, currentBiomeGeneration.propModules.Count)], GroundPosition(moduleXPosition), Quaternion.identity); } } if (spawnProp && Random.Range(0f, 1f) < powerUpChance) { float powerUpYPosition; float powerUpXPosition = moduleXPosition + Random.Range(-10, 10); if (GroundPosition(powerUpXPosition).y < groundHeight + 6f) // if powerUpXPosition is not on a module, { powerUpYPosition = groundHeight + Random.Range(10f, 15f); //spawn it in the air. } else { powerUpYPosition = GroundPosition(powerUpXPosition).y + 1;//otherwise, spawn it on top of the module } Vector2 PowerUpPosition = new Vector2(powerUpXPosition, powerUpYPosition); if (Random.Range(0, 2) == 0) { Instantiate(SpeedBoost, PowerUpPosition, Quaternion.identity); } else { Instantiate(jetPack, PowerUpPosition, Quaternion.identity); } } noOfSpawnedModules++; modulesUntilNextBiome--; } }
internal override bool ParseNodeBodyElement(string id, VRMLParser parser) { int line = parser.Line; if (id == "groundAngle") { GroundAngle.AddRange(parser.ParseSFFloatOrMFFloatValue()); } else if (id == "groundColor") { GroundColor.AddRange(parser.ParseSFColorOrMFColorValue()); } else if (id == "backTexture") { X3DNode node = parser.ParseSFNodeValue(); if (node != null) { BackTexture = node as X3DTextureNode; if (BackTexture == null) { parser.ErrorParsingNode(VRMLReaderError.UnexpectedNodeType, this, id, node, line); } } } else if (id == "bottomTexture") { X3DNode node = parser.ParseSFNodeValue(); if (node != null) { BottomTexture = node as X3DTextureNode; if (BottomTexture == null) { parser.ErrorParsingNode(VRMLReaderError.UnexpectedNodeType, this, id, node, line); } } } else if (id == "frontTexture") { X3DNode node = parser.ParseSFNodeValue(); if (node != null) { FrontTexture = node as X3DTextureNode; if (FrontTexture == null) { parser.ErrorParsingNode(VRMLReaderError.UnexpectedNodeType, this, id, node, line); } } } else if (id == "leftTexture") { X3DNode node = parser.ParseSFNodeValue(); if (node != null) { LeftTexture = node as X3DTextureNode; if (LeftTexture == null) { parser.ErrorParsingNode(VRMLReaderError.UnexpectedNodeType, this, id, node, line); } } } else if (id == "rightTexture") { X3DNode node = parser.ParseSFNodeValue(); if (node != null) { RightTexture = node as X3DTextureNode; if (RightTexture == null) { parser.ErrorParsingNode(VRMLReaderError.UnexpectedNodeType, this, id, node, line); } } } else if (id == "topTexture") { X3DNode node = parser.ParseSFNodeValue(); if (node != null) { TopTexture = node as X3DTextureNode; if (TopTexture == null) { parser.ErrorParsingNode(VRMLReaderError.UnexpectedNodeType, this, id, node, line); } } } else if (id == "skyAngle") { SkyAngle.AddRange(parser.ParseSFFloatOrMFFloatValue()); } else if (id == "skyColor") { if (wasSkyColor) { SkyColor.AddRange(parser.ParseSFColorOrMFColorValue()); } else { SkyColor = parser.ParseSFColorOrMFColorValue(); } wasSkyColor = true; } else if (id == "transparency") { // since X3D Node Spec and VRML Classic Coding Spec disagree on the fieldType List <double> values = parser.ParseSFFloatOrMFFloatValue(); if (values.Count != 0) { Transparency = values[0]; } } else { return(false); } return(true); }