diff --git a/Game1/Content/Clouds b/Game1/Content/Clouds new file mode 100644 index 0000000..338e5da Binary files /dev/null and b/Game1/Content/Clouds differ diff --git a/Game1/Content/Clouds.png b/Game1/Content/Clouds.png index 917faa5..338e5da 100644 Binary files a/Game1/Content/Clouds.png and b/Game1/Content/Clouds.png differ diff --git a/Game1/Game1.cs b/Game1/Game1.cs index 5ac7da2..606387c 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), tractorUnit.getFarm().getRainAmount(i, 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())); } } diff --git a/Game1/Sources/Crops/Farm.cs b/Game1/Sources/Crops/Farm.cs index 1acd5ce..c9928c3 100644 --- a/Game1/Sources/Crops/Farm.cs +++ b/Game1/Sources/Crops/Farm.cs @@ -19,7 +19,6 @@ class Farm private System.Drawing.Color[][] RainfallMap; private float[][] whiteNoise; private float[][] perlinNoise; - private int resetBitMap = 0; //initializes the crops @@ -73,17 +72,38 @@ class Farm init(Size, housepos); RainPosition.X = r.Next(0, 1900); RainPosition.Y = r.Next(0, 1950); + RainPosition.X = 5; + RainPosition.Y = 5; RainfallMap = PerlinNoise.LoadImage("C:\\Users\\Joel\\source\\repos\\Oskars Repo\\Game1\\Content\\Rainfall.png"); } public Rectangle getRainPosition(int TileSize, int x, int y) { - return new Rectangle(x * TileSize, y * TileSize, TileSize, TileSize); + float xtrunc = RainPosition.X - (float)Math.Truncate(RainPosition.X); + float ytrunc = RainPosition.Y - (float)Math.Truncate(RainPosition.Y); + + if (xtrunc > 0.5) + xtrunc = xtrunc - 1; + + if (ytrunc > 0.5) + ytrunc = ytrunc - 1; + xtrunc = -xtrunc; + ytrunc = -ytrunc; + + + + //return new Rectangle((int)(xtrunc * TileSize) + x * TileSize,(int)(ytrunc * TileSize) + y * TileSize, TileSize, TileSize); + return new Rectangle((int)(xtrunc * TileSize) + x * TileSize, (int)(ytrunc * TileSize) + y * TileSize, TileSize, TileSize); } - public Rectangle getDestinationRectangle(int x, int y) + public Rectangle getDestinationRectangle(int x, int y, Vector2 Size) { - return new Rectangle(x + (int)Math.Round(RainPosition.X), y + (int)Math.Round(RainPosition.Y), 1, 1); + Vector2 temp = new Vector2((int)Math.Round(RainPosition.X), (int)Math.Round(RainPosition.Y)); + if (RainPosition.X >= 1999 - Size.X) + temp.X = (Size.X) - (1999 - (int)Math.Round(RainPosition.X)); + if (RainPosition.Y >= 1999 - Size.Y) + temp.Y = (Size.Y) - (1999 - (int)Math.Round(RainPosition.Y)); + return new Rectangle(x + (int)temp.X, y + (int)temp.Y, 1, 1); } public void drawWeatherInformation(SpriteBatch spriteBatch, SpriteFont Bold, Input input) @@ -102,14 +122,18 @@ class Farm { for (int j = 0; j < Size.Y; j++) { - - crops[i, j].updateCrop(Size, RainfallMap[(int)Math.Round(RainPosition.X) + i][(int)Math.Round(RainPosition.Y) + j].GetBrightness()); + Vector2 temp = new Vector2((int)Math.Round(RainPosition.X), (int)Math.Round(RainPosition.Y)); + if (RainPosition.X >= 1999 - Size.X) + temp.X = (Size.X) - (1999 - (int)Math.Round(RainPosition.X)); + if (RainPosition.Y >= 1999 - Size.Y) + temp.Y = (Size.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()); } } Update = 0; } - updateRainMapPosition(); + updateRainMapPosition(Size); } @@ -144,13 +168,13 @@ class Farm return crops; } - private void updateRainMapPosition() + private void updateRainMapPosition(Vector2 Size) { float x, y; x = WindSpeed.X + GetRandomNumber(-1f, 1f) / 2000; y = WindSpeed.Y + GetRandomNumber(-1f, 1f) / 2000; - - if (x < 0.02f && x > -0.02f) + x = -0.02f; + if (x <= 1f && x >= -1f) { WindSpeed.X = x; } @@ -160,31 +184,25 @@ class Farm WindSpeed.Y = y; } - if (WindSpeed.X > 0 && RainPosition.X < 1900) - { + if (WindSpeed.X > 0 && RainPosition.X < 2000) RainPosition.X = RainPosition.X + WindSpeed.X; - } - else if (WindSpeed.X < 0 && RainPosition.X > 1) - { + else if (WindSpeed.X < 0 && RainPosition.X > 0) RainPosition.X = RainPosition.X + WindSpeed.X; - } - if (WindSpeed.Y > 0 && RainPosition.Y < 1900) - { + if (WindSpeed.Y > 0 && RainPosition.Y < 2000) RainPosition.Y = RainPosition.Y + WindSpeed.Y; - } - else if (WindSpeed.Y < 0 && RainPosition.Y > 1) - { + else if (WindSpeed.Y < 0 && RainPosition.Y > 0) RainPosition.Y = RainPosition.Y + WindSpeed.Y; - } - resetBitMap++; - if (resetBitMap == 100000) - { - RainPosition.X = r.Next(700, 1300); - RainPosition.Y = r.Next(700, 1300); - resetBitMap = 0; - } + if (Math.Round(RainPosition.X) == 1999 && WindSpeed.X > 0) + RainPosition.X = 1; + 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; + if (Math.Round(RainPosition.Y) == 1 && WindSpeed.Y < 0) + RainPosition.Y = 1999 - Size.Y - 1; } public void setNewHousePos(Vector2 pos, bool newState) @@ -234,10 +252,21 @@ class Farm return holderIndex; } - public Color getRainAmount(int x, int y) + public Color getRainAmount(int x, int y, Color color, Vector2 Size) { - return Color.FromNonPremultiplied(255, 255, 255, (int)(255 * RainfallMap[x + (int)Math.Round(RainPosition.X)][y + (int)Math.Round(RainPosition.Y)].GetBrightness())); - + Vector2 temp = new Vector2(x + (int)Math.Round(RainPosition.X), y + (int)Math.Round(RainPosition.Y)); + if (RainPosition.X >= 1999 - Size.X) + temp.X = (Size.X) - (1999 - (int)Math.Round(RainPosition.X)); + if (RainPosition.Y >= 1999 - Size.Y) + temp.Y = (Size.Y) - (1999 - (int)Math.Round(RainPosition.Y)); + if (RainfallMap[(int)temp.X][(int)temp.Y].GetBrightness() < 0.4f) + { + return Color.FromNonPremultiplied(color.R, color.G, color.B, (int)(0)); + } + else + { + return Color.FromNonPremultiplied(color.R, color.G, color.B, (int)(255 * RainfallMap[(int)temp.X][(int)temp.Y].GetBrightness())); + } } public float getProductionRate(int x, int y, int Type)