extended usable Items with UsableItem
This commit is contained in:
parent
fb9aa4e349
commit
0d49c92c15
8 changed files with 21 additions and 26 deletions
|
|
@ -1,17 +1,22 @@
|
||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Item : MonoBehaviour {
|
public class Item : MonoBehaviour, IComparable<Item> {
|
||||||
private string displayName;
|
private readonly string displayName;
|
||||||
private string description;
|
private readonly string description;
|
||||||
private int id; //TODO: create an actual ID System that makes snens
|
private readonly int id; //TODO: create an actual ID System that makes snens
|
||||||
public SpriteRenderer spriteRenderer;
|
public SpriteRenderer spriteRenderer;
|
||||||
public Sprite selectedSprite;
|
public Sprite selectedSprite;
|
||||||
public Sprite defaultSprite;
|
public Sprite defaultSprite;
|
||||||
|
|
||||||
public Item(string displayName, string description, int id) {
|
public Item(string displayName, string description, int id) {
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
spriteRenderer.sprite ??= defaultSprite; // defaultSprite is set in UnityEditor
|
spriteRenderer.sprite ??= defaultSprite; // defaultSprite is set in UnityEditor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int CompareTo(Item other) {
|
||||||
|
return this.id - other.id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,7 @@
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Items {
|
namespace Items {
|
||||||
public class FishingRod : Item, IUsable {
|
public class FishingRod : UsableItem {
|
||||||
public FishingRod() : base("Fishing Rod", "Can be used to fish fishy fish.", 1) { }
|
public FishingRod() : base("Fishing Rod", "Can be used to fish fishy fish.", 1) { }
|
||||||
|
|
||||||
public void select() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Items {
|
namespace Items {
|
||||||
public class Hoe : Item {
|
public class Hoe : UsableItem {
|
||||||
public Hoe() : base("Hoe", "Used to hoe the ground into farmland.", 2){}
|
public Hoe() : base("Hoe", "Used to hoe the ground into farmland.", 2){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Items {
|
namespace Items {
|
||||||
public class Scythe : Item {
|
public class Scythe : UsableItem {
|
||||||
public Scythe() : base("Scythe", "Used to cut down crops.", 3){}
|
public Scythe() : base("Scythe", "Used to cut down crops.", 3){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Items {
|
namespace Items {
|
||||||
public class WateringCan : Item {
|
public class WateringCan : UsableItem {
|
||||||
public WateringCan():base("Watering Can", "Used to water planted crops.", 4){}
|
public WateringCan():base("Watering Can", "Used to water planted crops.", 4){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Items {
|
namespace Items {
|
||||||
public class WheatSeed : Item {
|
public class WheatSeed : UsableItem {
|
||||||
public WheatSeed() : base("Wheat Seeds", "When planted on farmland, wheat will grow.", 6){}
|
public WheatSeed() : base("Wheat Seeds", "When planted on farmland, wheat will grow.", 6){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,33 +6,28 @@ public class PlayerController : MonoBehaviour {
|
||||||
private List<Item> inventory;
|
private List<Item> inventory;
|
||||||
private int money;
|
private int money;
|
||||||
private UsableItem selectedItem;
|
private UsableItem selectedItem;
|
||||||
|
|
||||||
private static PlayerController instance;
|
private static PlayerController instance;
|
||||||
|
|
||||||
public int startMoney = 100;
|
public int startMoney = 100;
|
||||||
|
|
||||||
public static PlayerController getInstance() {
|
public static PlayerController getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start() {
|
||||||
{
|
|
||||||
inventory ??= new List<Item>();
|
inventory ??= new List<Item>();
|
||||||
money = startMoney;
|
money = startMoney;
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update() {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedItem(UsableItem item) {
|
public void setSelectedItem(UsableItem item) {
|
||||||
selectedItem = item;
|
selectedItem = item;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,6 @@ public class UsableItem : Item, IUsable
|
||||||
}
|
}
|
||||||
|
|
||||||
public void select() {
|
public void select() {
|
||||||
throw new System.NotImplementedException();
|
PlayerController.getInstance().setSelectedItem(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue