Esempio n. 1
0
 private void ApplyItem(Item item)
 {
     if (item.RestoreHealth.HasValue)
     {
         Health = Mathf.Min(Health + item.RestoreHealth.Value, MaxHealth);
         AudioUtils.Play("HealUp", 7.0f);
     }
     if (item.ExplosionForce.HasValue)
     {
         ExplosionFactory.Create(item.Position, item.ExplosionForce.Value);
     }
     if (item.ApplyBuff != null)
     {
         buffs.Add(item.ApplyBuff);
     }
     if (item.ApplyEffect != null)
     {
         effects.Add(item.ApplyEffect);
     }
 }
Esempio n. 2
0
        protected void Die(DamageInfo dmgInfo)
        {
            float oldLife = currentLife;

            currentLife -= dmgInfo.Damage;
            lifeBar.transform.localScale = new Vector3(currentLife / life * 0.5f / transform.localScale.x,
                                                       lifeBar.transform.localScale.y,
                                                       lifeBar.transform.localScale.z);

            if (currentLife < 0.1f)
            {
                ExplosionFactory.Create(transform.position, 1.0f);
                AudioUtils.Play("ZombieDeath", transform.position);

                BloodFactory.SplatFromDamageInfo(dmgInfo);
                GameStatistics.AddKill(dmgInfo.PlayerNumber, this);

                Destroy(this.gameObject);
                switch (enemyType)
                {
                case EnemyType.Regular:
                    Item.CreateRandom(transform.position);
                    break;

                case EnemyType.Boss:
                    var        tileset = (GameObject.Find("Map")).GetComponent <Assets.Scripts.Map.Map>().tilesets;
                    GameObject stairs  = (GameObject)Instantiate(tileset[Assets.Scripts.Map.Tile.Type.Exit][0],
                                                                 transform.position,
                                                                 Quaternion.identity);
                    stairs.transform.SetParent(map.transform);
                    break;
                }
            }
            else
            {
                AudioUtils.Play(damageSound, transform.position, 10.0f);
            }
        }
Esempio n. 3
0
        void Die(float damage)
        {
            if (IsImmune)
            {
                return;
            }

            Health -= damage;

            const float IMMUNITY_TIME_S = 1.0f;

            IsImmune = true;
            Invoke("StopImmunity", IMMUNITY_TIME_S);

            if (Health <= 0.0f)
            {
                AudioUtils.BackgroundMusic.Stop();
                ExplosionFactory.Create(transform.position, 3.0f);

                DetachCamera();
                AudioUtils.Play("GameOver", 15.0f);
                Destroy(this.gameObject);
            }
        }
Esempio n. 4
0
        void WebControl(KeyCode key, LegData leg)
        {
            if (Input.GetKeyDown(key))
            {
                if (!leg.spring)
                {
                    GameObject legObject    = leg.gameObject;
                    Transform  legTransform = legObject.transform;
                    LayerMask  layerMask    = ~(1 << LayerMask.NameToLayer("Player"));
                    // shoot web from the tip of the leg
                    Vector2      legEnd  = legTransform.position + (legTransform.up * leg.height);
                    RaycastHit2D hitInfo = Physics2D.Raycast(legEnd, legTransform.up, WebSwingRange, layerMask);
                    if (hitInfo.collider)
                    {
                        if (hitInfo.collider.tag == "Enemy")
                        {
                            DamageInfo dmgSource = new DamageInfo(Damage,
                                                                  Position,
                                                                  hitInfo.collider.gameObject.transform.position,
                                                                  leg.PlayerNumber,
                                                                  hitInfo.collider);
                            hitInfo.rigidbody.SendMessage("Die", dmgSource);
                        }

                        // if out leg is inside the wall don't create spring
                        if (!legEnd.Equals(hitInfo.point))
                        {
                            leg.webHitInfo = hitInfo;
                            SpringJoint2D spring = legObject.AddComponent <SpringJoint2D> ();
                            spring.autoConfigureDistance = false;
                            spring.distance     = 0;
                            spring.dampingRatio = 0.9F;
                            spring.frequency    = 0.3F;
                            // it should be up because joint start should be attached to the tip of the leg, but due to
                            // hingejoint bugs its atm connected to the body
                            spring.anchor          = Vector2.zero;
                            spring.connectedAnchor = hitInfo.point;
                            leg.spring             = spring;
                            leg.swingCollision     = true;
                            leg.lr.SetPosition(1, leg.spring.connectedAnchor);
                            leg.lr.enabled = true;
                        }
                    }
                    else
                    {
                        // did not hit anything, change web color to red with the end at the maximum range
                        leg.swingCollision = false;
                        Vector2 reachedPoint = legTransform.position + legTransform.up * (leg.height + WebSwingRange);
                        leg.lr.SetPosition(1, reachedPoint);
                        leg.lr.enabled = true;
                    }

                    AudioUtils.Play("Laser");
                }
            }
            else if (Input.GetKeyUp(key))
            {
                leg.lr.enabled = false;
                SpringJoint2D spring = leg.spring;
                if (spring)
                {
                    Destroy(spring);
                    leg.webHitInfo = new RaycastHit2D();
                }
            }

            if (leg.lr.enabled)
            {
                if (leg.webHitInfo.collider && !leg.webHitInfo.collider.name.ToLower().Contains("enemy"))   // if we're connected to (not enemy)
                // shoot ray again to check if the string should be destroyed
                {
                    LayerMask    layerMask    = ~(1 << LayerMask.NameToLayer("Player"));
                    Transform    legTransform = leg.gameObject.transform;
                    Vector2      legEnd       = legTransform.position + (legTransform.up * leg.height);
                    RaycastHit2D hitInfo      = Physics2D.Raycast(legEnd, leg.webHitInfo.point - legEnd, WebSwingRange, layerMask);
                    if (Vector2.SqrMagnitude(hitInfo.point - leg.webHitInfo.point) > 0.001F)
                    {
                        leg.lr.enabled = false;
                        SpringJoint2D spring = leg.spring;
                        Destroy(spring);
                        leg.webHitInfo = new RaycastHit2D();

                        AudioUtils.Play("FabricTorn", hitInfo.point);
                        return;
                    }
                }

                Vector2 legTip = leg.gameObject.transform.position + Quaternion.Euler(0, 0, leg.gameObject.transform.eulerAngles.z) * new Vector2(0, leg.height);
                if (leg.swingCollision)
                {
                    leg.lr.SetPosition(0, legTip);
                    leg.lr.SetColors(Color.white, Color.white);
                }
                else
                {
                    leg.lr.SetColors(Color.red, Color.red);
                    leg.lr.SetPosition(0, legTip);
                }
            }
        }