Inheritance: Base
Example #1
0
 void AcceptIncomingSpore(Spore incomingSpore, PlanetSettings.Allegiance sourceAllegiance)
 {
     if (myAllegiance.myAllegiance == sourceAllegiance ||
         myAllegiance.myAllegiance == PlanetSettings.Allegiance.unclaimed)
     {
         incomingSpore.ChangeOwnership(this);
         AddSpore(incomingSpore);
         if (myAllegiance.myAllegiance == PlanetSettings.Allegiance.unclaimed)
         {
             myAllegiance.ChangeAllegiance(sourceAllegiance);
         }
     }
     else
     {
         if (mySpores.Count > 0)
         {
             var finalSporeIndex = mySpores.Count - 1;
             var defendingSpore  = mySpores[finalSporeIndex];
             mySpores.RemoveAt(finalSporeIndex);
             incomingSpore.AttackOtherSpore(defendingSpore);
         }
         else
         {
             myAllegiance.ChangeAllegiance(sourceAllegiance);
         }
     }
 }
Example #2
0
 public void ReturnSporeToPool(Spore sporeToReturn)
 {
     if (!sporeToReturn)
     {
         return;
     }
     sporeToReturn.transform.parent = transform;
     sporeToReturn.gameObject.SetActive(false);
 }
Example #3
0
 public void Retire(Spore obj)
 {
     if (stack.Count < maxSize)
     {
         stack.Push(obj);
     }
     else
     {
         Destroy(obj.gameObject);
     }
 }
Example #4
0
 public void AttackOtherSpore(Spore opponentSpore)
 {
     parentPlanet       = null;
     this.opponentSpore = opponentSpore;
     opponentSpore.GetAttackedByOtherSpore(this);
     //myRigidbody.AddForce(
     //    opponentSpore.transform.position -
     //    transform.position *
     //    SporeSettings.instance.AttackSpeedInitial
     //);
 }
Example #5
0
    async Task Destroy()
    {
        beingDestroyed = true;
        await Task.Delay(TimeSpan.FromSeconds(SporeSettings.instance.SporeLifetime));

        SporePool.instance.ReturnSporeToPool(this);
        opponentSpore.opponentSpore = null;
        SporePool.instance.ReturnSporeToPool(opponentSpore);
        opponentSpore  = null;
        beingDestroyed = false;
    }
Example #6
0
 public Spore GetSpore()
 {
     if (stack.Count == 0)
     {
         Spore spore = Instantiate(prefab).GetComponent <Spore>();
         spore.Setup(roomController.wallColliders, GameController.Main.combatSettings);
         return(spore);
     }
     else
     {
         return(stack.Pop());
     }
 }
Example #7
0
    void OnTriggerEnter2D(Collider2D other)
    {
        Seed  seed  = other.GetComponent <Seed>();
        Spore spore = other.GetComponent <Spore>();

        if (null != seed && seed.IsCaptured)
        {
            return;
        }

        if ((IsFertil || GameManager.Instance.IsNewFlowerReplaceOldOne) && null != seed)
        {
            seed.IsCaptured = true;

            int previousLevel = 0;

            if (GameManager.Instance.IsNewFlowerReplaceOldOne)
            {
                if (null != PlantedFlower)
                {
                    FlowerRoot flower     = PlantedFlower.GetComponent <FlowerRoot>();
                    FlowerRoot seedFlower = seed.Flower.GetComponent <FlowerRoot>();

                    if (flower.Level == seedFlower.Level && flower.GrowthLevel < 3)
                    {
                        previousLevel = flower.GrowthLevel;
                        PlantedFlower.GetComponent <FlowerRoot>().Kill();
                        CreateTheFlower(seed, previousLevel + 1, this.transform);
                    }
                }
                else
                {
                    CreateTheFlower(seed, 1, this.transform);
                }

                seed.StopFade();
                ScaleObject scale = seed.gameObject.AddComponent <ScaleObject>();
                scale.GetComponent <Rigidbody2D>().isKinematic = true;
                scale.Scale(0.2f, Vector3.zero, true, Center.position, AbsorbIsFinish);
            }
        }

        if (null != spore)
        {
            if ((Time.time - spore.BirthTime) > 1f)
            {
                spore.Kill();
            }
        }
    }
Example #8
0
    void OnCollisionEnter2D(Collision2D coll)
    {
        Seed seed = coll.gameObject.GetComponent <Seed>();

        if (null != seed)
        {
            coll.gameObject.GetComponent <Rigidbody2D>().AddForce(Vector2.up * 2f);
            GameObject.Destroy(coll.gameObject, 0.4f);
        }
        Spore spore = coll.gameObject.GetComponent <Spore>();

        if (null != spore && spore.IsFlying)
        {
            spore.Kill();
        }
    }
Example #9
0
    void OnCollisionEnter2D(Collision2D coll)
    {
        Seed seed = coll.gameObject.GetComponent <Seed>();

        if (null != seed)
        {
            coll.gameObject.GetComponent <Rigidbody2D>().AddForce(Vector2.up * 0.1f);
            seed.Kill();
        }
        Spore spore = coll.gameObject.GetComponent <Spore>();

        if (null != spore && spore.IsFlying)
        {
            if ((Time.time - spore.BirthTime) > 1f)
            {
                spore.Kill();
            }
        }
    }
Example #10
0
    public void CreateSeed(Spore s1, Spore s2)
    {
        if (s1.Level == s2.Level && s1.Flower != s2.Flower && !s1.HasCollided && !s2.HasCollided)
        {
            s1.HasCollided = true;
            s2.HasCollided = true;
            int newLevel = s1.Level + 1;
            if (newLevel < Flowers.Length)
            {
                GameObject go = GameObject.Instantiate(Seeds[newLevel]);
                go.transform.position = s1.transform.position;
                var component = GameObject.FindGameObjectWithTag("SFXPlayerPollen").GetComponent <FX>();
                component.PlaySound();
            }

            s1.Kill();
            s2.Kill();

            /*foreach (var seedSpawn in s1.Flower.SeedSpawns)
             * {
             *   foreach (Transform child in seedSpawn.transform)
             *   {
             *
             *       GameObject.Destroy(child.gameObject);
             *   }
             * }
             * foreach (var seedSpawn in s2.Flower.SeedSpawns)
             * {
             *   foreach (Transform child in seedSpawn.transform)
             *   {
             *
             *       GameObject.Destroy(child.gameObject);
             *   }
             * }*/
        }
        else
        {
            Physics2D.IgnoreCollision(s1.GetComponent <Collider2D>(), s2.GetComponent <Collider2D>());
        }
    }
Example #11
0
 void AddSpore(Spore sporeToAdd)
 {
     mySpores.Add(sporeToAdd);
     countText.text = mySpores.Count.ToString();
 }
Example #12
0
 public void GetAttackedByOtherSpore(Spore attackingSpore)
 {
     parentPlanet  = null;
     opponentSpore = attackingSpore;
 }
Example #13
0
    public void CreateSeed(Spore s1, Spore s2)
    {
        if (s1.Level == s2.Level && s1.Flower != s2.Flower && !s1.HasCollided && !s2.HasCollided)
        {
            //print("Level created = " + s1.Level);
            if (s1.Level == 0 && TutoSecondStep)
            {
                TutoSecondStep = false;
                var findGameObjectsWithTag = GameObject.FindGameObjectsWithTag("TutoTwo");
                foreach (var o in findGameObjectsWithTag)
                {
                    Image image = o.GetComponent <Image>();
                    if (image == null)
                    {
                        Destroy(o);
                    }
                    else
                    {
                        image.gameObject.SendMessage(FadeTutorial.DESACTIVATE_TUTORIAL);
                    }
                }
            }
            s1.HasCollided = true;
            s2.HasCollided = true;
            int newLevel = s1.Level + 1;
            if (newLevel < Flowers.Length)
            {
                GameObject go = GameObject.Instantiate(Seeds[newLevel]);
                go.transform.position = s1.transform.position;
                var direction = go.transform.position - PlanetObject.position;
                direction.Normalize();
                go.GetComponent <Rigidbody2D>().velocity = direction * 2f;
                go.GetComponent <Seed>().firstParent     = s1.FlowerHead;
                go.GetComponent <Seed>().secondParent    = s2.FlowerHead;
                go.GetComponent <Seed>().AnimatCircle();
                var component = GameObject.FindGameObjectWithTag("SFXPlayerPollen").GetComponent <FX>();
                component.PlaySound();
            }

            s1.Kill();
            s2.Kill();

            /*foreach (var seedSpawn in s1.Flower.SeedSpawns)
             * {
             *   foreach (Transform child in seedSpawn.transform)
             *   {
             *
             *       GameObject.Destroy(child.gameObject);
             *   }
             * }
             * foreach (var seedSpawn in s2.Flower.SeedSpawns)
             * {
             *   foreach (Transform child in seedSpawn.transform)
             *   {
             *
             *       GameObject.Destroy(child.gameObject);
             *   }
             * }*/
        }
        else
        {
            Physics2D.IgnoreCollision(s1.GetComponent <Collider2D>(), s2.GetComponent <Collider2D>());
        }
    }
Example #14
0
    //update
    void FixedUpdate()
    {
        //cause death if below water level
        if (transform.position.y < MainGameHandler.waterLevel)
        {
            MainGameHandler.creatures.Remove(gameObject);
            Destroy(gameObject);
        }

        //handle joint simulation
        age++;
        if (age >= maxAge)
        {
            MainGameHandler.creatures.Remove(gameObject);
            Destroy(gameObject);
        }

        //handle if plant
        if (creatureType.Equals(MainGameHandler.CreatureType.Plant))
        {
            //handle reproduction
            reproductionValue++;

            if (reproductionValue >= 250)
            {
                GameObject spore = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                spore.name = "Spore";
                spore.transform.position   = transform.position;
                spore.transform.localScale = new Vector3(0.5F, 0.5F, 0.5F);

                Spore     sporeScript = spore.AddComponent <Spore>();
                Rigidbody body        = spore.AddComponent <Rigidbody>();
                body.mass = 0.035F;

                reproductionValue = 0;
            }

            //handle height gain
            height += 0.005F;
            gameObject.transform.localScale = new Vector3(2, height, 2);

            //handle energy usage/creation
            int sunMod = 1 - MainGameHandler.currentTimeOfDay / 360;
            if (MainGameHandler.waterLevel > 1)
            {
                MainGameHandler.waterLevel -= 0.0005F;
                energy += 1 + 1 * sunMod;
            }
            energy--;
            if (energy <= 40)
            {
                gameObject.GetComponent <Renderer>().material.color = Color.yellow;
            }
            if (energy <= 0)
            {
                MainGameHandler.creatures.Remove(gameObject);
                Destroy(gameObject);
            }
        }
        else //handle if animal
        {
            transform.LookAt(targetPosition);
            Rigidbody body = transform.GetComponent <Rigidbody>();
            body.AddForce(new Vector3(0, 0, speed + body.mass), ForceMode.Force);
        }
    }
    // Update is called once per frame
    void Update()
    {
        timer -= Time.deltaTime;
        switch (behaviorState)
        {
        case BehaviorState.Idle:
            if (timer <= 0.0f)
            {
                if (lastAtk == LastAttack.None || lastAtk == LastAttack.SporeAttack)
                {
                    // todo: calculate timer based on hp
                    timer         = 10.0f;
                    target        = TOP_SCREEN_LOC;
                    behaviorState = BehaviorState.DropRocksAttack;
                }
                else
                {
                    timer         = 10.0f;
                    currCornerInd = TOP_LEFT_IND;
                    target        = corners[currCornerInd];
                    behaviorState = BehaviorState.SporeAttack;
                }
            }
            break;

        case BehaviorState.GoToIdlePos:
            if (closeEnoughToTarget())
            {
                timer         = IDLE_TIME;
                behaviorState = BehaviorState.Idle;
            }
            else
            {
                target = IDLE_TARGET_LOC;
                move();
            }
            break;

        case BehaviorState.DropRocksAttack:
            lastAtk      = LastAttack.DropsRocksAttack;
            attackTimer -= Time.deltaTime;
            if (timer <= 0.0f)
            {
                target        = IDLE_TARGET_LOC;
                behaviorState = BehaviorState.GoToIdlePos;
            }
            else
            {
                if (!closeEnoughToTarget())
                {
                    // move to top of screen
                    move();
                }
                else
                {
                    // oscillate between left and right of screen
                    // todo: have it check if collided instead
                    target = new Vector3(9 * direction, 3.5f);
                    if (transform.position.x <= -8.0f)
                    {
                        direction = 1;
                    }
                    if (transform.position.x >= 8.0f)
                    {
                        direction = -1;
                    }
                }
                if (attackTimer <= 0.0f)
                {
                    GameObject aBoulder = boulderPooler.GetDanmaku(boulderIndex);
                    aBoulder.SetActive(true);
                    if (aBoulder != null)
                    {
                        Boulder boulderScript = aBoulder.GetComponent <Boulder>();
                        aBoulder.transform.position = gameObject.transform.position;
                    }
                    // reset the timer
                    attackTimer = DROP_ROCK_INTERVAL;
                }
            }
            break;

        case BehaviorState.SporeAttack:
            lastAtk      = LastAttack.SporeAttack;
            attackTimer -= Time.deltaTime;

            if (!closeEnoughToTarget())
            {
                // move to corner of screen
                move();
            }
            else
            {
                // switch to next target
                if (currCornerInd < cornersLen - 1)
                {
                    currCornerInd += 1;
                    target         = corners[currCornerInd];
                }
                else
                {
                    target        = IDLE_TARGET_LOC;
                    behaviorState = BehaviorState.GoToIdlePos;
                }
            }
            if (attackTimer <= 0.0f)
            {
                // let a spore loose
                GameObject aSpore = boulderPooler.GetDanmaku(sporeIndex);
                aSpore.SetActive(true);
                if (aSpore != null)
                {
                    Spore boulderScript = aSpore.GetComponent <Spore>();
                    aSpore.transform.position = gameObject.transform.position;
                }
                // reset the timer
                attackTimer = EXCRETE_SPORE;
            }
            break;
        }
    }