示例#1
0
文件: Coin.cs 项目: ninify13/GSTJ
        public override void OnAllocate()
        {
            base.OnAllocate();

            m_scrollingObject = gameObject.GetComponent <ScrollingObject>();

            m_coinPlayer.SetClip(0);
            m_coinPlayer.Play();
        }
示例#2
0
        public void Init(Vector3 position)
        {
            transform.position = position;

            m_smokePlayer.SetClip(0);
            m_smokePlayer.Play();
        }
示例#3
0
        public void Update(float dt, bool allowInput)
        {
            // Update physics
            Position += Velocity * dt;
            Velocity += (0, 500 * dt);

            // Update sprite player
            SpritePlayer.Update(dt);

            // Hit "floor"
            if (Position.Y > 0)
            {
                _onGround = true;

                if (Velocity.X == 0F && SpritePlayer.Animation.Name != "idle")
                {
                    SpritePlayer.Play("idle");
                }

                Position.Y = 0;
                Velocity.Y = 0;
            }

            //
            if (Position.X < -400)
            {
                Position.X = -400;
            }
            if (Position.X > +400)
            {
                Position.X = +400;
            }

            if (allowInput)
            {
                if (_onGround && Input.CheckKey(Key.Space, ButtonState.Down))
                {
                    Velocity -= (0, 300);
                    SpritePlayer.Play("jump");
                    _onGround = false;
                }

                var pressLeft  = Input.CheckKey(Key.A, ButtonState.Down);
                var pressRight = Input.CheckKey(Key.D, ButtonState.Down);
                if (pressLeft || pressRight)
                {
                    // If on the ground, begin walking
                    if (_onGround && SpritePlayer.Animation.Name != "walk")
                    {
                        SpritePlayer.Play("walk");
                    }

                    if (pressLeft)
                    {
                        Velocity.X -= 300 * dt;
                        _flip       = true;
                    }
                    else
                    {
                        Velocity.X += 300 * dt;
                        _flip       = false;
                    }
                }
                else if (_onGround)
                {
                    // Stop
                    SpritePlayer.Play("idle");
                    Velocity.X = 0F;
                }
            }

            if (Calc.Abs(Velocity.X) > 200)
            {
                Velocity.X = 200 * Calc.Sign(Velocity.X);
            }

            // Emote logic
            ProcessEmotes(dt);
        }