1
0
forked from s425077/PotatoPlan
This commit is contained in:
Joel 2020-05-24 16:26:04 +02:00
parent 2e48e49239
commit 64aaef69dd
4 changed files with 62 additions and 33 deletions

BIN
Game1/Content/Clouds Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View File

@ -318,7 +318,7 @@ namespace Game1
{ {
for (int j = -1; j < input.getSize().Y + 1; j++) 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()));
} }
} }

View File

@ -19,7 +19,6 @@ class Farm
private System.Drawing.Color[][] RainfallMap; private System.Drawing.Color[][] RainfallMap;
private float[][] whiteNoise; private float[][] whiteNoise;
private float[][] perlinNoise; private float[][] perlinNoise;
private int resetBitMap = 0;
//initializes the crops //initializes the crops
@ -73,17 +72,38 @@ class Farm
init(Size, housepos); init(Size, housepos);
RainPosition.X = r.Next(0, 1900); RainPosition.X = r.Next(0, 1900);
RainPosition.Y = r.Next(0, 1950); 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"); RainfallMap = PerlinNoise.LoadImage("C:\\Users\\Joel\\source\\repos\\Oskars Repo\\Game1\\Content\\Rainfall.png");
} }
public Rectangle getRainPosition(int TileSize, int x, int y) 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) public void drawWeatherInformation(SpriteBatch spriteBatch, SpriteFont Bold, Input input)
@ -102,14 +122,18 @@ class Farm
{ {
for (int j = 0; j < Size.Y; j++) for (int j = 0; j < Size.Y; j++)
{ {
Vector2 temp = new Vector2((int)Math.Round(RainPosition.X), (int)Math.Round(RainPosition.Y));
crops[i, j].updateCrop(Size, RainfallMap[(int)Math.Round(RainPosition.X) + i][(int)Math.Round(RainPosition.Y) + j].GetBrightness()); 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; Update = 0;
} }
updateRainMapPosition(); updateRainMapPosition(Size);
} }
@ -144,13 +168,13 @@ class Farm
return crops; return crops;
} }
private void updateRainMapPosition() private void updateRainMapPosition(Vector2 Size)
{ {
float x, y; float x, y;
x = WindSpeed.X + GetRandomNumber(-1f, 1f) / 2000; x = WindSpeed.X + GetRandomNumber(-1f, 1f) / 2000;
y = WindSpeed.Y + GetRandomNumber(-1f, 1f) / 2000; y = WindSpeed.Y + GetRandomNumber(-1f, 1f) / 2000;
x = -0.02f;
if (x < 0.02f && x > -0.02f) if (x <= 1f && x >= -1f)
{ {
WindSpeed.X = x; WindSpeed.X = x;
} }
@ -160,31 +184,25 @@ class Farm
WindSpeed.Y = y; WindSpeed.Y = y;
} }
if (WindSpeed.X > 0 && RainPosition.X < 1900) if (WindSpeed.X > 0 && RainPosition.X < 2000)
{
RainPosition.X = RainPosition.X + WindSpeed.X; RainPosition.X = RainPosition.X + WindSpeed.X;
} else if (WindSpeed.X < 0 && RainPosition.X > 0)
else if (WindSpeed.X < 0 && RainPosition.X > 1)
{
RainPosition.X = RainPosition.X + WindSpeed.X; 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; RainPosition.Y = RainPosition.Y + WindSpeed.Y;
} else if (WindSpeed.Y < 0 && RainPosition.Y > 0)
else if (WindSpeed.Y < 0 && RainPosition.Y > 1)
{
RainPosition.Y = RainPosition.Y + WindSpeed.Y; 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) public void setNewHousePos(Vector2 pos, bool newState)
@ -234,10 +252,21 @@ class Farm
return holderIndex; 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) public float getProductionRate(int x, int y, int Type)