Beispiel #1
0
    private void Shoot(Vector3 startPos, Vector3 rotation, List <Vector3> points, int reflections)
    {
        RaycastHit2D hit = Physics2D.Raycast(startPos, rotation);

        if (hit)
        {
            points.Add(hit.point);
            if (hit.collider.tag.Equals("Reflector"))
            {
                IDamageable obj = hit.collider.GetComponent <WallController>();
                obj.Damage(1);
                Shoot(hit.point + hit.normal * 0.01f, Vector3.Reflect(rotation, hit.normal), points, reflections + 1);
            }
            else if (hit.collider.tag.Equals("Enemy") && reflections > 0)
            {
                DrawShootEffect(points);

                IKillable obj = hit.collider.GetComponent <EnemyController>();
                obj.Kill();
                GameController.SharedInstance.ScorePoints(GameController.SharedInstance.ScorePerKill, reflections);
            }
            else
            {
                DrawShootEffect(points);
            }
        }
    }
Beispiel #2
0
    protected void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.tag != "Player")
        {
            if (coll.gameObject.tag == "Floor")
            {
                audioSource.PlayOneShot(hitfloor, volumeScale);
            }
            else if (coll.gameObject.tag == "Wall")
            {
                audioSource.PlayOneShot(hitfloor, volumeScale);
            }
            dangerous = false;
        }

        IOpenable openable = coll.gameObject.GetComponent <IOpenable>();
        IKillable killable = coll.gameObject.GetComponent <IKillable>();

        if (openable != null)
        {
            audioSource.PlayOneShot(openDoor, 0.5f);
            openable.Open();
            Destroy(gameObject);
        }

        if (killable != null && dangerous)
        {
            audioSource.PlayOneShot(hitPlayer, volumeScale);
            killable.Kill();
            Destroy(gameObject);
        }
    }
Beispiel #3
0
    public void GetHit(int hurt, Vector3 posAttacker)
    {
        currentLife -= hurt;
        Debug.Log("hit ! -" + hurt);
        if (shake)
        {
            CameraOrthoShake.Instance.CShake(2f, 1000f);
            //            ScreenShake.Instance.ShakeCamera();
        }

        //son quand on est touché
        SoundManager.GetSingleton.PlaySound(soundToPlayHit);

        if (isPlayer)
        {
            Debug.Log("player");
            ObjectsPooler.Instance.SpawnFromPool(GameData.PoolTag.ParticleBimpPlayer, transform.position, transform.rotation, ObjectsPooler.Instance.transform);
        }
        else
        {
            ObjectsPooler.Instance.SpawnFromPool(GameData.PoolTag.ParticleBump, transform.position, transform.rotation, ObjectsPooler.Instance.transform);
        }
        PlayerConnected.Instance.SetVibrationPlayer(0, vibration);

        if (currentLife <= 0)
        {
            currentLife = 0;

            killable.Kill();
        }
        else
        {
            killable.GetHit(hurt, posAttacker);
        }
    }
Beispiel #4
0
    /// <summary>
    /// prend des dommages, renvoi X point de score à rajouter si on meurt ! sinon 0
    /// (pour le scorring)
    /// </summary>
    /// <param name="damages"></param>
    /// <returns></returns>
    public int TakeDamages(float damages, bool oneShot)
    {
        lock (this)
        {
            if (!invincible && currentLife > 0)
            {
                if (!coroutineOnTakeDmgStarted && entityType == EntityType.Ennemy)
                {
                    StartCoroutine(OnTakeDamage(0.1f));
                }

                if (oneShot)
                {
                    damages = currentLife;
                }

                currentLife = Mathf.Max(0, currentLife - damages);

                if (currentLife <= 0)
                {
                    if (killable != null)
                    {
                        killable.Kill();
                        return(scoreToGiveToOther);  //ici get le nombre de score que le gameObject donne en mourrant
                    }
                }
                else
                {
                    //si on est pas mort, ajouter quand même le score au joueur !
                    return(scoreToGiveToOtherOnHit);
                }
            }
            return(0);
        }
    }
 public void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.collider.tag.Equals("Player"))
     {
         IKillable player = collision.gameObject.GetComponent <PlayerController>();
         player.Kill();
     }
 }
Beispiel #6
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        IKillable killable = collider.gameObject.GetComponentInChildren <IKillable>();

        if (killable != null)
        {
            killable.Kill();
        }
    }
Beispiel #7
0
        private void OnTriggerEnter2D(Collider2D other)
        {
            IKillable killable = other.gameObject.GetComponent <IKillable>();

            if (killable != null)
            {
                killable.Kill();
            }
        }
Beispiel #8
0
    IEnumerator ExecuteAfterTime(float time)
    {
        yield return(new WaitForSeconds(time));

        if (killable != null)
        {
            killable.Kill();
        }
    }
Beispiel #9
0
    private void TryKill(GameObject other)
    {
        IKillable killable = other.GetComponent <IKillable> ();

        if (killable != null)
        {
            killable.Kill();
        }
    }
Beispiel #10
0
    /// <summary>
    /// on se tue soit même
    /// </summary>
    private void KillSelf()
    {
        IKillable killable = gameObject.GetComponent <IKillable>();

        if (killable != null)
        {
            killable.Kill();
        }
    }
Beispiel #11
0
    protected override void Use()
    {
        IKillable killableEntity = currentHandler.gameObject.GetComponent <IKillable>();

        if (killableEntity != null)
        {
            killableEntity.Kill();
        }
    }
    public void Hit(int damage)
    {
        stats.health -= damage;
        print(stats.health);

        if (stats.health <= 0 && !killable.IsDead)
        {
            killable.Kill();
        }
    }
Beispiel #13
0
    public void TakeDamage(float dmg)
    {
        float healthDmg = Mathf.Clamp(dmg - armor, 0f, dmg);

        armor  = Mathf.Clamp(armor - dmg, 0f, armor);
        health = Mathf.Clamp(health - healthDmg, 0f, maxHealth);
        if (killable != null && health == 0f)
        {
            killable.Kill();
        }
    }
Beispiel #14
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        IKillable killable = collision.GetInterface <IKillable>();

        if (killable != null)
        {
            killable.Kill();
        }

        Kill();
    }
    public void Hit(PlayerAttack pa)
    {
        stats.Health -= pa.Damage;
        if (Alive && stats.Health <= 0)
        {
            killable.Kill();
            Alive = false;

            OnHasDied();
        }
    }
Beispiel #16
0
    private void TryKill(GameObject other)
    {
        IKillable killable = other.GetComponent <IKillable>();

        if (killable != null)
        {
            if (tagToKill.Count > 0)
            {
                for (int i = 0; i < tagToKill.Count; i++)
                {
                    if (other.tag == tagToKill[i])
                    {
                        killable.Kill();
                        return;
                    }
                }
                return;
            }
            killable.Kill();
        }
    }
        /*
         * public void OwnTriggerEnter(Collider other)
         * {
         *
         * }
         *
         * public void OwnTriggerStay(Collider other)
         * {
         *
         * }
         *
         * public void OwnTriggerExit(Collider other)
         * {
         *
         * }
         *
         * public void OwnCollisionEnter(Collision collision)
         * {
         *
         * }
         *
         * public void OwnCollisionStay(Collision collision)
         * {
         *
         * }
         *
         * public void OwnCollisionExit(Collision collision)
         * {
         *
         * }
         */

        public void Kill()
        {
            if (objectToKill == null)
            {
                return;
            }
            IKillable kill = objectToKill.GetComponent <IKillable>();

            if (kill != null)
            {
                kill.Kill();
            }
        }
Beispiel #18
0
        public void OnTriggerEnter2D(Collider2D other)
        {
            IKillable killable = other.GetComponent <IKillable>();

            if (killable != null)
            {
                killable.Kill();
            }

            if (_destroyObject)
            {
                Destroy(other);
            }
        }
Beispiel #19
0
    /// <summary>
    /// essai de tuer...
    /// </summary>
    private void TryKill(GameObject other)
    {
        IKillable killable = other.GetComponent <IKillable> ();

        if (killable != null)
        {
            for (int i = 0; i < listPrefabsToKill.Count; i++)
            {
                if (other.CompareTag(listPrefabsToKill[i].ToString()))
                {
                    killable.Kill();
                    if (killItSelf)
                    {
                        KillSelf();
                    }
                    return;
                }
            }
        }
    }
Beispiel #20
0
    /// <summary>
    /// test la collision avec l'objet
    /// </summary>
    private void CollisionBehavior(Collider col)
    {
        LifeBehavior life = col.gameObject.GetComponent <LifeBehavior>();

        if (life && !currentlyIntoTrigger)
        {
            bool damageable = isDamagingThis(life.EntityType);
            if (damageable)
            {
                counterCollision++;
                int score = life.TakeDamages(damages, oneShot);
                if (score != 0)
                {
                    if (PlayerController) // NB si un ennemi fait des degats, il ne gagne pas de points et ne devrait pas avoir de playerController
                    {
                        Vector3 scorePosition = life.CurrentLife <= 0 ? life.transform.position : life.transform.position + life.transform.up * 1.5f;
                        CreateScorePrefab(scorePosition, life.CurrentLife <= 0, score);
                        PlayerController.ScorePlayer += score;
                        SoundManager.GetSingularity.PlayImpactSound(PlayerController.IdPlayer);
                    }
                }
                else
                {
                    // Si on kill la target pas besoin de désactiver la source de dommage
                    // Important car TriggerExit jamais appelé donc currentlyIntoTrigger reste à true
                    currentlyIntoTrigger = true;
                }

                if (collisionBeforeKilling >= 0 && counterCollision >= collisionBeforeKilling)
                {
                    isSourceEnabled = false;  //desactiver l'origine des dégât si souhaité

                    IKillable killable = gameObject.GetComponent <IKillable>();
                    if (killable != null)
                    {
                        killable.Kill();
                    }
                }
            }
        }
    }
Beispiel #21
0
    public void Hit()
    {
        stats.Health -= 10;

        if (hasTakenDamage != null)
        {
            hasTakenDamage();
        }

        if (stats.Health <= 0 && !isDead)
        {
            killable.Kill();

            if (hasDied != null)
            {
                hasDied();
            }

            isDead = true;
        }
    }
Beispiel #22
0
 public void Damage(int damage)
 {
     if (_overcharge == 0)
     {
         _energy -= damage;
         Debug.Log("Energy: " + _energy);
         //Debug.Log ("Energy:" + _energy);
         if (_energy < 0)
         {
             try {
                 _parent.Kill();
             } catch {
                 Debug.Log("on Luke Death exception caught");
             }
         }
         else
         {
             float scale = _energy / 100f;
             float pos   = scale / 2 + .45f;
             AdjustSaberLength(scale, pos, _mesh);
         }
     }
     else
     {
         _overcharge -= damage;
         //Debug.Log ("Energy:" + _energy);
         if (_overcharge < 0)
         {
             _overcharge = 0;
         }
         else
         {
             float scale = _overcharge / 100f;
             float pos   = scale / 2 + .45f;
             AdjustSaberLength(scale, pos, _oMesh);
         }
     }
 }
Beispiel #23
0
        // Update is called once per frame
        void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Ray        _ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit _hit;
                if (Physics.Raycast(_ray, out _hit))
                {
                    IKillable _scpKill = _hit.collider.GetComponent <IKillable> ();
                    if (_scpKill != null)
                    {
                        _scpKill.Kill();
                    }


                    IDamageable <float> _scpDamage = _hit.collider.GetComponent <IDamageable <float> > ();
                    if (_scpDamage != null)
                    {
                        _scpDamage.Damage(10f);
                    }
                }
            }
        }
Beispiel #24
0
        protected void OnCollisionEnter2D(Collision2D other)
        {
            Collider2D otherCollider = other.collider;

            if (IsDead)
            {
                if (IgnoreDeathCollision)
                {
                    Player player = otherCollider.GetComponent <Player>();
                    if (player != null)
                    {
                        Physics2D.IgnoreCollision(otherCollider, GetComponent <Collider2D>());
                    }
                }

                return;
            }

            IEnemy enemy = otherCollider.GetComponent <IEnemy>();

            if (enemy != null)
            {
                TurnAround();
                if (!FriendlyFire)
                {
                    return;
                }
            }

            IKillable killable = otherCollider.GetComponent <IKillable>();

            if (killable != null)
            {
                killable.Kill();
            }
        }
 public void KillObject(IKillable killable)
 {
     Debug.LogWarningFormat("{0} killed by GameSceneController", killable.GetName());
     killable.Kill();
 }
Beispiel #26
0
 public void KillObject(IKillable killable)
 {
     killable.Kill();
 }
 public void KillObject(IKillable killable)
 {
     Debug.LogWarningFormat("{0} killed by Game Scene Controller", killable.GetName());
     killable.Kill(); //will take any class/struct that implements IKillable
 }
 public void KillObject(IKillable killable)
 {
     // Debug.LogWarning($"{killable.GetName()} was killed by gameSceneController");
     killable.Kill();
 }