diff --git a/Game1/Game1.cs b/Game1/Game1.cs index 606387c..c01ef1f 100644 --- a/Game1/Game1.cs +++ b/Game1/Game1.cs @@ -318,7 +318,7 @@ namespace Game1 { for (int j = -1; j < input.getSize().Y + 1; j++) { - spriteBatch.Draw(Rain, tractorUnit.getFarm().getRainPosition(input.getTileSize(), i, j), tractorUnit.getFarm().getDestinationRectangle(i, j, input.getSize()), tractorUnit.getFarm().getRainAmount(i, j, Time.GetTimeOfDay(), input.getSize())); + spriteBatch.Draw(Rain, tractorUnit.getFarm().getRainPosition(input.getTileSize(), i, j, input.getSize()), tractorUnit.getFarm().getDestinationRectangle(i, j, input.getSize()), tractorUnit.getFarm().getRainAmount(i, j, Time.GetTimeOfDay(), input.getSize())); } } diff --git a/Game1/Sources/Crops/Farm.cs b/Game1/Sources/Crops/Farm.cs index 5d9dd20..b92376b 100644 --- a/Game1/Sources/Crops/Farm.cs +++ b/Game1/Sources/Crops/Farm.cs @@ -72,14 +72,20 @@ class Farm init(Size, housepos); RainPosition.X = r.Next(0, 1900); RainPosition.Y = r.Next(0, 1950); - RainPosition.X = 1980; - RainPosition.Y = 800; + RainPosition.X = 1970; + RainPosition.Y = 155; RainfallMap = PerlinNoise.LoadImage("C:\\Users\\Joel\\source\\repos\\Oskars Repo\\Game1\\Content\\Rainfall.png"); //RainfallMap = PerlinNoise.LoadImage("C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/Rainfall.png"); } - public Rectangle getRainPosition(int TileSize, int x, int y) + public Rectangle getRainPosition(int TileSize, int x, int y, Vector2 Size) { + Vector2 temp = new Vector2((int)Math.Round(RainPosition.X), (int)Math.Round(RainPosition.Y)); + if (temp.X >= 1999 - Size.X - 1) + temp.X = x + (1999 - (int)Math.Round(RainPosition.X) - Size.X); + if (temp.Y >= 1999 - Size.Y - 1) + temp.Y = (1999 - (int)Math.Round(RainPosition.Y)); + float xtrunc = RainPosition.X - (float)Math.Truncate(RainPosition.X); float ytrunc = RainPosition.Y - (float)Math.Truncate(RainPosition.Y); @@ -99,12 +105,12 @@ class Farm public Rectangle getDestinationRectangle(int x, int y, Vector2 Size) { - Vector2 temp = new Vector2((int)Math.Round(RainPosition.X), (int)Math.Round(RainPosition.Y)); + Vector2 temp = new Vector2((int)Math.Round(x + RainPosition.X), y + (int)Math.Round(RainPosition.Y)); if (temp.X >= 1999 - Size.X - 1) - temp.X = (1999 - (int)Math.Round(RainPosition.X)); + temp.X = x + (1999 - (int)Math.Round(RainPosition.X)); if (temp.Y >= 1999 - Size.Y - 1) temp.Y = (1999 - (int)Math.Round(RainPosition.Y)); - return new Rectangle(x + (int)temp.X, y + (int)temp.Y, 1, 1); + return new Rectangle((int)temp.X, (int)temp.Y, 1, 1); } public void drawWeatherInformation(SpriteBatch spriteBatch, SpriteFont Bold, Input input) @@ -123,12 +129,14 @@ class Farm { for (int j = 0; j < Size.Y; j++) { - Vector2 temp = new Vector2((int)Math.Round(RainPosition.X), (int)Math.Round(RainPosition.Y)); + Vector2 temp = new Vector2((int)Math.Round(i + RainPosition.X), j + (int)Math.Round(RainPosition.Y)); if (temp.X >= 1999 - Size.X - 1) - temp.X = (1999 - (int)Math.Round(RainPosition.X)); + temp.X = i + ((1999 - (int)Math.Round(RainPosition.X))); if (temp.Y >= 1999 - Size.Y - 1) temp.Y = (1999 - (int)Math.Round(RainPosition.Y)); - crops[i, j].updateCrop(Size, RainfallMap[(int)Math.Round(temp.X) + i][(int)Math.Round(temp.Y) + j].GetBrightness()); + if (temp.X == -1) + temp.X = 1999; + crops[i, j].updateCrop(Size, RainfallMap[(int)Math.Round(temp.X)][(int)Math.Round(temp.Y)].GetBrightness()); } } @@ -196,12 +204,12 @@ class Farm RainPosition.Y = RainPosition.Y + WindSpeed.Y; if (Math.Round(RainPosition.X) == 1999 && WindSpeed.X > 0) - RainPosition.X = 1; + RainPosition.X = 0; else if (Math.Round(RainPosition.X) == 1 && WindSpeed.X < 0) RainPosition.X = 1999; if (Math.Round(RainPosition.Y) == 1999 - Size.Y - 1 && WindSpeed.Y > 0) - RainPosition.Y = 1; + RainPosition.Y = 0; if (Math.Round(RainPosition.Y) == 1 && WindSpeed.Y < 0) RainPosition.Y = 1999 - Size.Y - 1; } @@ -256,10 +264,10 @@ class Farm public Color getRainAmount(int x, int y, Color color, Vector2 Size) { Vector2 temp = new Vector2(x + (int)Math.Round(RainPosition.X), y + (int)Math.Round(RainPosition.Y)); - if (temp.X >= 1999 - Size.X - 1) - temp.X = (1999 - (int)Math.Round(RainPosition.X) + x); + if (temp.X >= 1999) + temp.X = -(1999 - (int)Math.Round(temp.X)); if (temp.Y >= 1999 - Size.Y - 1) - temp.Y = (1999 - (int)Math.Round(RainPosition.Y) + y); + temp.Y = (1999 - (int)Math.Round(RainPosition.Y)); if (temp.X == -1) temp.X = 1999; if (RainfallMap[(int)temp.X][(int)temp.Y].GetBrightness() < 0.4f)