Beispiel #1
0
    public void StartNewGame()
    {
        if (melonArea == null)
        {
            melonArea = GameObject.FindGameObjectWithTag("MelonArea").GetComponent <BoxArea>();
        }

        if (melons != null && melons.Length > 0)
        {
            for (int i = 0; i < melons.Length; i++)
            {
                if (melons[i] != null)
                {
                    Destroy(melons[i].gameObject);
                }
            }
        }

        melons = new Watermelon[melonCount];
        for (int i = 0; i < melonCount; i++)
        {
            melons[i] = Instantiate(melonPrefabs[Random.Range(0, melonPrefabs.Length)].gameObject).GetComponent <Watermelon>();
            if (i == 0 && (melons[i].Maturity > 1.2f || melons[i].Maturity < 0.8f))
            {
                Destroy(melons[i].gameObject);
                i--;
                continue;
            }

            melons[i].transform.localScale = Vector3.one * Random.Range(melonScaleRange.x, melonScaleRange.y);
            melons[i].transform.rotation   = Quaternion.Euler(0, 0, Random.value * 180 - 90);

            Vector3 pos = Vector3.zero;
            for (int j = 0; j < 100; j++)
            {
                pos = melonArea.GetRandomPoint();
                bool foundSuitablePos = true;
                foreach (var m in melons)
                {
                    if (m == null)
                    {
                        break;
                    }
                    if (((Vector2)(m.transform.position - pos)).sqrMagnitude < melonDistance * melonDistance)
                    {
                        foundSuitablePos = false;
                        break;
                    }
                }

                if (foundSuitablePos)
                {
                    break;
                }
            }

            pos.z = pos.y;
            melons[i].transform.position = pos;
        }
    }
Beispiel #2
0
        private void RegisterBox(BoxType key1, BoxArea key2, GameObject boxGameObject)
        {
            int hash = 0;

            Hash(ref hash, key1, key2);

            boxDictionary.Add(hash, boxGameObject);
        }
Beispiel #3
0
        public Box GetBox(BoxType key1, BoxArea key2)
        {
            Box box = null;

            if (GetGameBox(key1, key2) != null)
            {
                box = GetGameBox(key1, key2).GetComponent <Box>();
            }
            return(box);
        }
Beispiel #4
0
        public GameObject GetGameBox(BoxType key1, BoxArea key2)
        {
            int hash = 0;

            Hash(ref hash, key1, key2);

            if (boxDictionary.ContainsKey(hash))
            {
                return(boxDictionary[hash]);
            }
            return(null);
        }
Beispiel #5
0
        private void Hash(ref int hashValue, BoxType key1, BoxArea key2)
        {
            switch (key1)
            {
            case BoxType.Hitbox:
                hashValue += (int)key1 * 1;
                break;

            case BoxType.Hurtbox:
                hashValue += (int)key1 * 200;
                break;

            case BoxType.GroundBox:
                hashValue += (int)key1 * 2000;
                break;

            default:
                break;
            }

            hashValue += (int)key2;
        }
Beispiel #6
0
 private void OnEnable()
 {
     area = (BoxArea)target;
 }
Beispiel #7
0
 private void Awake()
 {
     spawnArea = GetComponent <BoxArea>();
 }