示例#1
0
        private void HandleIdle()
        {
            var observations = _entity.observations;

            observations.Sort(new GameObjectDistanceSortComparer(this.transform.position));

            var count = observations.Count;

            for (int i = 0; i < count; i++)
            {
                var obs = observations[i];

                var nest = obs.GetComponent <NestStructure>();
                if (nest != null)
                {
                    if (_entity.IsAllied(nest))
                    {
                        // try to avoid attacking own nest
                        continue;
                    }

                    _attackTarget = nest;
                    _currentState = BlasterState.Exploding;
                    return;
                }

                var otherUnit = obs.GetComponent <UnitBase>();
                if (otherUnit != null)
                {
                    if (_entity.IsAllied(otherUnit))
                    {
                        // try to avoid attacking allied units
                        continue;
                    }

                    _attackTarget = otherUnit;
                    _currentState = BlasterState.Exploding;
                    return;
                }
            }

            // nothing interesting in memory, do some random wandering
            if (!_entity.isMoving)
            {
                _entity.RandomWander();
            }
        }
示例#2
0
        private void HandleExploding()
        {
            if (_attackTarget == null || _attackTarget.isDead)
            {
                _attackTarget = null;
                _currentState = BlasterState.Idle;
                return;
            }

            if ((_attackTarget.transform.position - _entity.transform.position).sqrMagnitude > (_entity.explodeRadius * _entity.explodeRadius))
            {
                // attack target outside of range
                if (!_entity.isMoving)
                {
                    _entity.MoveTo(_attackTarget.transform.position);
                }

                return;
            }

            // attack target within range
            _entity.Attack();
        }
示例#3
0
 private void HandleDeath(ICanDie bl)
 {
     if(bl is EnemyBl)
     {
         EnemyBl b = bl as EnemyBl;
         if (rand.Next(10) >= 7)
         {
             switch (rand.Next(2))
             {
                 case 0:
                     DamagePowerUPModel temp = new DamagePowerUPModel(b.Shape.Area.Left, b.Shape.Area.Top, 10, 10);
                     PowerUPBl tempbl = new PowerUPBl(temp);
                     AddToEntities(tempbl);
                     break;
                 case 1:
                     LifePowerUPModel temp2 = new LifePowerUPModel(b.Shape.Area.Left, b.Shape.Area.Top, 10, 10);
                     PowerUPBl tempbl2 = new PowerUPBl(temp2);
                     AddToEntities(tempbl2);
                     break;
                 default:
                     break;
             }
         }
     }
 }
示例#4
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        if (!leftPlayer)
        {
            leftPlayer = true;
            return;
        }

        if (genericHitNoise)
        {
            audio.PlayOneShot(genericHitNoise, genericHitNoiseVolume);
        }

        GameObject other = collider.gameObject;

        switch (other.tag)
        {
        case "Door":
            DoorLogic dl = other.GetComponent <DoorLogic>();
            if (dl.colour == this.colour)
            {
                dl.Open();
                Die();
            }
            else
            {
                if (bounceOnWrongDoors)
                {
                    this.Bounce();
                }
                else
                {
                    Die();
                }
            }
            break;

        case "Player":
            CharacterControl cc = other.GetComponent <CharacterControl>();
            cc.Damaged();
            Die();
            break;

        case "Enemy":
            if (hitEnemyNoise)
            {
                audio.PlayOneShot(hitEnemyNoise, hitEnemyNoiseVolume);
            }
            ICanDie icd = other.GetComponent <ICanDie>();
            if (icd)
            {
                icd.Hit(damage);
            }
            Die();
            break;

        case "Projectile":
            // do nothing
            break;

        default:
            if (hitWallNoise)
            {
                audio.PlayOneShot(hitWallNoise, hitWallNoiseVolume);
            }
            Die();
            break;
        }
    }