added Tiles, basic TileBehaviour

This commit is contained in:
j-weissen 2022-05-18 22:53:23 +02:00
parent 66756be23b
commit 433158e658
8 changed files with 100 additions and 7 deletions

View file

@ -13,7 +13,7 @@ GameObject:
- component: {fileID: 4752245148499717903}
- component: {fileID: 4752245148499717900}
m_Layer: 0
m_Name: GrassTile
m_Name: BaseTile
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

View file

@ -1,14 +1,18 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Tiles;
using UnityEngine;
public class GrassTile : MonoBehaviour
public class TileBehaviour : MonoBehaviour
{
private BaseTile tile;
// Start is called before the first frame update
void Start()
{
Debug.Log("Created");
SetTile(new GrassTile());
}
// Update is called once per frame
@ -20,5 +24,12 @@ public class GrassTile : MonoBehaviour
void OnMouseDown()
{
Debug.Log("Clicked");
tile.Clicked(/* Current tool */ null);
}
void SetTile(BaseTile tileToSet)
{
tile = tileToSet;
GetComponent<SpriteRenderer>().color = tile.getColor;
}
}

View file

@ -35,4 +35,6 @@ public class TileController : MonoBehaviour
{
}
}

View file

@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Tiles
{
public abstract class BaseTile
{
protected Color color;
public Color getColor => color;
// Later to be replaced with
// public Sprite sprite;
protected BaseTile(Color color)
{
this.color = color;
}
protected void Start()
{
}
protected void Update()
{
}
public void DayLightStep()
{
}
public void Clicked(UsableItem usable)
{
Debug.Log(usable.ToString() + " used on " + this.ToString());
}
}
}

View file

@ -0,0 +1,12 @@
using UnityEngine;
namespace Tiles
{
public class FarmlandTile : BaseTile
{
public FarmlandTile() : base(Color.black)
{
}
}
}

View file

@ -0,0 +1,12 @@
using UnityEngine;
namespace Tiles
{
public class GrassTile : BaseTile
{
public GrassTile() : base(Color.green)
{
}
}
}

View file

@ -0,0 +1,12 @@
using UnityEngine;
namespace Tiles
{
public class WaterTile : BaseTile
{
public WaterTile() : base(Color.blue)
{
}
}
}

View file

@ -16,10 +16,12 @@ public class UsableItem : Item, IUsable
}
public UsableItem(string displayName, string description, int id) : base(displayName, description, id) {
}
public UsableItem(string displayName, string description, int id) : base(displayName, description, id)
{
}
public void select() {
PlayerController.getInstance().setSelectedItem(this);
public void select()
{
PlayerController.getInstance().setSelectedItem(this);
}
}
}