示例#1
0
        public void Frames(GameTime gameTime)
        {
            time      += speed * gameTime.DeltaTime();
            rectFrame += speed * gameTime.DeltaTime();

            // time = MathHelper.Clamp(time, 0, clip.Count);

            if (_loop)
            {
                if (time >= clip.Count)
                {
                    rectFrame = 1f;
                    time      = 0F;
                }
            }

            if (time < clip.Count)
            {
                for (int i = 0; i < clip.Count; i++)
                {
                    if (rectFrame >= (int)time)
                    {
                        rect = clip[(int)time];
                    }
                }
            }

            //Console.WriteLine(" / " + rectFrame + " / " + time);
        }
        public override void OnKeyDown(Keys key, GameTime gameTime, CurrentKeyState currentKeyState)
        {
            if (_menu.Focused)
            {
                _menu.OnKeyDown(key, gameTime, currentKeyState);
                return;
            }

            switch (key)
            {
            case Keys.W:
            case Keys.Up:
                Camera.OffsetPosition(new Vector2(0, -ScrollSpeed / Camera.Zoom) * gameTime.DeltaTime());
                break;

            case Keys.S:
            case Keys.Down:
                Camera.OffsetPosition(new Vector2(0, ScrollSpeed / Camera.Zoom) * gameTime.DeltaTime());
                break;

            case Keys.A:
            case Keys.Left:
                Camera.OffsetPosition(new Vector2(-ScrollSpeed / Camera.Zoom, 0) * gameTime.DeltaTime());
                break;

            case Keys.D:
            case Keys.Right:
                Camera.OffsetPosition(new Vector2(ScrollSpeed / Camera.Zoom, 0) * gameTime.DeltaTime());
                break;
            }
        }
示例#3
0
        public void Update(GameTime gameTime)
        {
            pos      += vel * speed * gameTime.DeltaTime();
            duration -= gameTime.DeltaTime() * 1000;
            if (duration <= 0)
            {
                dead             = true;
                vel              = new Vector2(0);
                ignore_collision = true;
            }

            Sprite.Update(gameTime);
        }
示例#4
0
        public void Update(GameTime gameTime)
        {
            UpdateMoveVec();
            pos += vel * speed * gameTime.DeltaTime();

            Sprite.Update(gameTime);
        }
示例#5
0
        public override void Update(GameTime gameTime)
        {
            // Reduce invincible timer if needed
            if (_invincibleTimer > 0.0f)
            {
                _invincibleTimer -= gameTime.DeltaTime();
            }

            // Calculate player rectangle to be used bay enemies, pacdots and power pellets
            _area = new Rectangle(_position, new Point(Game1.TileSize));

            if (_position == _targetPosition)
            {
                HandleInput();
            }
            else
            {
                // Move player
                Vector2 vec = _targetPosition.ToVector2() - _position.ToVector2();
                vec.Normalize();

                _position = (_position.ToVector2() + (vec * _speed)).ToPoint();

                if ((_position.X + _position.Y) % 8 == 0)
                {
                    _frame++;
                    if (_frame > 1)
                    {
                        _frame = 0;
                    }
                }
            }
        }
示例#6
0
        public void Update(GameTime gameTime)
        {
            AnimExplosionDuration -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (AnimExplosionDuration < 0)
            {
                AnimExplosionDuration = 0;
            }

            Sprite.Update(gameTime);
            ExplosionSprite?.Update(gameTime);

            if (dead)
            {
                return;
            }

            UpdateMoveVec();
            attack_cooldown -= gameTime.DeltaTime() * 1000;

            if (spawned && !spawnFinished)
            {
                SpawnEffectDuration -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                if (SpawnEffectDuration > 0)
                {
                    SpawnEffectSprite.Update(gameTime);
                }
                else
                {
                    spawnFinished = true;
                    active        = true;
                }
            }
        }
示例#7
0
        protected override void Update(GameTime gameTime)
        {
            MouseState mouse = Mouse.GetState();

            {
                grid.SelectedCell = grid.GetCellAt(mouse.Position);

                if (_canPlace)
                {
                    if (mouse.LeftButton == ButtonState.Pressed && _lastMouse.LeftButton == ButtonState.Released)
                    {
                        if (grid.SelectedCell.HasValue)
                        {
                            grid.SetColorUser(grid.SelectedCell.Value.X, grid.SelectedCell.Value.Y, true);

                            CheckDone();
                        }
                    }
                    if (mouse.RightButton == ButtonState.Pressed && _lastMouse.RightButton == ButtonState.Released)
                    {
                        if (grid.SelectedCell.HasValue)
                        {
                            grid.SetColorUser(grid.SelectedCell.Value.X, grid.SelectedCell.Value.Y, false);

                            CheckDone();
                        }
                    }

                    if (mouse.MiddleButton == ButtonState.Pressed && _lastMouse.MiddleButton == ButtonState.Released)
                    {
                        if (grid.SelectedCell.HasValue)
                        {
                            grid.SetMaybe(grid.SelectedCell.Value.X, grid.SelectedCell.Value.Y, !grid.GetMaybe(grid.SelectedCell.Value.X, grid.SelectedCell.Value.Y));
                        }
                    }
                }

                ButtonInput(mouse, _lastMouse);
            }
            _lastMouse = mouse;

            if (solve)
            {
                if ((solveTime -= gameTime.DeltaTime()) <= 0.0f)
                {
                    solveTime = SolveStepTime;

                    if (!grid.SolveCell())
                    {
                        solve = false;
                    }

                    CheckDone();
                }
            }

            base.Update(gameTime);
        }
示例#8
0
    // return true when done
    public bool MoveTowards(Vector3 targetPos, Vector3 targetLookAt, float targetFOV, float targetMoveSecs, float closeEnough)
    {
        Transform thisT = _thisCamera.transform;

        targetMoveSecs *= GameTime.GetRate();

        if (_bMoving)
        {
            thisT.position = Vector3.SmoothDamp(thisT.position, targetPos, ref _curVel, targetMoveSecs);
            if (Vector3.Distance(thisT.position, targetPos) < closeEnough)
            {
                _bMoving = false;
                logger.Debug($"MoveTowards() - Not moving");
            }
        }

        if (_bRotating)
        {
            Vector3    relativePos    = targetLookAt - thisT.position;
            Quaternion targetRotation = Quaternion.LookRotation(relativePos);
            var        step           = kMaxRotRate * GameTime.DeltaTime();
            thisT.rotation = Quaternion.RotateTowards(thisT.rotation, targetRotation, step);
            // gotten there? Note that the rotation can't be considered done until the motion is done
            // Since the latter affects the former
            if ((_bMoving == false) && (Quaternion.Angle(thisT.rotation, targetRotation) < 5))
            {
                _bRotating = false;
            }
        }

        if (_bZooming)
        {
            if (targetFOV <= 0)
            {
                _bZooming = false;
            }
            else
            {
                float dt  = (Time.time - _moveStartTime) / (targetMoveSecs * 2);
                float ang = Mathf.Lerp(_moveStartFOV, targetFOV, dt);
                _thisCamera.fieldOfView = ang;

                // gotten there?
                if (dt >= 1.0)
                {
                    _bZooming = false;
                }
            }
        }

        if (!(_bMoving || _bRotating || _bZooming))
        {
            logger.Debug("MoveTowards() - Got there");
        }

        return(!(_bMoving || _bRotating || _bZooming)); // true if "we are there"
    }
示例#9
0
        public override void Update(GameTime gameTime)
        {
            //movex = transform.position.X -= 25 * gameTime.DeltaTime();


            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                gameObject.GetComponent <Transform>().Move(-speed * gameTime.DeltaTime(), 0);
            }

            else if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                gameObject.GetComponent <Transform>().Move(speed * gameTime.DeltaTime(), 0);
            }

            else if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                gameObject.GetComponent <Transform>().Move(0, speed * gameTime.DeltaTime());
            }

            else if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                gameObject.GetComponent <Transform>().Move(0, -speed * gameTime.DeltaTime());
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Space) && !keyState.IsKeyDown(Keys.Space))
            {
                GameObject tomato = new GameObject();
                tomato.AddComponent(new Tomato());
                tomato.GetComponent <Transform>().position = gameObject.GetComponent <Transform>().position;
                GameObject.Instantiate(tomato);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Q) && !keyState.IsKeyDown(Keys.Q))
            {
                SceneManager.LoadScene(new AnotherOne());
            }

            keyState = Keyboard.GetState();


            gameObject.GetComponent <Transform>().position.Y = MathHelper.Clamp(gameObject.GetComponent <Transform>().position.Y, 0, Screen.bounds.Height - gameObject.GetComponent <Sprite>().rect.Height *gameObject.GetComponent <Sprite>().scale);
            gameObject.GetComponent <Transform>().position.X = MathHelper.Clamp(gameObject.GetComponent <Transform>().position.X, 0, Screen.bounds.Width - gameObject.GetComponent <Sprite>().rect.Width *gameObject.GetComponent <Sprite>().scale);
        }
示例#10
0
    // Update is called once per frame
    void Update()
    {
        //gameNetPerfMarker.Begin();
        gameNet.Loop();
        //gameNetPerfMarker.End();

        //backendPerfMarker.Begin();
        beamApp.Loop(GameTime.DeltaTime());
        //backendPerfMarker.End();
    }
示例#11
0
        public void ApplyMovement(GameTime gameTime)
        {
            var delta = gameTime.DeltaTime();

            if (Rotation != TargetRotation)
            {
                if (Math.Abs(Rotation - TargetRotation) < 1.0f)
                {
                    Rotation = TargetRotation;
                }
                else
                {
                    if (Rotation < TargetRotation)
                    {
                        if (Math.Abs(Rotation - TargetRotation) < 180.0f)
                        {
                            Rotation += TurnSpeed * delta;
                        }
                        else
                        {
                            Rotation -= TurnSpeed * delta;
                        }
                    }
                    else
                    {
                        if (Math.Abs(Rotation - TargetRotation) < 180.0f)
                        {
                            Rotation -= TurnSpeed * delta;
                        }
                        else
                        {
                            Rotation += TurnSpeed * delta;
                        }
                    }
                }

                if (Rotation < 0.0f)
                {
                    Rotation += 360.0f;
                }
                else if (Rotation > 360.0f)
                {
                    Rotation -= 360.0f;
                }
            }

            var forwardVector = new Vector2(0f, -1f);
            var rotaterMatrix = Matrix.CreateRotationZ(MathHelper.ToRadians(Rotation));

            forwardVector = Vector2.TransformNormal(forwardVector, rotaterMatrix);
            Velocity      = forwardVector * MoveSpeed;

            Position += Velocity * delta;
        }
示例#12
0
        public override void update()
        {
            _curAngle += GameTime.DeltaTime() * _degPerSec * Mathf.Deg2Rad;

            Vector3 pos = new Vector3(_radius * Mathf.Cos(_curAngle), _height, _radius * Mathf.Sin(_curAngle));

            pos += _offset;
            pos += _targetObj.transform.position;

            _theGameCam.transform.position = pos;
            _theGameCam.transform.LookAt(_targetObj.transform.position + _offset);
        }
示例#13
0
        public virtual void Update(GameTime gameTime)
        {
            var delta = gameTime.DeltaTime();

            foreach (var weapon in Weapons)
            {
                weapon.CurrentCooldown -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (weapon.CurrentCooldown <= 0)
                {
                    weapon.CurrentCooldown = 0;
                }
            }

            if (!IsShieldActive)
            {
                ShieldCooldown -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                if (ShieldCooldown <= 0)
                {
                    ShieldCooldown = 0;
                    ActivateShield();
                }
            }
            else
            {
                if (CurrentShieldHP <= 0)
                {
                    DeactivateShield();
                }

                CurrentShieldHP += (CurrentShieldRegenRate + GameplayState.UpgradeManager.BonusShieldRegen) * delta;
                if (CurrentShieldHP > BaseShieldHP)
                {
                    CurrentShieldHP = BaseShieldHP;
                }
            }

            if (IsMoving)
            {
                ApplyMovement(gameTime);
            }

            ShieldSprite.Update(gameTime);
            StateMachine.Update(gameTime);

            foreach (var weapon in Weapons)
            {
                if (weapon.MountType == MountType.Turret)
                {
                    AIHelper.HandleTurret(this, weapon, gameTime);
                }
            }
        } // Update
示例#14
0
        public override void Update(GameTime gameTime)
        {
            // Reduce run away timer
            _isRunningAway = _runAwayTimer > 0.0f;

            if (_isRunningAway)
            {
                _runAwayTimer -= gameTime.DeltaTime();
            }

            // Reduce cooldown
            if (_cooldown > 0.0f)
            {
                _cooldown -= gameTime.DeltaTime();
                return;
            }

            Move();

            Intersections();
        }
示例#15
0
        public void Update(GameTime gameTime)
        {
            if (Velocity != Vector2.Zero)
            {
                var delta = gameTime.DeltaTime();

                _position += Velocity * delta;
            }

            _view.X = (int)_position.X;
            _view.Y = (int)_position.Y;

            CheckBoundingBox();
        }
示例#16
0
        public override void update()
        {
            if (_bike == null)                                            // target went away (gameobject refs get autonulled on destroy)
            {
                _theGameCam.SetMode(CamModeID.kNormal).init(_theGameCam); // when we get there switch to "normal"
            }
            else
            {
                Vector3 posOffset = new Vector3(0, _height, -_radius);
                Vector3 pos       = TargetCamPos(_bike, posOffset);
                Vector3 lookAt    = TargetCamLookat(_bike, _lookAngle, _viewHeight);
                _theGameCam.MoveTowards(pos, lookAt, -1, .2f, kZeroDist);

                float lookSign = Mathf.Sign(_lookAngle);
                float absLA    = Mathf.Max(0, Math.Abs(_lookAngle) - (GameTime.DeltaTime() * _lookDecayRate));
                _lookAngle = lookSign * absLA;
            }
        }
示例#17
0
    // Update is called once per frame
    protected void Update()
    {
        float frameMs = GameTime.DeltaTime();

        if (bMoving)
        {
            transform.localPosition = Vector3.SmoothDamp(transform.localPosition, targetPos, ref curVel, switchSecs);
            if (Vector3.Distance(transform.localPosition, targetPos) < kZeroDist)
            {
                bMoving = false;
                curVel  = Vector3.zero;
            }
        }

        secsLeft -= frameMs;
        if (secsLeft <= 0)
        {
            mgr?.RemoveToast(this);
        }
    }
示例#18
0
        private void UpdateScaling(GameTime gameTime)
        {
            if (_scaleDirection == ScaleDirection.None)
            {
                return;
            }

            Scale += (_scaleChangePerSecond * gameTime.DeltaTime()) * (float)_scaleDirection;

            if (_scaleDirection == ScaleDirection.ScaleUp && Scale >= _targetScale)
            {
                _scaleDirection = ScaleDirection.None;
                Scale           = _targetScale;
                IsScaling       = false;
            }
            else if (_scaleDirection == ScaleDirection.ScaleDown && Scale <= _targetScale)
            {
                _scaleDirection = ScaleDirection.None;
                Scale           = _targetScale;
                IsScaling       = false;
            }
        }
        public override void Update(GameTime gameTime)
        {
            if (Vector2.Distance(Target.Position, ParentShip.Position) <= FollowDistance)
            {
                if (Target.IsMoving)
                {
                    ParentShip.MoveSpeed = Target.MoveSpeed;
                    ParentShip.SetDestination(Target.Position);
                }
                else
                {
                    ParentShip.StopMovement();
                }

                Target.RepairArmour(RepairRate * gameTime.DeltaTime());
            }
            else
            {
                ParentShip.MoveSpeed = ParentShip.BaseMoveSpeed;
                ParentShip.SetDestination(Target.Position);
            }
        }
示例#20
0
        public void Update(GameTime gameTime)
        {
            // Doors don't unlock until the opening animation plays, the duration is open_time
            if (unlocking)
            {
                open_timer += gameTime.DeltaTime();
                if (open_timer >= open_time)
                {
                    locked     = false;
                    unlocking  = false;
                    open_timer = 0.0f;
                    if (!draw_if_unlocked)
                    {
                        draw = false;
                    }
                }
            }

            if (animated)
            {
                Sprite.Update(gameTime);
            }
        }
示例#21
0
        private void UpdateFade(GameTime gameTime)
        {
            if (_fadeDirection == FadeDirection.None)
            {
                return;
            }

            _fadeTransparency += (_fadeChangePerSecond * gameTime.DeltaTime()) * (float)_fadeDirection;

            if (_fadeDirection == FadeDirection.FadeIn && _fadeTransparency >= _targetTransparency)
            {
                _fadeTransparency = _targetTransparency;
                _fadeDirection    = FadeDirection.None;
                IsFading          = false;
            }
            else if (_fadeDirection == FadeDirection.FadeOut && _fadeTransparency <= _targetTransparency)
            {
                _fadeTransparency = _targetTransparency;
                _fadeDirection    = FadeDirection.None;
                IsFading          = false;
            }

            Colour.A = (byte)_fadeTransparency;
        }
示例#22
0
        private void UpdateRotation(GameTime gameTime)
        {
            if (_rotationDirection == RotationDirection.None)
            {
                return;
            }

            float change = _rotationChangePerSecond * gameTime.DeltaTime();

            if (_rotationAmount - change < 0)
            {
                change = _rotationAmount;
            }

            Rotation += change * (float)_rotationDirection;

            _rotationAmount -= change;

            if (_rotationAmount <= 0)
            {
                _rotationDirection = RotationDirection.None;
                IsRotating         = false;
            }
        }
示例#23
0
 public void Update(GameTime gameTime)
 {
     Rotation += RotationSpeed * gameTime.DeltaTime();
 }
示例#24
0
        public virtual void Update(GameTime gameTime)
        {
            var delta = gameTime.DeltaTime();

            ShieldSprite.Update(gameTime);
            StateMachine.Update(gameTime);

            Position += Velocity * delta;

            foreach (var weapon in Weapons)
            {
                weapon.CurrentCooldown -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (weapon.CurrentCooldown <= 0)
                {
                    weapon.CurrentCooldown = 0;
                }
            }

            if (!IsShieldActive)
            {
                ShieldCooldown -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                if (ShieldCooldown <= 0)
                {
                    ShieldCooldown = 0;
                    ActivateShield();
                }
            }
            else
            {
                if (CurrentShieldHP <= 0)
                {
                    DeactivateShield();
                }
                else
                {
                    CurrentShieldHP += CurrentShieldRegenRate * delta;
                    if (CurrentShieldHP > BaseShieldHP)
                    {
                        CurrentShieldHP = BaseShieldHP;
                    }
                }
            }

            if (Moving)
            {
                TargetRotation = GetAngleToTarget(Destination);

                if (Rotation != TargetRotation)
                {
                    if (TargetRotation > Rotation)
                    {
                        Rotation += TurnSpeed * gameTime.DeltaTime();
                        if (Rotation > TargetRotation)
                        {
                            Rotation = TargetRotation;
                        }
                    }
                    else
                    {
                        Rotation -= TurnSpeed * gameTime.DeltaTime();
                        if (Rotation < TargetRotation)
                        {
                            Rotation = TargetRotation;
                        }
                    }
                }

                var forwardVector = new Vector2(0f, -1f);
                var rotaterMatrix = Matrix.CreateRotationZ(MathHelper.ToRadians(Rotation));
                forwardVector = Vector2.TransformNormal(forwardVector, rotaterMatrix);
                Velocity      = forwardVector * MoveSpeed;
            }
        } // Update
示例#25
0
 protected override void Update(GameTime gameTime)
 {
     inputManager.Update(gameTime.DeltaTime());
     base.Update(gameTime);
 }
 public override void Update(GameTime gameTime)
 {
     movex = gameObject.GetComponent <Transform>().position.X -= 250 * gameTime.DeltaTime();
 }
        public void Update(GameTime gameTime)
        {
            var pos = MathHelper.Clamp(rigidbody.Position.X, 0, ConvertUnits.ToSimUnits(Screen.width - rect.Width));

            rigidbody.Position = new Vector2(pos, rigidbody.Position.Y);

            buttonPressed = false;

            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                rigidbody.Position = new Vector2(rigidbody.Position.X + moveSpeed * gameTime.DeltaTime(), rigidbody.Position.Y);

                buttonPressed = true;

                flip = SpriteEffects.None;

                if (grounded && aniState != AnimationState.Jump)
                {
                    aniState = AnimationState.Walk;
                }
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                rigidbody.Position = new Vector2(rigidbody.Position.X - moveSpeed * gameTime.DeltaTime(), rigidbody.Position.Y);

                buttonPressed = true;

                flip = SpriteEffects.FlipHorizontally;

                if (grounded && aniState != AnimationState.Jump)
                {
                    aniState = AnimationState.Walk;
                }
            }

            if (ControlInput.IsKeyPressed(Keys.Space) && grounded && aniState != AnimationState.Jump)
            {
                rigidbody.ApplyForce(new Vector2(0f, jumpForce));
                aniState = AnimationState.Jump;
            }

            if (ControlInput.IsKeyPressed(Keys.R))
            {
                rigidbody.Position = ConvertUnits.ToSimUnits(initPos);
                rigidbody.ResetDynamics();
            }

            Raycast();

            if (!grounded && aniState != AnimationState.Jump)
            {
                aniState = AnimationState.Fall;
            }
            else if (!grounded && rigidbody.LinearVelocity.Y > 0)
            {
                aniState = AnimationState.Fall;
            }
            else if (grounded && !buttonPressed && aniState != AnimationState.Jump)
            {
                aniState = AnimationState.Idle;
            }
            else if (grounded && aniState == AnimationState.Jump && !ControlInput.IsKeyPressed(Keys.Space))
            {
                aniState = AnimationState.Idle;
            }

            // Console.WriteLine(grounded + " / " + aniState);

            //Console.WriteLine(rigidbody.LinearVelocity.Y);

            setClip();
            animator.Frames(gameTime);
            animator.Update(gameTime);
            rect = animator.UpdateRect;
        }
示例#28
0
 public virtual void Update(GameTime gameTime)
 {
     Duration -= gameTime.ElapsedGameTime.TotalMilliseconds;
     Position += Velocity * gameTime.DeltaTime();
 }