1
0
forked from s425077/PotatoPlan

Somewhat finished

This commit is contained in:
Joel 2020-05-10 19:21:52 +02:00
parent f39f27ba4e
commit 913f813895
4 changed files with 70 additions and 23 deletions

View File

@ -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
}
}
}

View File

@ -112,12 +112,15 @@ class Farm
for (int i = 0; i < Size.X; i++)
{
for (int j = 0; j < Size.X; j++)
{
if (crops[i, j].getStatus() != 3)
{
int x = getHighestProductionRate(i, j);
crops[i, j].setCropType(x, PresetCrops.getPresetCropTypes(x));
}
}
}
}
private int getHighestProductionRate(int x, int y)
{

View File

@ -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;
}

View File

@ -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
{