Skip to content
Snippets Groups Projects
Commit 370ba7bc authored by Leevi Grönlund's avatar Leevi Grönlund
Browse files

BerryBush respawn style changed etc

parent 7d7005de
No related branches found
No related tags found
No related merge requests found
......@@ -4,32 +4,51 @@ using UnityEngine;
public class BerryBush : Resource
{
private float growthspeed;
public bool coroutineRunning =false;
public override void checkExistence()
{
if (!coroutineRunning)
{
StartCoroutine("timer");
coroutineRunning = true;
}
}
private IEnumerator timer()
{
yield return new WaitForSeconds(3);
setAmount(500);
coroutineRunning = false;
}
public override void setAmount(int i)
{
base.setAmount(i);
}
public override void refreshSprite()
{
if (getAmount() < 100)
if (getAmount() < 1)
{
gameObject.GetComponent<SpriteRenderer>().sprite = sprites[5];
}
else if (getAmount() < 200)
else if (getAmount() < 100)
{
gameObject.GetComponent<SpriteRenderer>().sprite = sprites[4];
}
else if (getAmount() < 300)
else if (getAmount() < 200)
{
gameObject.GetComponent<SpriteRenderer>().sprite = sprites[3];
}
else if (getAmount() < 400)
else if (getAmount() < 300)
{
gameObject.GetComponent<SpriteRenderer>().sprite = sprites[2];
}
else if (getAmount() < 500)
else if (getAmount() < 400)
{
gameObject.GetComponent<SpriteRenderer>().sprite = sprites[1];
}
......@@ -42,18 +61,7 @@ public class BerryBush : Resource
// Start is called before the first frame update
void Start()
{
setAmount(Random.Range(50, 200));
growthspeed = 1;
StartCoroutine("Grow");
}
IEnumerator Grow()
{
while (getAmount() < 600)
{
setAmount(getAmount() + 1);
yield return new WaitForSeconds(growthspeed);
}
setAmount(500);
}
// Update is called once per frame
......@@ -61,4 +69,5 @@ public class BerryBush : Resource
{
}
}
......@@ -3,10 +3,39 @@ using System.Collections.Generic;
using UnityEngine;
// Luokka, joka vaatii collectoreilta 100 puuta ennen kuin Quarry voidaan luoda samaan pisteeseen kartalla
public class Outcrop : Resource
public class Outcrop : MonoBehaviour
{
public override void checkExistence() { }
public override void refreshSprite() { }
[SerializeField]
private int wood;
[SerializeField]
private GameObject quarry;
public int getAmount()
{
return wood;
}
public void setAmount(int amount)
{
wood += amount;
}
public void checkExistence()
{
if (getAmount() >= 100)
{
GameObject go = Instantiate<GameObject>(quarry);
go.transform.position = this.transform.position;
Destroy(gameObject);
}
}
public void addResource(int amount)
{
setAmount(getAmount() + amount);
checkExistence();
}
// Start is called before the first frame update
void Start()
......@@ -22,4 +51,5 @@ public class Outcrop : Resource
// luo Quarry -olio samaan pisteeseen kartalla ja tuhoa Outcrop -olio
}
}
}
......@@ -44,6 +44,7 @@ public class Quarry : Resource
// Start is called before the first frame update
void Start()
{
setAmount(Random.Range(2000, 4000));
}
......
......@@ -7,14 +7,27 @@ public abstract class Resource : MonoBehaviour
[SerializeField]
private int resources;
[SerializeField]
private bool resourceSource;
[SerializeField]
protected Sprite[] sprites;
public bool isResourceSource()
{
return resourceSource;
}
public void setResourceSource(bool i)
{
resourceSource = i;
}
public void setAmount(int i)
public virtual void setAmount(int i)
{
resources = i;
refreshSprite();
checkExistence();
}
public int getAmount()
......@@ -27,16 +40,12 @@ public abstract class Resource : MonoBehaviour
if (resources-amount < 0)
{
int r = resources;
resources = 0;
refreshSprite();
checkExistence();
setAmount(0);
return r;
}
else
{
resources = resources - amount;
refreshSprite();
checkExistence();
setAmount(resources - amount);
return amount;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment