Ejemplo n.º 1
0
Archivo: G.cs Proyecto: jdaiv/bomb-game
    public void FireHitscan(Entity owner, Vector2 origin, Vector2 direction, int explosionRadius = 0, int bounces = 0, int teleports = 0)
    {
        if (teleports > 4)
        {
            return;
        }
        direction.Normalize();
        var raycast = Physics2D.Raycast(origin, direction);

        if (raycast.collider != null)
        {
            if (Entity.IsEntity(raycast.collider))
            {
                if (Entity.IsEntity <Teleporter>(raycast.collider))
                {
                    var teleporter = raycast.collider.GetComponent <Teleporter>();
                    FireHitscan(owner, (Vector2)level.entities[teleporter.target].transform.position + (direction * (Teleporter.RADIUS + 0.01f)), direction, explosionRadius, bounces, teleports + 1);
                }
                else
                {
                    Entity.KillEntity(raycast.collider, owner);
                }
            }
            else
            {
                if (explosionRadius > 0)
                {
                    level.Explosion(raycast.point, explosionRadius, false);
                }
                if (bounces > 0)
                {
                    FireHitscan(owner, raycast.point, Vector2.Reflect(direction, raycast.normal), explosionRadius, bounces - 1, teleports);
                }
            }
            particles.Emit(1, raycast.point, 1, new Vector2(-1, -1), new Vector2(1, 1));
            bulletTrails.AddTrail(origin, raycast.point);
        }
        else
        {
            bulletTrails.AddTrail(origin, origin + (direction * 80));
        }
    }
Ejemplo n.º 2
0
    void OnCollisionEnter(Collision collision)
    {
        if (collision.collider.CompareTag("Wall") || collision.collider.CompareTag("Thing"))
        {
            if (m_IsShooting)
            {
                //v.1
                // AddSpring (collision.rigidbody);

                //v.2
                RemoveRigidbody();
                //usePhysics = false;
                useRigidbody = false;
                m_IsShooting = false;
                // Invoke ("RemoveRigidbody", 3f);
            }
            else if (m_IsSpringing)
            {
                Invoke("RemoveSpring", 3f);
            }
            else if (m_IsDropping)
            {
                Invoke("RemoveRigidbody", 2f);
                //usePhysics = false;
                useRigidbody = false;
                m_IsDropping = false;
            }
        }

        if (collision.collider.CompareTag("Sticker"))
        {
            if (m_IsShooting || m_IsDropping)
            {
                Invoke("RemoveRigidbody", 2f);
                //usePhysics = false;
                useRigidbody = false;
                m_IsDropping = false;
            }
        }

        if (IsHammered)
        {
            // Particle effect start
            //v.1

            /*
             * var i_particle = Instantiate(Particles, collision.contacts[0].point, Quaternion.identity, transform);
             *
             * if (TapeWidth != 0)
             * {
             *      //Mapping(float x, float in_min, float in_max, float out_min, float out_max)
             *      float newSize = Mapping(TapeWidth, 0.05f, 4f, 0.2f, 4f);
             *      i_particle.transform.localScale *= newSize;
             * }
             *
             * i_particle.Play ();
             */
            var emitParams = new ParticleSystem.EmitParams();
            if (TapeWidth != 0)
            {
                //Mapping(float x, float in_min, float in_max, float out_min, float out_max)
                float newSize = Mapping(TapeWidth, 0.05f, 4f, 0.01f, 0.35f);
                emitParams.startSize = newSize;
            }
            emitParams.position = collision.contacts [0].point;
            Particles.Emit(emitParams, 1);

            if (!readyToDie)
            {
                Invoke("DoDestroy", 1f);
                readyToDie = true;
            }
        }
    }