Exemple #1
0
        public override void Update()
        {
            base.Update();

            // All of those are not entities, so they have to be updated manually.

            // It needs to be updated automatically.
            _fireAnimation.Update();

            _slowAlarm.Update();

            // You also can not use TriggerAction and check if the alarm was triggered this way.
            if (_autoAlarm.Update())
            {
                _autoAlarmSwitch = !_autoAlarmSwitch;
            }


            // You can count time by hand. Not that you should, it just
            // shows how time keepers are used internally.
            // It is usually used for different tasks, which alarms can't really handle.
            _counter += _slowTimeKeeper.Time();
            if (_counter > _alarmPeriod)
            {
                // Subtracting instead of zeroing will correct for time errors.
                _counter      -= _alarmPeriod;
                _counterSwitch = !_counterSwitch;
            }

            _stateMachine.Update();
        }
Exemple #2
0
        public override void Update()
        {
            if (_mode == ShootingMode.Auto)
            {
                _initialDelayAlarm.Update();

                if (!_initialDelayAlarm.Running && _fireAlarm.Update())
                {
                    Shoot();
                }
            }

            if (_mode == ShootingMode.Trigger)
            {
                if (_myButton != null)
                {
                    if (_myButton.Pressed)
                    {
                        Shoot();
                    }
                }
                else
                {
                    if (TryGetComponent(out LinkComponent link))
                    {
                        if (link.Pair != null)
                        {
                            _myButton = (Button)link.Pair.Owner;
                            RemoveComponent <LinkComponent>();
                        }
                    }
                }
            }


            if (_shootingAnimationRunning)
            {
                _shootingAnimationProgress += TimeKeeper.GlobalTime(_shootingAnimationSpeed);

                if (_shootingAnimationProgress > 1)
                {
                    _shootingAnimationRunning  = false;
                    _shootingAnimationProgress = 0;
                }
            }
        }
        public override void Update()
        {
            _delayAlarm.Update();

            if (_delayAlarm.Running)
            {
                return;
            }

            if (_alarm.Update())
            {
                _fadeDirection *= -1;
                if (_fadeDirection == 1)
                {
                    DestroyEntity();
                }
                else
                {
                    if (_nextLevel)
                    {
                        MapController.BuildNextMap();
                    }
                    else
                    {
                        MapController.RebuildCurrentMap();
                    }
                }
            }


            _blackscreenAlpha = _alarm.Counter / _fadeTime;

            if (_fadeDirection == 1)
            {
                _blackscreenAlpha = 1 - _blackscreenAlpha;
            }
        }
        public override void Update()
        {
            if (_typeAlarm.Update())
            {
                TextPtr += 1;

                try
                {
                    if (Text[TextPtr] == ' ')
                    {
                        TextPtr += 1;
                    }

                    if (Text[TextPtr] == Environment.NewLine[0])
                    {
                        TextPtr += Environment.NewLine.Length;
                    }

                    if (TextPtr >= Text.Length)
                    {
                        throw new Exception();
                    }
                }
                catch (Exception)
                {
                    _typeAlarm.Active = false;
                    TextPtr           = Text.Length - 1;
                    _delayAlarm.Set(1 + Text.Length * 0.1);
                }
            }

            var str = "";

            if (!_dead)
            {
                str = Text.Substring(0, TextPtr + 1);
            }

            _targetTextSize = _font.MeasureString(str);

            _textSize.X += (float)GameCntrl.Time((_targetTextSize.X - _textSize.X) / _textRubberBand);
            _textSize.Y += (float)GameCntrl.Time((_targetTextSize.Y - _textSize.Y) / _textRubberBand);

            _targetPos = Test.RoundVector2(Owner.Position + MainOffset);

            _pos.X += (float)GameCntrl.Time((_targetPos.X - _pos.X) / _posRubberBand);
            _pos.Y += (float)GameCntrl.Time((_targetPos.Y - _pos.Y) / _posRubberBand);

            if ((_targetPos - _pos).Length() > _maxBubbleDist)
            {
                var e = _targetPos - _pos;
                e.Normalize();
                _pos = _targetPos + e * _maxBubbleDist;
            }


            if (_delayAlarm.Update())
            {
                //Objects.Destroy(this);
                _dead           = true;
                _textRubberBand = 2f / 60f;
            }

            if (_dead && _textSize.X < 4 && _textSize.Y < 4)
            {
                Objects.Destroy(this);
            }

            var phaseAdd = GameCntrl.Time(_wiggleysSpd);

            for (var i = 0; i < _wiggleys.Length; i += 1)
            {
                _wiggleysPhase[i] += phaseAdd;
                if (_wiggleysPhase[i] > Math.PI * 2)
                {
                    _wiggleysPhase[i] -= Math.PI * 2;
                }

                _wiggleys[i] = new Vector2(
                    (float)Math.Cos(_wiggleysPhase[i]),
                    (float)Math.Sin(_wiggleysPhase[i])
                    ) * _wiggleysR;
            }
        }
        public override void Update()
        {
            PawTrail.Update();

            if (CurrentState == State.Patroling)
            {
                if (GameMath.Distance(Position, _patrolPoints[_currentPointIndex]) < 8)
                {
                    _currentPointIndex += 1;
                    if (_currentPointIndex == _patrolPoints.Count)
                    {
                        _currentPointIndex = 0;
                    }
                }

                var vec = _patrolPoints[_currentPointIndex] - Position;
                vec.Normalize();

                Position += vec * (float)GameCntrl.Time(_speed);

                if (_pawprint.Update())
                {
                    var normVec = new Vector2(vec.Y * _inverse, -vec.X * _inverse) * _stepWidth;
                    PawTrail.AddPawprint(Position + normVec, (float)GameMath.Direction(vec), SpritesDefault.EnemyPaw);
                    _inverse *= -1;
                }

                // Checking for player's trail.
                var player = Objects.ObjFind <Player>(0);

                if (player != null)
                {
                    foreach (Pawprint myPawprint in PawTrail.Pawprints)
                    {
                        foreach (Pawprint playersPawprint in player.PawTrail.Pawprints)
                        {
                            if (!playersPawprint.Destroyed && GameMath.Distance(myPawprint.Position, playersPawprint.Position) < _detectionRadius)
                            {
                                _tracedPawprint = playersPawprint;
                                CurrentState    = State.Alarmed;
                                _pursuingDelayAlarm.Set(_pursuingDelay);
                                break;
                            }
                        }
                        if (_tracedPawprint != null)
                        {
                            break;
                        }
                    }
                }
                // Checking for player's trail.
            }

            if (CurrentState == State.Alarmed)
            {
                if (_pursuingDelayAlarm.Update())
                {
                    if (!_tracedPawprint.Destroyed)
                    {
                        CurrentState = State.Pursuing;
                        _origPos     = Position;
                        Position     = _tracedPawprint.Position;
                    }
                    else
                    {
                        _tracedPawprint = null;
                        CurrentState    = State.Patroling;
                    }
                }
            }

            if (CurrentState == State.Pursuing)
            {
                if (_pursuingAlarm.Update())
                {
                    var player = Objects.ObjFind <Player>(0);

                    var lostTrail = false;

                    if (player != null)
                    {
                        var id = player.PawTrail.Pawprints.IndexOf(_tracedPawprint);
                        if (id == -1 || id == 0)
                        {
                            lostTrail = true;
                        }
                        else
                        {
                            id -= 1;
                            _tracedPawprint = player.PawTrail.Pawprints[id];
                            Position        = _tracedPawprint.Position;
                            if (_tracedPawprint.Destroyed)
                            {
                                lostTrail = true;
                            }
                        }
                    }
                    else
                    {
                        lostTrail = true;
                    }

                    if (lostTrail)
                    {
                        _tracedPawprint = null;
                        CurrentState    = State.Patroling;
                    }

                    int x = (int)player.Position.X / Scene.CellSize;
                    int y = (int)player.Position.Y / Scene.CellSize;

                    if (Test.CurrentScene.TileMap[x, y] != 2 && GameMath.Distance(Position, player.Position) < _detectionRadius * 2)
                    {
                        player.Die();

                        Position     = _origPos;
                        CurrentState = State.Resting;
                        _restingAlarm.Set(_restingTime);
                    }
                }
            }

            if (CurrentState == State.Resting)
            {
                if (_restingAlarm.Update())
                {
                    CurrentState = State.Patroling;
                }
            }
        }