示例#1
0
        public void Update()
        {
            _doJump     = Input.GetAxis("Vertical") > 0;
            _xAxisInput = Input.GetAxis("Horizontal");
            var goSideWay = Mathf.Abs(_xAxisInput) > _movingThresh;

            if (IsGrounded())
            {
                //walking
                if (goSideWay)
                {
                    GoSideWay();
                }
                _spriteAnimator.StartAnimation(_view._spriteRenderer, goSideWay ? AnimState.Run : AnimState.Idle, true, _animationSpeed);

                //start jump
                if (_doJump && _yVelocity == 0)
                {
                    _yVelocity = _jumpStartSpeed;
                }
                //stop jump
                else if (_yVelocity < 0)
                {
                    _yVelocity = 0;
                    _view._transform.position = _view._transform.position.Change(y: _groundLevel);
                }
            }
            else
            {
                //flying
                if (goSideWay)
                {
                    GoSideWay();
                }
                if (Mathf.Abs(_yVelocity) > _flyThresh)
                {
                    _spriteAnimator.StartAnimation(_view._spriteRenderer, AnimState.Jump, false, _animationSpeed);
                }
                _yVelocity += _g * Time.deltaTime;
                _view._transform.position += Vector3.up * (Time.deltaTime * _yVelocity);
            }
        }
示例#2
0
        private void Awake()
        {
            _inits    = new List <IInit>();
            _updaters = new List <IUpdate>();

            var backgroundData = Resources.Load <BackgroundData>("BackgroundCfg");

            _palaraxManager = new PalaraxManager(backgroundData, _camera.transform);
            _inits.Add(_palaraxManager);
            _updaters.Add(_palaraxManager);

            var playerConfig = Resources.Load <SpriteAnimatorConfig>("AnimPlayerCfg");

            _playerAnimator = new SpriteAnimator(playerConfig);
            _playerAnimator.StartAnimation(_playerView._spriteRenderer, AnimState.Run, true, _animationSpeed);
            _playerController = new PlayerMove(_playerView, _playerAnimator);

            var aimingMuzzle = new AimingMuzzle(_muzzelTurel, _playerView._transform);

            List <BulletView> bulletList = new List <BulletView>()
            {
                Object.Instantiate(Resources.Load <BulletView>("bullet"), Vector3.zero, Quaternion.identity),
                Object.Instantiate(Resources.Load <BulletView>("bullet"), Vector3.zero, Quaternion.identity),
                Object.Instantiate(Resources.Load <BulletView>("bullet"), Vector3.zero, Quaternion.identity),
                Object.Instantiate(Resources.Load <BulletView>("bullet"), Vector3.zero, Quaternion.identity),
                Object.Instantiate(Resources.Load <BulletView>("bullet"), Vector3.zero, Quaternion.identity),
                Object.Instantiate(Resources.Load <BulletView>("bullet"), Vector3.zero, Quaternion.identity)
            };
            var bulletEmiter = new BulletsEmitter(bulletList, _muzzelTurel);

            _updaters.Add(_playerAnimator);
            _updaters.Add(_playerController);
            _updaters.Add(aimingMuzzle);
            _updaters.Add(bulletEmiter);

            Init();
        }