public override IObject2D CreateObject2D(LandWorld2D landWorld2D, IObject obj) { GroundLandObject groundLandObject = obj as GroundLandObject; if (groundLandObject != null) { return(new GroundObject2D(this, groundLandObject)); } return(null); }
public GroundObject2D(IObject2DFactory factory, GroundLandObject landObject) { Texture texture = factory.GetTextureByIndex((int)landObject.Type); if (landObject.LandTransition == LandTransition.NONE) { Random random = new Random(landObject.Position.X - landObject.Position.Y * landObject.Position.Y); switch (random.Next(0, 4)) { case 0: this.ObjectSprite = new Sprite(texture, new IntRect(2 * MainWindow.MODEL_TO_VIEW, 4 * MainWindow.MODEL_TO_VIEW, 2 * MainWindow.MODEL_TO_VIEW, 2 * MainWindow.MODEL_TO_VIEW)); break; case 1: this.ObjectSprite = new Sprite(texture, new IntRect(0 * MainWindow.MODEL_TO_VIEW, 0 * MainWindow.MODEL_TO_VIEW, 2 * MainWindow.MODEL_TO_VIEW, 2 * MainWindow.MODEL_TO_VIEW)); break; case 2: this.ObjectSprite = new Sprite(texture, new IntRect(2 * MainWindow.MODEL_TO_VIEW, 0 * MainWindow.MODEL_TO_VIEW, 2 * MainWindow.MODEL_TO_VIEW, 2 * MainWindow.MODEL_TO_VIEW)); break; case 3: this.ObjectSprite = new Sprite(texture, new IntRect(4 * MainWindow.MODEL_TO_VIEW, 0 * MainWindow.MODEL_TO_VIEW, 2 * MainWindow.MODEL_TO_VIEW, 2 * MainWindow.MODEL_TO_VIEW)); break; } } else { this.ObjectSprite = new Sprite(texture, this.GetTransitionTextureCoord(landObject.LandTransition)); } this.ObjectSprite.Scale = new Vector2f(0.5f, 0.5f); this.Position = new Vector2f(landObject.Position.X, landObject.Position.Y); }
public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude) { ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"]; ALandLayerGenerator cliffLandLayerGenerator = worldGenerator.Generators["cliff"]; bool[,] subArea = new bool[3, 3]; bool isThereGrass = false; this.ConstructGrassArea(worldGenerator, area); for (int i = 0; i < area.Height; i++) { for (int j = 0; j < area.Width; j++) { int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i); int altitudeOffset = cliffLandLayerGenerator.GetComputedPowerAt(j, i); if ((altitude > -2 || (altitude == -2 && altitudeOffset > 0)) && altitude < 7) { LandCreationHelper.GetComputedLandType(this, area, i, j, out int grassTypeInt, out int secondTypeInt, out LandTransition landTransition, out LandTransition secondLandTransition); //this.GetComputedLandType(area, i, j, out GrassType grassType, out GrassType secondType, out LandTransition landTransition, out LandTransition secondLandTransition); GrassType grassType = (GrassType)grassTypeInt; GrassType secondType = (GrassType)secondTypeInt; GroundLandObject groundLandObject = null; GroundLandObject secondGroundLandObject = null; if (grassType != GrassType.NONE) { groundLandObject = new GrassLandObject(area.Left + j, area.Top + i, altitude, grassType); groundLandObject.SetTransition(landTransition); isThereGrass = true; } if (secondType != grassType && secondType != GrassType.NONE) { secondGroundLandObject = new GrassLandObject(area.Left + j, area.Top + i, 0, secondType); secondGroundLandObject.SetTransition(secondLandTransition); isThereGrass = true; } bool onlyGround = altitude == 6 && altitudeOffset > 0; AssignGround(landChunk, i, j, altitude, altitudeOffset, groundLandObject, secondGroundLandObject, onlyGround); } } } if (isThereGrass) { landChunk.AddTypeInChunk(typeof(GrassLandObject)); } return(seed); }