Crops working
This commit is contained in:
parent
22a4abf927
commit
7ceb7e4bcb
10 changed files with 388 additions and 117 deletions
|
|
@ -9,33 +9,26 @@ namespace Tiles
|
|||
private Sprite _sprite;
|
||||
public Sprite Sprite => _sprite;
|
||||
|
||||
protected BaseTile(String pathToImageFile)
|
||||
protected GameObject _gameObject;
|
||||
|
||||
protected BaseTile(String pathToImageFile, GameObject gameObject)
|
||||
{
|
||||
this._gameObject = gameObject;
|
||||
this._sprite = GenerateSpriteFromFile(pathToImageFile);
|
||||
HouseController.NewDayEvent.AddListener(DayLightStep);
|
||||
}
|
||||
|
||||
protected void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void DayLightStep()
|
||||
public virtual void DayLightStep()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual BaseTile Clicked(UsableItem usable)
|
||||
{
|
||||
Debug.Log(usable.ToString() + " used on " + this.ToString());
|
||||
return null;
|
||||
}
|
||||
|
||||
static protected Sprite GenerateSpriteFromFile(String pathToImageFile)
|
||||
static public Sprite GenerateSpriteFromFile(String pathToImageFile)
|
||||
{
|
||||
byte[] data = File.ReadAllBytes(pathToImageFile);
|
||||
Texture2D texture = new Texture2D(32, 32, TextureFormat.ARGB32, false);
|
||||
|
|
|
|||
|
|
@ -6,52 +6,23 @@ namespace Tiles
|
|||
{
|
||||
private Crop _crop;
|
||||
|
||||
public FarmlandTile() : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_008.png")
|
||||
public FarmlandTile(GameObject gameObject) : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_008.png", gameObject)
|
||||
{
|
||||
_crop = null;
|
||||
_crop = new Crop(gameObject.transform.GetChild(1).GetComponent<SpriteRenderer>(),
|
||||
gameObject.transform.GetChild(0).GetComponent<SpriteRenderer>());
|
||||
}
|
||||
|
||||
public override void DayLightStep()
|
||||
{
|
||||
_crop.DayLightStep();
|
||||
}
|
||||
|
||||
public new void DayLightStep()
|
||||
{
|
||||
}
|
||||
|
||||
public new BaseTile Clicked(UsableItem usable)
|
||||
public override BaseTile Clicked(UsableItem usable)
|
||||
{
|
||||
base.Clicked(usable);
|
||||
|
||||
ItemContainer ic = ItemContainer.Instance;
|
||||
|
||||
if (usable.id == ic.GetItemIdByName("Hoe"))
|
||||
{
|
||||
Debug.Log("Farmland hydrated");
|
||||
//_hydrated = true;
|
||||
}
|
||||
_crop.Clicked(usable);
|
||||
|
||||
if (usable.id == ic.GetItemIdByName("Wheat Seed") && _crop == null)
|
||||
{
|
||||
Plant();
|
||||
}
|
||||
|
||||
if (usable.id == ic.GetItemIdByName("Scythe") && _crop != null && _crop.FullyGrown)
|
||||
{
|
||||
Harvest();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void Harvest()
|
||||
{
|
||||
Debug.Log("Farmland harvested");
|
||||
// add wheat to inventory
|
||||
_crop = null;
|
||||
}
|
||||
|
||||
private void Plant()
|
||||
{
|
||||
Debug.Log("Farmland planted");
|
||||
// wheatSeeds-- in inventory
|
||||
_crop = new Crop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ namespace Tiles
|
|||
{
|
||||
public class GrassTile : BaseTile
|
||||
{
|
||||
public GrassTile() : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_000.png")
|
||||
public GrassTile(GameObject gameObject) : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_000.png", gameObject)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ namespace Tiles
|
|||
base.Clicked(usable);
|
||||
if (usable.id == ItemContainer.Instance.GetItemIdByName(new string("Hoe")))
|
||||
{
|
||||
rv = new FarmlandTile();
|
||||
rv = new FarmlandTile(_gameObject);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ namespace Tiles
|
|||
{
|
||||
public class WaterTile : BaseTile
|
||||
{
|
||||
public WaterTile() : base(null)
|
||||
public WaterTile() : base(null, null)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue