Example #1
0
    public Particle RequestParticle(sSubstance substanceRequested)
    {
        // If the list is empty return null.
        if (notInUse.Count <= 0)
        {
            // Create a new substance for the empty list.
            GameObject substanceInstance = Instantiate(particlePrefab, transform);

            Particle substanceScript = substanceInstance.GetComponent <Particle> ();
            substanceScript.Deactivate();

            notInUse.Add(substanceScript);

            // Debug to increase the number.
            Debug.Log("The object pool went over " + MAX_Particules);
        }

        // Select the first particle.
        Particle particleScript = notInUse [0];

        // Update the list.
        notInUse.Remove(particleScript);
        inUse.Add(particleScript);

        // Activate the substance.
        particleScript.Activate(substanceRequested);

        return(particleScript);
    }
    public bool AddParticule(sSubstance substanceParticule)
    {
        // Update substance if none is inside.
        if (substance == null)
        {
            GreenBackground();

            particules = 1;
            substance  = substanceParticule;
            return(true);
        }
        // Check if there is the right substance.
        else if (substance == substanceParticule)
        {
            GreenBackground();

            particules += 5;
            return(true);
        }
        // Let the player know if the wrong substance is inside.
        else
        {
            Blink();
            MessageManager.getInstance().DissplayMessage("There is an other substance inside this container.", 1f);
            return(false);
        }
    }
    public void FillWith(float particulesCount, sSubstance newSubstance)
    {
        particules = particulesCount;
        substance  = newSubstance;

        UpdateContainerUI();
    }
    public sSubstance ReleaseParticule()
    {
        // Check if there is any substance in the container.
        if (substance == null)
        {
            Blink();
            return(null);
        }

        // Check if there is any substance left inside the container.
        else if (particules == 0)
        {
            Blink();
            substance = null;
            return(null);
        }

        // Return particle of the substance.
        else
        {
            RedBackground();
            particules--;
            return(substance);
        }
    }
    private void Relase()
    {
        state         = ContainersState.Releasing;
        axisTriggered = true;

        if (availableContainers == 0)
        {
            return;
        }

        // Play corresponding sound.
        if (!audioS.isPlaying)
        {
            audioS.loop = true;
            audioS.clip = releaseSound;
            audioS.Play();
        }

        // Get the substance from the current container.
        sSubstance particleSubstanceToRelease = containers[currentIndex].ReleaseParticule();

        // Release a particle of the substance.
        if (particleSubstanceToRelease != null)
        {
            generator.Release(particleSubstanceToRelease);
        }
    }
Example #6
0
    private void MixContainers(Container cont1, Container cont2, Container destContainer)
    {
        // If there is one more empty container there is nothing to mix.
        if (cont1.isEmpty() || cont2.isEmpty())
        {
            return;
        }

        // Simulate the reaction between the 2 substances.
        sSubstance result = cont1.substance.CollidingWith(cont2.substance);

        // Check the result of the new substance.
        if (result == null)
        {
            MessageManager.getInstance().DissplayMessage("Substances can't mix", 1f);
        }

        else
        {
            // Calculate the number of the particules for the new container.
            float resultPart = cont1.particules + cont2.particules;

            // Empty the used containers.
            cont1.EmptyContainer();
            cont2.EmptyContainer();

            // Fill the destination container with the result.
            destContainer.FillWith(resultPart, result);
        }
    }
    public Particle CreateSubstance(sSubstance substanceToRelase)
    {
        if (nextRelease <= Time.time && substanceToRelase != null)
        {
            // It is time to spawn a new particle.

            // Create the new particle object.
            Particle newParticle = ParticlePool.instance.RequestParticle(substanceToRelase);

            // Update particle parameters.
            Vector3 spawnPosition = transform.position;
            spawnPosition.z = 0f;
            newParticle.transform.position = spawnPosition;
            newParticle.ChangeSubstanceState(substanceToRelase);
            newParticle.rb.AddForce(transform.right * relaseForce);

            // Set the timer.
            nextRelease = Time.time + releaseInterval;

            return(newParticle);
        }
        else
        {
            return(null);
        }
    }
    public ReactionEq(sSubstance _first, sSubstance _second, sSubstance _result)
    {
        first  = _first;
        second = _second;
        result = _result;

        reversible = false;
    }
    public void EmptyContainer()
    {
        // Clear all data about the container.
        particules = 0;
        substance  = null;

        UpdateContainerUI();
    }
Example #10
0
    public void ReactWith(sSubstance otherSubstance)
    {
        // Run the collision on the current substance scriptable object.
        sSubstance newSubstance = currentSubstance.CollidingWith(otherSubstance);

        // Update current substance if the answer is not null.
        if (newSubstance != null)
        {
            ChangeSubstanceState(newSubstance);
        }
    }
Example #11
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        // The the other substance script.
        Particle otherParticle = collision.gameObject.GetComponent <Particle>();

        if (otherParticle != null)
        {
            // Handle the collision between them in the current state.
            sSubstance otherSubstance = otherParticle.currentSubstance;
            ReactWith(otherSubstance);
        }
    }
    public sSubstance CollidingWith(sSubstance otherSubstance)
    {
        for (int i = 0; i < reactions.Count; i++)
        {
            if (reactions[i].second == otherSubstance)
            {
                return(reactions[i].result);
            }
        }

        return(null);
    }
Example #13
0
    public void ChangeSubstanceState(sSubstance newSubstance)
    {
        // Set substance reference
        currentSubstance = newSubstance;

        // Update the life time.
        totalLifeTime   = newSubstance.particleLifeTime;
        currentLifeTime = 0;

        // Set the rigidbody for the particle..
        rb.gravityScale = newSubstance.particleGravity;
        rb.constraints  = RigidbodyConstraints2D.None;
        rb.velocity     = Vector2.zero;

        // Move it to the corresponding layer.
        gameObject.layer = (int)newSubstance.particleLayer;

        // Update the material used by the mesh renderer.
        rend.material = newSubstance.particleMaterial;
    }
Example #14
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        FiniteBarrel barrel = collision.gameObject.GetComponent <FiniteBarrel>();

        if (barrel != null)
        {
            sSubstance particleInsideBarrel = barrel.CheckParticle();

            if (particleInsideBarrel != null)
            {
                StartFeedBack();
            }
        }

        // Get information about the current collision.
        Particle collectedParticle = collision.GetComponent <Particle>();

        //Escape collisions with ground or other objects or the players is not collecting now.
        if (collectedParticle != null)
        {
            StartFeedBack();
        }
    }
    public List <ReactionEq> GetReactionsFor(sSubstance substToFind)
    {
        // Create new empty list.
        List <ReactionEq> searchedList = new List <ReactionEq>();

        foreach (ReactionEq reaction in table)
        {
            // if the substance is found on the first place, add it.
            if (reaction.first == substToFind)
            {
                searchedList.Add(reaction);
            }

            // if the substance is found on the second place and the reaction is reversible, add the reaction reverse.
            else if (reaction.second == substToFind && reaction.reversible)
            {
                ReactionEq newReaction = new ReactionEq(reaction.second, reaction.first, reaction.result);
                searchedList.Add(newReaction);
            }
        }

        return(searchedList);
    }
Example #16
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        bool  success        = false;
        Color collectedColor = Color.black;

        if (collecting == false)
        {
            return;
        }

        FiniteBarrel barrel = collision.gameObject.GetComponent <FiniteBarrel>();

        if (barrel != null)
        {
            sSubstance particleInsideBarrel = barrel.CheckParticle();

            if (particleInsideBarrel != null)
            {
                success = containerToFill.AddParticule(particleInsideBarrel);
                if (success)
                {
                    sSubstance collectedSubstance = barrel.GetParticle();
                    collectedColor = collectedSubstance.particleColor;
                }
                else
                {
                    MessageManager.getInstance().DissplayMessage("There is a problem with this barrel", 1f);
                }
            }
            else
            {
                MessageManager.getInstance().DissplayMessage("There is no substance inside the barrel", 1f);
            }
        }

        // Get information about the current collision.
        Particle collectedParticle = collision.GetComponent <Particle>();

        //Escape collisions with ground or other objects or the players is not collecting now.
        if (collectedParticle != null)
        {
            // Add the substance to the current container sent.
            success = containerToFill.AddParticule(collectedParticle.currentSubstance);

            // Destory particle if collected.
            if (success)
            {
                collectedColor = collectedParticle.currentSubstance.particleColor;
                Destroy(collectedParticle.gameObject);
            }
        }

        if (success)
        {
            particleFeedback.startColor = collectedColor;

            var vel = particleFeedback.velocityOverLifetime;

            PlayerMovement player = FindObjectOfType <PlayerMovement>();

            Vector3 direction = player.transform.position - particleFeedback.transform.position;
            direction = direction.normalized * 10f;

            vel.x = direction.x;
            vel.y = direction.y;
            vel.z = direction.z;


            particleFeedback.Play();
        }
    }
Example #17
0
 public void Activate(sSubstance newSubstance)
 {
     ChangeSubstanceState(newSubstance);
     ChangeActiveState(true);
 }
 public void SetSubstance(sSubstance newSubst)
 {
     particleSubstance = newSubst;
 }
 public ContainerData(sSubstance _subst, float _count)
 {
     subst = _subst;
     count = _count;
 }
 public void UpdateContainerSubstance(sSubstance newSubstance)
 {
     substance = newSubstance;
 }
 public void Release(sSubstance substanceToCreate)
 {
     Particle newParticle = CreateSubstance(substanceToCreate);
 }