コード例 #1
0
        private IEnumerator SearchingRoutine(DroneState pState)
        {
            _state = pState;

            var waitingMovementRoutine = WaitingMovementRoutine();

            if (_state == DroneState.SEARCHING_ENEMY)
            {
                Console.WriteLine($"{this.name} SearchingRoutine | {Time.time}");

                _ledSprite.SetColor(0, 1, 0);
                _blinkLedRoutine = CoroutineManager.StartCoroutine(BlinkLed(), this);

                CoroutineManager.StartCoroutine(waitingMovementRoutine, this);
                _iesDebug.Add(waitingMovementRoutine);
            }

            while (_state == DroneState.SEARCHING_ENEMY ||
                   _state == DroneState.RETURN_TO_START_POINT_AFTER_CHASING_AND_SEARCHING_ENEMY)
            {
                _distanceToTarget = _enemy.Pos - this._pos;

                float dist = _distanceToTarget.Magnitude;

                if (dist < _detectEnemyRange)
                {
                    //Enemy Detected
                    CoroutineManager.StopCoroutine(waitingMovementRoutine);
                    CoroutineManager.StopCoroutine(_returnToStartPointRoutine);
                    CoroutineManager.StopCoroutine(_goToPointRoutine);

                    _iesDebug.Remove(_returnToStartPointRoutine);
                    _iesDebug.Remove(_goToPointRoutine);

                    _enemyDetectedRoutine = CoroutineManager.StartCoroutine(EnemyDetectedRoutine(), this);
                    _iesDebug.Add(_enemyDetectedRoutine);
                }

                yield return(null);
            }

            _iesDebug.Remove(_searchingRoutine);
            _iesDebug.Remove(waitingMovementRoutine);
        }
コード例 #2
0
        public DroneGameObject(float pX, float pY, float pWidth, float pHeight, float pSpeed = 200,
                               float pRotation = 0) : base(
                "data/Drone spritesheet small.png", 2, 2, 4, false, true)
        {
            _id  = ++IdCounter;
            name = $"{this}_{_id}";

            _customColliderBounds = new Rectangle(-27, -24, 53, 50);

            _maxSpeed = pSpeed;

            float originalWidth  = width;
            float originalHeight = height;

            SetOrigin(0, height);

            float lScaleX = pWidth / width;
            float lScaleY = pHeight / height;

            SetScaleXY(lScaleX, lScaleY);

            x = pX; // + width / 2;
            y = pY; // - height + height / 2f;

            SetOrigin(originalWidth / 2f, originalHeight / 2f);

            Turn(pRotation);

            x = pX + Mathf.Cos(rotation.DegToRad()) * width * 0.5f;
            y = pY + Mathf.Sin(rotation.DegToRad()) * width * 0.5f;

            var pos  = new Vector2(x - pX, y - pY);
            var perp = new Vector2(pos.y, -pos.x).Normalized;

            pos = perp * height * 0.5f;

            SetScaleXY(1, 1);

            x += pos.x;
            y += pos.y;

            _startPosition = new Vector2(x, y);

            _ledSprite = new AnimationSprite("data/Drone White Led.png", 1, 1, -1, false, false);
            _ledSprite.SetOrigin(width * 0.5f, height * 0.5f);

            _ledOffSprite = new AnimationSprite("data/Drone Gray Led.png", 1, 1, -1, false, false);
            _ledOffSprite.SetOrigin(width * 0.5f, height * 0.5f);

            _ledSprite.SetColor(0, 1f, 0);

            AddChild(_ledOffSprite);
            AddChild(_ledSprite);

            _droneFollowRangeCone = new DroneFollowRangeCone(this);
            _droneFollowRangeCone.SetColor(0.9f, 0.9f, 0);
            _droneFollowRangeCone.alpha = 0;
            AddChild(_droneFollowRangeCone);

            _easyDrawDebug = new EasyDraw(200, 80, false);
            _easyDrawDebug.SetOrigin(0, _easyDrawDebug.height * 0.5f);
            _easyDrawDebug.Clear(Color.Black);
            AddChild(_easyDrawDebug);
            _easyDrawDebug.TextFont("data/Gaiatype.ttf", 8);
            _easyDrawDebug.x = 0;
            _easyDrawDebug.y = -40;

            CoroutineManager.StartCoroutine(WaitForEnemyLoad(), this);
        }