forked from s425077/PotatoPlan
Merge branch 'Joel-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Joel-ML
This commit is contained in:
commit
4a786a166e
@ -248,6 +248,30 @@
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:PulsesIcon.png
|
||||
|
||||
#begin rain.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:MakeSquare=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:rain.png
|
||||
|
||||
#begin rain.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:MakeSquare=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:rain.png
|
||||
|
||||
#begin Right.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
|
BIN
Game1/Content/Rainfall.bmp
Normal file
BIN
Game1/Content/Rainfall.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.7 MiB |
BIN
Game1/Content/rain.png
Normal file
BIN
Game1/Content/rain.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.3 KiB |
@ -21,6 +21,7 @@ namespace Game1
|
||||
private Texture2D house;
|
||||
private Texture2D markers;
|
||||
private Texture2D mouseCursor;
|
||||
private Texture2D Rain;
|
||||
string directory = Directory.GetCurrentDirectory();
|
||||
|
||||
|
||||
@ -43,6 +44,10 @@ namespace Game1
|
||||
|
||||
MouseState state;
|
||||
|
||||
private int cloudAnimationSpeed = 2;
|
||||
private int cloudFrame = 0;
|
||||
private int cloudSprite;
|
||||
|
||||
|
||||
public Game1()
|
||||
{
|
||||
@ -86,7 +91,7 @@ namespace Game1
|
||||
|
||||
|
||||
graphics.PreferredBackBufferWidth = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().X;
|
||||
graphics.PreferredBackBufferHeight = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().Y + 300;
|
||||
graphics.PreferredBackBufferHeight = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().Y + 380;
|
||||
graphics.ApplyChanges();
|
||||
}
|
||||
|
||||
@ -108,6 +113,8 @@ namespace Game1
|
||||
tileConnected[2] = Content.Load<Texture2D>("Right");
|
||||
tileConnected[3] = Content.Load<Texture2D>("Bottom");
|
||||
|
||||
Rain = Content.Load<Texture2D>("rain");
|
||||
|
||||
|
||||
|
||||
|
||||
@ -191,11 +198,11 @@ namespace Game1
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
spriteBatch.Draw(ProgressionBar, new Rectangle(i * 227, (int)(input.getSize().Y * (input.getTileSize() + input.getSpacing())), 5, 295), Color.White);
|
||||
spriteBatch.Draw(tile[0], new Rectangle(i * 227, (int)(input.getSize().Y * (input.getTileSize() + input.getSpacing())), 5, 350), Color.White);
|
||||
}
|
||||
for (int i = 0; i < 15; i++)
|
||||
for (int i = 0; i < 17; i++)
|
||||
{
|
||||
spriteBatch.Draw(ProgressionBar, new Rectangle(0, (int)(input.getSize().Y * (input.getTileSize() + input.getSpacing())) + i * 20, (int)(input.getSize().X * (input.getTileSize() + input.getSpacing())), 1), Color.White);
|
||||
spriteBatch.Draw(tile[0], new Rectangle(0, (int)(input.getSize().Y * (input.getTileSize() + input.getSpacing())) + i * 20, (int)(input.getSize().X * (input.getTileSize() + input.getSpacing())), 1), Color.White);
|
||||
}
|
||||
|
||||
spriteBatch.DrawString(Bold, "Time: ", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed);
|
||||
@ -239,10 +246,9 @@ namespace Game1
|
||||
{
|
||||
for (int j = 0; j < input.getSize().Y; j++)
|
||||
{
|
||||
|
||||
|
||||
Rectangle tilePos = new Rectangle(i * (input.getSpacingTile()), j * (input.getSpacingTile()), input.getTileSize(), input.getTileSize());
|
||||
|
||||
|
||||
|
||||
spriteBatch.Draw(tile[tractorUnit.getFarm().getCrop(i, j).getStatus()], tilePos, Time.GetTimeOfDay());
|
||||
if (i > 0)
|
||||
{
|
||||
@ -306,6 +312,23 @@ namespace Game1
|
||||
|
||||
}
|
||||
}
|
||||
cloudFrame++;
|
||||
if (cloudFrame > cloudAnimationSpeed)
|
||||
{
|
||||
cloudSprite++;
|
||||
if (cloudSprite > 4)
|
||||
{
|
||||
cloudSprite = 0;
|
||||
}
|
||||
cloudFrame = 0;
|
||||
}
|
||||
for (int i = -1; i < input.getSize().X + 1; i++) //Draw the tiles
|
||||
{
|
||||
for (int j = -1; j < input.getSize().Y + 1; j++)
|
||||
{
|
||||
spriteBatch.Draw(Rain, tractorUnit.getFarm().getRainPosition(input.getTileSize(), i, j), new Rectangle(0, cloudSprite * 96, input.getTileSize(), input.getTileSize()), Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void InspectTile()
|
||||
|
@ -32,13 +32,13 @@ class Controller
|
||||
if (state.IsKeyDown(Keys.W) && Size.Y < 20)
|
||||
{
|
||||
Size.Y++;
|
||||
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 300;
|
||||
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 380;
|
||||
}
|
||||
|
||||
if (state.IsKeyDown(Keys.S) && Size.Y > 2)
|
||||
{
|
||||
Size.Y--;
|
||||
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 300;
|
||||
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 380;
|
||||
}
|
||||
return Size;
|
||||
}
|
||||
|
@ -17,18 +17,21 @@ class Crops
|
||||
private float fullTimer;
|
||||
private bool housePos = false;
|
||||
private Vector2 Size;
|
||||
private Random r = new Random();
|
||||
private CropTypes DataSet;
|
||||
SoilProperties soilProperties = new SoilProperties();
|
||||
private float ProductionRate;
|
||||
private float tempRain;
|
||||
|
||||
|
||||
|
||||
public void updateCrop(Vector2 newSize)
|
||||
public void updateCrop(Vector2 newSize, float Rain)
|
||||
{
|
||||
tempRain = Rain;
|
||||
getProductionRate(DataSet);
|
||||
if (UpdateCrop == 60)
|
||||
{
|
||||
degradeSoil();
|
||||
degradeSoil(Rain);
|
||||
UpdateCrop = 0;
|
||||
}
|
||||
|
||||
@ -195,7 +198,7 @@ class Crops
|
||||
}
|
||||
}
|
||||
|
||||
public void degradeSoil()
|
||||
public void degradeSoil(float Rain)
|
||||
{
|
||||
|
||||
if (soilProperties.Nitrogen > 4.0f)
|
||||
@ -211,6 +214,22 @@ class Crops
|
||||
soilProperties.Potassium = soilProperties.Potassium - (soilProperties.PotassiumDegradeRate * (float)Math.Pow(ProductionRate, 2));
|
||||
}
|
||||
|
||||
|
||||
if (Rain >= 0.5f)
|
||||
{
|
||||
soilProperties.Rainfall = soilProperties.Rainfall + (float)Math.Pow(Rain, 1.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
soilProperties.Rainfall = soilProperties.Rainfall - 0.1f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setPrevRainfall(float nRainfall)
|
||||
{
|
||||
soilProperties.prevRainfall = nRainfall;
|
||||
soilProperties.Rainfall = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -413,6 +432,12 @@ class Crops
|
||||
spriteBatch.DrawString(Bold, Math.Round(soilProperties.Nitrogen, 1).ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 262), Color.DarkBlue);
|
||||
spriteBatch.DrawString(Bold, "Production Rate: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 282), Color.DarkRed);
|
||||
spriteBatch.DrawString(Bold, Math.Round((ProductionRate * 100), 1).ToString() + "%", new Vector2(370, Size.Y * (tileSize + Spacing) + 282), Color.DarkBlue);
|
||||
spriteBatch.DrawString(Bold, "Last Years Rainfall: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 302), Color.DarkRed);
|
||||
spriteBatch.DrawString(Bold, Math.Round((soilProperties.prevRainfall), 1).ToString() + "mm", new Vector2(370, Size.Y * (tileSize + Spacing) + 302), Color.DarkBlue);
|
||||
spriteBatch.DrawString(Bold, "Rainfall: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 322), Color.DarkRed);
|
||||
spriteBatch.DrawString(Bold, Math.Round((soilProperties.Rainfall), 1).ToString() + "mm", new Vector2(370, Size.Y * (tileSize + Spacing) + 322), Color.DarkBlue);
|
||||
spriteBatch.DrawString(Bold, "Rain mm/s: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 342), Color.DarkRed);
|
||||
spriteBatch.DrawString(Bold, Math.Round((tempRain * 2), 2).ToString() + "mm", new Vector2(370, Size.Y * (tileSize + Spacing) + 342), Color.DarkBlue);
|
||||
spriteBatch.End();
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,12 @@ class Farm
|
||||
private int Update;
|
||||
private Astar astar = new Astar();
|
||||
private PerlinNoise perlin = new PerlinNoise();
|
||||
private Vector2 RainPosition;
|
||||
private Vector2 WindSpeed;
|
||||
private System.Drawing.Color[][] RainfallMap;
|
||||
private float[][] whiteNoise;
|
||||
private float[][] perlinNoise;
|
||||
private int resetBitMap = 0;
|
||||
|
||||
|
||||
//initializes the crops
|
||||
@ -32,17 +36,7 @@ class Farm
|
||||
for (int j = 0; j < 99; j++)
|
||||
{
|
||||
int x = 0;
|
||||
/*
|
||||
int x = r.Next(0, 3);
|
||||
if (x == 0)
|
||||
{
|
||||
x = r.Next(0, 2);
|
||||
}
|
||||
if (x == 2)
|
||||
{
|
||||
x = r.Next(1, 3);
|
||||
}
|
||||
*/
|
||||
|
||||
if (perlinNoise[i][j] > 0 && perlinNoise[i][j] < 0.15f)
|
||||
x = 0;
|
||||
else if (perlinNoise[i][j] >= 0.15f && perlinNoise[i][j] < 0.8f)
|
||||
@ -78,9 +72,19 @@ class Farm
|
||||
}
|
||||
if (dirtCount != 0)
|
||||
init(Size, housepos);
|
||||
RainPosition.X = r.Next(0, 1900);
|
||||
RainPosition.Y = r.Next(0, 1950);
|
||||
WindSpeed.X = r.Next(-1, 1);
|
||||
WindSpeed.Y = r.Next(-1, 1);
|
||||
RainfallMap = PerlinNoise.LoadImage("C:\\Users\\Joel\\source\\repos\\Oskars Repo\\Game1\\Content\\Rainfall.bmp");
|
||||
}
|
||||
|
||||
public void updateFarm(Vector2 Size)
|
||||
public Rectangle getRainPosition(int TileSize, int x, int y)
|
||||
{
|
||||
return new Rectangle((int)(-TileSize * (RainPosition.X - Math.Truncate(RainPosition.X))) + TileSize * x, (int)(-TileSize * (RainPosition.Y - Math.Truncate(RainPosition.Y))) + TileSize * y, TileSize, TileSize);
|
||||
}
|
||||
|
||||
public void updateFarm(Vector2 Size, int nDay)
|
||||
{
|
||||
Update++;
|
||||
if (Update == 30)
|
||||
@ -90,14 +94,16 @@ class Farm
|
||||
for (int j = 0; j < Size.Y; j++)
|
||||
{
|
||||
|
||||
crops[i, j].updateCrop(Size);
|
||||
crops[i, j].updateCrop(Size, RainfallMap[(int)Math.Round(RainPosition.X) + i][(int)Math.Round(RainPosition.Y) + j].GetBrightness());
|
||||
}
|
||||
}
|
||||
|
||||
Update = 0;
|
||||
}
|
||||
|
||||
updateRainMapPosition();
|
||||
}
|
||||
|
||||
|
||||
//Changes the properties of the tile when the tractor reaches this tile.
|
||||
public void setCropStatus(float xfloat, float yfloat)
|
||||
{
|
||||
@ -129,6 +135,48 @@ class Farm
|
||||
return crops;
|
||||
}
|
||||
|
||||
private void updateRainMapPosition()
|
||||
{
|
||||
float x = WindSpeed.X + (float)r.Next(-5, 5) / 3000;
|
||||
float y = WindSpeed.Y + (float)r.Next(-5, 5) / 3000;
|
||||
|
||||
if (x < 0.02f && x > -0.02f)
|
||||
{
|
||||
WindSpeed.X = x;
|
||||
}
|
||||
|
||||
if (y < 0.02f && y > -0.02f)
|
||||
{
|
||||
WindSpeed.Y = y;
|
||||
}
|
||||
|
||||
if (WindSpeed.X > 0 && RainPosition.X < 1900)
|
||||
{
|
||||
RainPosition.X = RainPosition.X + WindSpeed.X;
|
||||
}
|
||||
else if (WindSpeed.X < 0 && RainPosition.X > 1)
|
||||
{
|
||||
RainPosition.X = RainPosition.X + WindSpeed.X;
|
||||
}
|
||||
|
||||
if (WindSpeed.Y > 0 && RainPosition.Y < 1900)
|
||||
{
|
||||
RainPosition.Y = RainPosition.Y + WindSpeed.Y;
|
||||
}
|
||||
else if (WindSpeed.Y < 0 && RainPosition.Y > 1)
|
||||
{
|
||||
RainPosition.Y = RainPosition.Y + WindSpeed.Y;
|
||||
}
|
||||
resetBitMap++;
|
||||
if (resetBitMap == 20000)
|
||||
{
|
||||
RainPosition.X = r.Next(700, 1300);
|
||||
RainPosition.Y = r.Next(700, 1300);
|
||||
resetBitMap = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setNewHousePos(Vector2 pos, bool newState)
|
||||
{
|
||||
crops[(int)pos.X, (int)pos.Y].setHousePos(newState);
|
||||
@ -176,6 +224,19 @@ class Farm
|
||||
return holderIndex;
|
||||
}
|
||||
|
||||
public Color getRainAmount(int x, int y)
|
||||
{
|
||||
if (RainfallMap[x + (int)Math.Round(RainPosition.X)][y + (int)Math.Round(RainPosition.Y)].GetBrightness() < 0.60f)
|
||||
{
|
||||
return Color.FromNonPremultiplied(255, 255, 255, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Color.FromNonPremultiplied(255, 255, 255, (int)(300 * RainfallMap[x + (int)Math.Round(RainPosition.X)][y + (int)Math.Round(RainPosition.Y)].GetBrightness()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public float getProductionRate(int x, int y, int Type)
|
||||
{
|
||||
return crops[x, y].getProductionRate(PresetCrops.getPresetCropTypes(Type));
|
||||
|
@ -17,6 +17,8 @@ class SoilProperties
|
||||
public float Nitrogen;
|
||||
public float Potassium;
|
||||
public float Phosphorous;
|
||||
public float Rainfall;
|
||||
public float prevRainfall;
|
||||
public float NitrogenDegradeRate = 1.0f - (1.0f/55 * 40);
|
||||
public float PotassiumDegradeRate = 1.0f - (1.0f/28 * 23);
|
||||
public float PhosphorousDegradeRate = 1.0f - (1.0f/60 * 37);
|
||||
@ -51,6 +53,7 @@ class SoilProperties
|
||||
Nitrogen = GetRandomNumber(4 , 42); //was 4, 60
|
||||
Potassium = GetRandomNumber(0.01f, 19); // was 0, 28
|
||||
Phosphorous = GetRandomNumber(0.01f, 42); // was 0, 60
|
||||
prevRainfall = r.Next(247, 3617);
|
||||
}
|
||||
|
||||
public float GetRandomNumber(double minimum, double maximum)
|
||||
|
@ -54,11 +54,12 @@ class DayNightCycle
|
||||
|
||||
public Color GetTimeOfDay()
|
||||
{
|
||||
int blue, red, brightness;
|
||||
int blue, red, brightness, green, potatorate = 255;
|
||||
if (nightTime == 0 && dayTime == 0)
|
||||
{
|
||||
red = 1;
|
||||
blue = 1;
|
||||
green = 1;
|
||||
brightness = 1;
|
||||
|
||||
}
|
||||
@ -66,20 +67,29 @@ class DayNightCycle
|
||||
{
|
||||
if ((float)dayTime / lengthOfDay < 0.5)
|
||||
{
|
||||
blue = (int)(((float)nightTime / lengthOfNight) * 255) + (int)((1.0f - (float)dayTime / lengthOfDay) * 255);
|
||||
blue = (int)(((float)nightTime / lengthOfNight) * potatorate) + (int)((1.0f - (float)dayTime / lengthOfDay) * potatorate);
|
||||
}
|
||||
else
|
||||
{
|
||||
blue = (int)(((float)nightTime / lengthOfNight) * 255) + (int)(((float)dayTime / lengthOfDay) * 255);
|
||||
blue = (int)(((float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
||||
}
|
||||
|
||||
if ((float)nightTime / lengthOfNight < 0.5)
|
||||
{
|
||||
red = (int)((1.0 - (float)nightTime / lengthOfNight) * 255) + (int)(((float)dayTime / lengthOfDay) * 255);
|
||||
red = (int)((1.0 - (float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
||||
}
|
||||
else
|
||||
{
|
||||
red = (int)(((float)nightTime / lengthOfNight) * 255) + (int)(((float)dayTime / lengthOfDay) * 255);
|
||||
red = (int)(((float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
||||
}
|
||||
|
||||
if ((float)nightTime / lengthOfNight < 0.5)
|
||||
{
|
||||
green = (int)((1.0 - (float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
||||
}
|
||||
else
|
||||
{
|
||||
green = (int)(((float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
||||
}
|
||||
|
||||
if (Time)
|
||||
@ -98,8 +108,12 @@ class DayNightCycle
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Color.FromNonPremultiplied(red, 255, blue, brightness);
|
||||
/*
|
||||
red = (int)(red / 1.2f);
|
||||
blue = (int)(blue / 1.2f);
|
||||
green = (int)(green / 1.2f);
|
||||
*/
|
||||
return Color.FromNonPremultiplied(red, green, blue, 255);
|
||||
}
|
||||
|
||||
public int GetTimeOfDayInt()
|
||||
|
@ -22,7 +22,7 @@ class Tractor
|
||||
Size = input.getSize();
|
||||
updatePosition(input.getSize(), Status);
|
||||
housePos = newHousePos;
|
||||
smartTractor.UpdateCrops(Speed);
|
||||
smartTractor.UpdateCrops(Speed, Time.getDays());
|
||||
|
||||
}
|
||||
|
||||
|
@ -73,11 +73,11 @@ class SmartTractor
|
||||
farm.setNewHousePos(pos, newState);
|
||||
}
|
||||
|
||||
public void UpdateCrops(int Speed)
|
||||
public void UpdateCrops(int Speed, int nDay)
|
||||
{
|
||||
for (int i = 0; i < Speed; i++)
|
||||
{
|
||||
farm.updateFarm(Size);
|
||||
farm.updateFarm(Size, nDay);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user