added Player GameObject, updated GrassTile.Clicked()

This commit is contained in:
j-weissen 2022-05-18 23:59:49 +02:00
parent 433158e658
commit 4612938b54
5 changed files with 76 additions and 5 deletions

View file

@ -7,7 +7,9 @@ public class PlayerController : MonoBehaviour {
private Dictionary<Item, int> inventory;
private int money;
private UsableItem selectedItem;
public UsableItem SelectedItem => selectedItem;
private static PlayerController instance;
public int startMoney = 100;
@ -39,4 +41,6 @@ public class PlayerController : MonoBehaviour {
Debug.Log("An item requested to select isn't in the inventory" + item);
}
}
}

View file

@ -24,12 +24,18 @@ public class TileBehaviour : MonoBehaviour
void OnMouseDown()
{
Debug.Log("Clicked");
tile.Clicked(/* Current tool */ null);
// SelectedItem always null for now
BaseTile temp = tile.Clicked(PlayerController.getInstance().SelectedItem);
if (temp != null)
{
SetTile(temp);
}
}
void SetTile(BaseTile tileToSet)
{
tile = tileToSet;
GetComponent<SpriteRenderer>().color = tile.getColor;
GetComponent<SpriteRenderer>().color = tile.getColor; // TODO: Change to Sprite
}
}

View file

@ -9,7 +9,7 @@ namespace Tiles
{
protected Color color;
public Color getColor => color;
// Later to be replaced with
// TODO: Change to Sprite, also in subclasses
// public Sprite sprite;
protected BaseTile(Color color)
@ -32,9 +32,10 @@ namespace Tiles
}
public void Clicked(UsableItem usable)
public BaseTile Clicked(UsableItem usable)
{
Debug.Log(usable.ToString() + " used on " + this.ToString());
return null;
}

View file

@ -8,5 +8,20 @@ namespace Tiles
{
}
/// <summary>
/// to be invoked when the Tile is clicked, handles the actions following on the click
/// </summary>
/// <param name="usable">the UsableItem that the Tile was clicked on with</param>
/// <returns>a subclass of BaseTile if the Tile has to change, null if it stays the same type</returns>
new public BaseTile Clicked(UsableItem usable) {
base.Clicked(usable);
BaseTile rv = null;
if (usable.GetType() == typeof(Items.Hoe))
{
rv = new FarmlandTile();
}
return rv;
}
}
}