Beispiel #1
0
        public override void OnAllocate()
        {
            base.OnAllocate();

            m_scrollingObject = gameObject.GetComponent <ScrollingObject>();

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

            m_smokePlayer.SetClip(0);
            m_smokePlayer.Play();
        }
Beispiel #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);
        }