From 913f8138952276862850c0d47fe2566f727ddb4b Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 10 May 2020 19:21:52 +0200 Subject: [PATCH 1/3] Somewhat finished --- Game1/Sources/Crops/Crops.cs | 53 ++++++++++++++++++++----- Game1/Sources/Crops/Farm.cs | 7 +++- Game1/Sources/Objects/HandleRotation.cs | 17 +++++--- Game1/Sources/Objects/Tractor.cs | 16 +++++--- 4 files changed, 70 insertions(+), 23 deletions(-) diff --git a/Game1/Sources/Crops/Crops.cs b/Game1/Sources/Crops/Crops.cs index 7ffe8a7..a8b437f 100644 --- a/Game1/Sources/Crops/Crops.cs +++ b/Game1/Sources/Crops/Crops.cs @@ -45,6 +45,11 @@ class Crops } } + public float getSpeedFactor(float tractorSpeed) + { + return 1f / getCostOnMovement(); + } + public SoilProperties getSoilProperties() { return soilProperties; @@ -103,7 +108,7 @@ class Crops // Changes the time required for the crops to be harvestable public void setCropTimer() { - if (cropType == 0) // Carrots + if (cropType == 1) // Barley { Timer = 300; fullTimer = Timer; @@ -133,25 +138,53 @@ class Crops } else if (Status == 2) //dirt { - return 16; + return 8; } else { - if (cropType == 0) + if (cropType == 1) { - return 15; //Carrots - } - else if (cropType == 1) - { - return 30; //Wheat + return 16; //Barley } else if (cropType == 2) { - return 40; //Berries + return 16; //Cotton + } + else if (cropType == 3) + { + return 16; //Ground Nuts + } + else if (cropType == 4) + { + return 16; //Maize + } + else if (cropType == 5) + { + return 16; //Millets + } + else if (cropType == 6) + { + return 16; //Oil Seeds + } + else if (cropType == 7) + { + return 16; //Paddy + } + else if (cropType == 8) + { + return 16; //Pulses + } + else if (cropType == 9) + { + return 16; //Sugarcane + } + else if (cropType == 10) + { + return 16; //Wheat } else { - return 50; //Fruit Trees + return 10; //Tobacco } } } diff --git a/Game1/Sources/Crops/Farm.cs b/Game1/Sources/Crops/Farm.cs index 5a5d0ed..b04c28c 100644 --- a/Game1/Sources/Crops/Farm.cs +++ b/Game1/Sources/Crops/Farm.cs @@ -113,8 +113,11 @@ class Farm { for (int j = 0; j < Size.X; j++) { - int x = getHighestProductionRate(i, j); - crops[i,j].setCropType(x, PresetCrops.getPresetCropTypes(x)); + if (crops[i, j].getStatus() != 3) + { + int x = getHighestProductionRate(i, j); + crops[i, j].setCropType(x, PresetCrops.getPresetCropTypes(x)); + } } } } diff --git a/Game1/Sources/Objects/HandleRotation.cs b/Game1/Sources/Objects/HandleRotation.cs index 0c23e92..3cadd22 100644 --- a/Game1/Sources/Objects/HandleRotation.cs +++ b/Game1/Sources/Objects/HandleRotation.cs @@ -1,17 +1,23 @@ using Microsoft.Xna.Framework; +using System; class HandleRotation { int rotationSpeed = 5, Rotation = 180; + private float oldSpeed; - public Vector2 UpdatePosition(int Destination, float tractorSpeed, Vector2 Position) + public Vector2 UpdatePosition(int Destination, float tractorSpeed, Vector2 Position, Crops crops) { Vector2 Direction; + if (oldSpeed != crops.getSpeedFactor(tractorSpeed)) + { + Position = new Vector2((int)Math.Round(Position.X), (int)Math.Round(Position.Y)); + } if (Destination == 0) { if (Rotation == 0) { - Direction = new Vector2(0, 1) * tractorSpeed; + Direction = new Vector2(0, 1) * crops.getSpeedFactor(tractorSpeed); Position = Position + Direction; } else @@ -34,7 +40,7 @@ class HandleRotation { if (Rotation == 180) { - Direction = new Vector2(0, -1) * tractorSpeed; + Direction = new Vector2(0, -1) * crops.getSpeedFactor(tractorSpeed); Position = Position + Direction; } else @@ -54,7 +60,7 @@ class HandleRotation { if (Rotation == 270) { - Direction = new Vector2(1, 0) * tractorSpeed; + Direction = new Vector2(1, 0) * crops.getSpeedFactor(tractorSpeed); Position = Position + Direction; } else @@ -77,7 +83,7 @@ class HandleRotation { if (Rotation == 90) { - Direction = new Vector2(-1, 0) * tractorSpeed; + Direction = new Vector2(-1, 0) * crops.getSpeedFactor(tractorSpeed); Position = Position + Direction; } else @@ -97,6 +103,7 @@ class HandleRotation } } + oldSpeed = crops.getSpeedFactor(tractorSpeed); return Position; } diff --git a/Game1/Sources/Objects/Tractor.cs b/Game1/Sources/Objects/Tractor.cs index d071f44..f2768a3 100644 --- a/Game1/Sources/Objects/Tractor.cs +++ b/Game1/Sources/Objects/Tractor.cs @@ -1,11 +1,12 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using System; class Tractor { private int Spacing, sizeTile, Speed = 1; private float tractorSpeed = 1; - private Vector2 Position, TargetPosition, Size, housePos; + private Vector2 Position, TargetPosition, Size, housePos, oldDeltaPosition, DeltaPosition; private Path path = new Path(); private SmartTractor smartTractor = new SmartTractor(); private HandleRotation handleRotation = new HandleRotation(); @@ -22,6 +23,7 @@ class Tractor updatePosition(input.getSize(), Status); housePos = newHousePos; smartTractor.UpdateCrops(Speed); + } public void init(Rectangle house, Input input) @@ -36,7 +38,8 @@ class Tractor // Runs when the tractor reaches a tile private void updateDirection(Vector2 Size, Vector2 newPosition) { - Vector2 DeltaPosition = TargetPosition - Position; + DeltaPosition = TargetPosition - Position; + if (DeltaPosition.X == 0) { @@ -46,23 +49,24 @@ class Tractor } else if (DeltaPosition.Y > 0) { - Position = handleRotation.UpdatePosition(0, tractorSpeed, Position); + Position = handleRotation.UpdatePosition(0, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing)))); } else if (DeltaPosition.Y < 0) { - Position = handleRotation.UpdatePosition(1, tractorSpeed, Position); + Position = handleRotation.UpdatePosition(1, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing)))); } } else if (DeltaPosition.X > 0) { - Position = handleRotation.UpdatePosition(2, tractorSpeed, Position); + Position = handleRotation.UpdatePosition(2, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing)))); } else if (DeltaPosition.X < 0) { - Position = handleRotation.UpdatePosition(3, tractorSpeed, Position); + Position = handleRotation.UpdatePosition(3, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing)))); } } + public void updatePosition(Vector2 Size, int Status) // updates the position { From c17adf52cd634f158ca4879496f86a60f9e9cbfc Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 10 May 2020 19:39:38 +0200 Subject: [PATCH 2/3] Fixed tile speed --- Game1/Sources/Crops/Crops.cs | 2 +- Game1/Sources/Objects/HandleRotation.cs | 26 ++++++++++++++++++++----- Game1/Sources/Objects/Tractor.cs | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Game1/Sources/Crops/Crops.cs b/Game1/Sources/Crops/Crops.cs index 1dba4d6..b89a402 100644 --- a/Game1/Sources/Crops/Crops.cs +++ b/Game1/Sources/Crops/Crops.cs @@ -184,7 +184,7 @@ class Crops } else { - return 10; //Tobacco + return 16; //Tobacco } } } diff --git a/Game1/Sources/Objects/HandleRotation.cs b/Game1/Sources/Objects/HandleRotation.cs index 3cadd22..2d11dde 100644 --- a/Game1/Sources/Objects/HandleRotation.cs +++ b/Game1/Sources/Objects/HandleRotation.cs @@ -4,7 +4,8 @@ using System; class HandleRotation { int rotationSpeed = 5, Rotation = 180; - private float oldSpeed; + private float oldSpeed, movementSpeed; + private Vector2 oldTile; public Vector2 UpdatePosition(int Destination, float tractorSpeed, Vector2 Position, Crops crops) { @@ -17,7 +18,7 @@ class HandleRotation { if (Rotation == 0) { - Direction = new Vector2(0, 1) * crops.getSpeedFactor(tractorSpeed); + Direction = new Vector2(0, 1) * movementSpeed; Position = Position + Direction; } else @@ -40,7 +41,7 @@ class HandleRotation { if (Rotation == 180) { - Direction = new Vector2(0, -1) * crops.getSpeedFactor(tractorSpeed); + Direction = new Vector2(0, -1) * movementSpeed; Position = Position + Direction; } else @@ -60,7 +61,7 @@ class HandleRotation { if (Rotation == 270) { - Direction = new Vector2(1, 0) * crops.getSpeedFactor(tractorSpeed); + Direction = new Vector2(1, 0) * movementSpeed; Position = Position + Direction; } else @@ -83,7 +84,7 @@ class HandleRotation { if (Rotation == 90) { - Direction = new Vector2(-1, 0) * crops.getSpeedFactor(tractorSpeed); + Direction = new Vector2(-1, 0) * movementSpeed; Position = Position + Direction; } else @@ -111,4 +112,19 @@ class HandleRotation { return Rotation; } + + public bool checkTile(Vector2 Position, int tileSize, int Spacing, float tractorSpeed, Crops crop) + { + Vector2 newTile = new Vector2((float)Math.Round(Position.X / (tileSize + Spacing)), (float)Math.Round(Position.Y / (tileSize + Spacing))); + if (oldTile != newTile) + { + oldTile = newTile; + movementSpeed = crop.getSpeedFactor(tractorSpeed); + return true; + } + else + { + return false; + } + } } diff --git a/Game1/Sources/Objects/Tractor.cs b/Game1/Sources/Objects/Tractor.cs index f2768a3..86c9ac1 100644 --- a/Game1/Sources/Objects/Tractor.cs +++ b/Game1/Sources/Objects/Tractor.cs @@ -39,7 +39,7 @@ class Tractor private void updateDirection(Vector2 Size, Vector2 newPosition) { DeltaPosition = TargetPosition - Position; - + handleRotation.checkTile(Position, sizeTile, Spacing, tractorSpeed, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing)))); if (DeltaPosition.X == 0) { From e4d2086bf9d1547a95e175c7afc753742602ce42 Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 10 May 2020 21:07:03 +0200 Subject: [PATCH 3/3] Fix --- Game1/Sources/Objects/HandleRotation.cs | 11 ++++++----- Game1/Sources/Objects/Tractor.cs | 2 +- Game1/Sources/Smart/SmartTractor.cs | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Game1/Sources/Objects/HandleRotation.cs b/Game1/Sources/Objects/HandleRotation.cs index 2d11dde..404a4a2 100644 --- a/Game1/Sources/Objects/HandleRotation.cs +++ b/Game1/Sources/Objects/HandleRotation.cs @@ -5,7 +5,7 @@ class HandleRotation { int rotationSpeed = 5, Rotation = 180; private float oldSpeed, movementSpeed; - private Vector2 oldTile; + private Vector2 oldTile, oldPosition; public Vector2 UpdatePosition(int Destination, float tractorSpeed, Vector2 Position, Crops crops) { @@ -14,7 +14,7 @@ class HandleRotation { Position = new Vector2((int)Math.Round(Position.X), (int)Math.Round(Position.Y)); } - if (Destination == 0) + if (Destination == 0) // down { if (Rotation == 0) { @@ -37,7 +37,7 @@ class HandleRotation } } } - else if (Destination == 1) + else if (Destination == 1) // up { if (Rotation == 180) { @@ -57,7 +57,7 @@ class HandleRotation } } - else if (Destination == 2) + else if (Destination == 2) // right { if (Rotation == 270) { @@ -80,7 +80,7 @@ class HandleRotation } } } - else if (Destination == 3) + else if (Destination == 3) // left { if (Rotation == 90) { @@ -105,6 +105,7 @@ class HandleRotation } oldSpeed = crops.getSpeedFactor(tractorSpeed); + oldPosition = Position; return Position; } diff --git a/Game1/Sources/Objects/Tractor.cs b/Game1/Sources/Objects/Tractor.cs index 86c9ac1..66fa73d 100644 --- a/Game1/Sources/Objects/Tractor.cs +++ b/Game1/Sources/Objects/Tractor.cs @@ -32,7 +32,7 @@ class Tractor Spacing = input.getSpacing(); Position = housePos; TargetPosition = new Vector2(house.X, house.Y); - smartTractor.init(); + smartTractor.init(new Vector2(house.X, house.Y)); } // Runs when the tractor reaches a tile diff --git a/Game1/Sources/Smart/SmartTractor.cs b/Game1/Sources/Smart/SmartTractor.cs index 4524778..d111af2 100644 --- a/Game1/Sources/Smart/SmartTractor.cs +++ b/Game1/Sources/Smart/SmartTractor.cs @@ -46,9 +46,10 @@ class SmartTractor } - public void init() + public void init(Vector2 nHousePos) { ai.init(); + housePos = nHousePos; farm.init(new Vector2(100, (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / tileSize) - 125 / tileSize), housePos / (tileSize + Spacing)); }