示例#1
0
    void Update()
    {
        #region now check whether we can see the player
        if (!onlyShootWhenInvisible || _cameraController.IsPointVisible(this.transform.position))
        {
            if (_lastRoundFiredTime + _rateOfFireInterval <= Time.time)
            {
                for (int i = 0; i < fireDirectionVectorGroups[_currentfireDirectionVectorGroupIndex].vectors.Count; i++)
                {
                    GameObject       enemyProjectileGameObject = _objectPoolingManager.GetObject(projectilePrefab.name, this.transform.position);
                    IEnemyProjectile enemyProjectile           = enemyProjectileGameObject.GetComponent <IEnemyProjectile>();
                    Logger.Assert(enemyProjectile != null, "Enemy projectile must not be null");

                    Vector2 direction;
                    if (fireDirectionSpace == Space.World)
                    {
                        direction = fireDirectionVectorGroups[_currentfireDirectionVectorGroupIndex].vectors[i];
                    }
                    else
                    {
                        direction = this.transform.TransformDirection(fireDirectionVectorGroups[_currentfireDirectionVectorGroupIndex].vectors[i]);
                    }

                    enemyProjectile.StartMove(this.transform.position, direction, projectileAcceleration, projectileTargetVelocity);
                }

                _currentfireDirectionVectorGroupIndex = _currentfireDirectionVectorGroupIndex == fireDirectionVectorGroups.Count - 1 ? 0 : _currentfireDirectionVectorGroupIndex + 1;
                _lastRoundFiredTime = Time.time;
            }
        }
        #endregion
    }
 public void handlePlayerCollision(IEnemyProjectile proj, IPlayer player)
 {
     //test for collision
     if (player.getDestRect().Intersects(proj.getDestRect()))
     {
         proj.doDamage(player);
         proj.collide(game);
         //add code to see if player dies later
     }
 }
示例#3
0
    void Update()
    {
        #region now check whether we can see the player
        bool isSeeingPlayer = false;

        Vector3 playerVector = _playerController.transform.position - this.transform.position;
        float   angle        = Mathf.Atan2(playerVector.y, playerVector.x);
        if (angle < 0f)
        {
            angle += 2 * Mathf.PI;
        }

        if (angle >= _startAngleRad && angle <= _endAngleRad)
        {
            RaycastHit2D raycastHit2D = Physics2D.Raycast(this.gameObject.transform.position, playerVector.normalized, playerVector.magnitude, scanRayCollisionLayers);
            if (raycastHit2D && raycastHit2D.collider.gameObject.layer == LayerMask.NameToLayer("Player"))
            {
                isSeeingPlayer          = true;
                _playerInSightDuration += Time.deltaTime;
            }
        }

        DrawRay(this.gameObject.transform.position, playerVector, isSeeingPlayer ? Color.red : Color.gray);

        if (!isSeeingPlayer)
        {
            _playerInSightDuration = 0f;
        }

        if (_playerInSightDuration >= timeNeededToDetectPlayer)
        {
            if (_lastRoundFiredTime + _rateOfFireInterval <= Time.time)
            {
                GameObject       enemyProjectileGameObject = _objectPoolingManager.GetObject(projectilePrefab.name, this.transform.position);
                IEnemyProjectile enemyProjectile           = enemyProjectileGameObject.GetComponent <IEnemyProjectile>();
                Logger.Assert(enemyProjectile != null, "Enemy projectile must not be null");

                enemyProjectile.StartMove(this.transform.position, playerVector, projectileAcceleration, projectileTargetVelocity);

                _lastRoundFiredTime = Time.time;
            }
        }
        #endregion
    }
示例#4
0
 public void RemoveEnemyProjectile(IEnemyProjectile projectile)
 {
     EnemyProjectiles.Remove(projectile);
 }
示例#5
0
 public void AddEnemyProjectile(IEnemyProjectile projectile)
 {
     EnemyProjectiles.Add(projectile);
 }
示例#6
0
 public void handleCollision(IEnemyProjectile projectile, GameManager game)
 {
     projectile.collide(game);
 }
示例#7
0
 public void RemoveEnemyProjectile(IEnemyProjectile projectile)
 {
     rooms[roomKey].RemoveEnemyProjectile(projectile);
 }
示例#8
0
 public void AddEnemyProjectile(IEnemyProjectile projectile)
 {
     rooms[roomKey].AddEnemyProjectile(projectile);
 }
示例#9
0
 public void handleRupeeShieldBlock(IEnemyProjectile proj, IPlayerProjectile r)
 {
     proj.collide(game);
     r.collide(game);
 }