From 97e3ed9a1cdcbaf33a60d715caa4afea0bf7cbab Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 10 May 2020 21:31:06 +0200 Subject: [PATCH] Fixed dynamic matrix --- Game1/Sources/Crops/Crops.cs | 4 ++++ Game1/Sources/Objects/HandleRotation.cs | 13 +++++++++---- Game1/Sources/Objects/Tractor.cs | 8 ++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Game1/Sources/Crops/Crops.cs b/Game1/Sources/Crops/Crops.cs index b89a402..a3560b1 100644 --- a/Game1/Sources/Crops/Crops.cs +++ b/Game1/Sources/Crops/Crops.cs @@ -142,6 +142,10 @@ class Crops } else { + if (cropType == 0) + { + return 16; //Barley + } if (cropType == 1) { return 16; //Barley diff --git a/Game1/Sources/Objects/HandleRotation.cs b/Game1/Sources/Objects/HandleRotation.cs index 404a4a2..acde830 100644 --- a/Game1/Sources/Objects/HandleRotation.cs +++ b/Game1/Sources/Objects/HandleRotation.cs @@ -5,11 +5,12 @@ class HandleRotation { int rotationSpeed = 5, Rotation = 180; private float oldSpeed, movementSpeed; - private Vector2 oldTile, oldPosition; + private Vector2 oldTile, oldPosition, oldMovementSpeed; + private Vector2 Direction; - public Vector2 UpdatePosition(int Destination, float tractorSpeed, Vector2 Position, Crops crops) + public Vector2 UpdatePosition(int Destination, float tractorSpeed, Vector2 Position, Crops crops, Vector2 oldDeltaPosition, Vector2 Target) { - Vector2 Direction; + if (oldSpeed != crops.getSpeedFactor(tractorSpeed)) { Position = new Vector2((int)Math.Round(Position.X), (int)Math.Round(Position.Y)); @@ -105,7 +106,11 @@ class HandleRotation } oldSpeed = crops.getSpeedFactor(tractorSpeed); - oldPosition = Position; + if (oldDeltaPosition.X < 1 && oldDeltaPosition.X > -1 && oldDeltaPosition.Y < 1 && oldDeltaPosition.Y > -1) + { + Position = Target; + } + oldMovementSpeed = Direction; return Position; } diff --git a/Game1/Sources/Objects/Tractor.cs b/Game1/Sources/Objects/Tractor.cs index 66fa73d..21a5a66 100644 --- a/Game1/Sources/Objects/Tractor.cs +++ b/Game1/Sources/Objects/Tractor.cs @@ -49,20 +49,20 @@ class Tractor } else if (DeltaPosition.Y > 0) { - Position = handleRotation.UpdatePosition(0, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing)))); + Position = handleRotation.UpdatePosition(0, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))), DeltaPosition, TargetPosition); } else if (DeltaPosition.Y < 0) { - Position = handleRotation.UpdatePosition(1, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing)))); + Position = handleRotation.UpdatePosition(1, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))), DeltaPosition, TargetPosition); } } else if (DeltaPosition.X > 0) { - Position = handleRotation.UpdatePosition(2, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing)))); + Position = handleRotation.UpdatePosition(2, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))), DeltaPosition, TargetPosition); } else if (DeltaPosition.X < 0) { - Position = handleRotation.UpdatePosition(3, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing)))); + Position = handleRotation.UpdatePosition(3, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))), DeltaPosition, TargetPosition); } }