示例#1
0
        override public void Update(float speed)
        {
            springSprite.Position    = new Vector2(springSprite.Position.X - speed, springSprite.Position.Y);
            springSprite2.Position   = new Vector2(springSprite2.Position.X - speed, springSprite2.Position.Y);
            springTopSprite.Position = new Vector2(springTopSprite.Position.X - speed, springTopSprite.Position.Y);

            trap.Update(speed);
            pit.Update(speed);

            if (springReleased)
            {
                // Spring can move too fast for collisions, split it up
                int   iterations    = (int)FMath.Ceiling(speed / 3.0f);
                float speedPerCycle = speed / iterations;

                for (int i = 0; i < iterations; i++)
                {
                    // Update collision box
                    _min.X   = springTopSprite.Position.X;
                    _min.Y   = springTopSprite.Position.Y;
                    _max.X   = springTopSprite.Position.X + springTopTextureInfo.TextureSizef.X;
                    _max.Y   = springTopSprite.Position.Y + springTopTextureInfo.TextureSizef.Y;
                    _box.Min = _min;
                    _box.Max = _max;

                    // Check for collision with player
                    if (AppMain.GetPlayer().GetBottomBox().Overlaps(_box))
                    {
                        missedSpring = false;
                        AppMain.GetPlayer().DoJump();
                    }

                    // Update spring height
                    if (springCurrentHeight < springOriginalHeight)
                    {
                        springTopSprite.Position = new Vector2(springTopSprite.Position.X, springTopSprite.Position.Y + (speedPerCycle * 5));
                        springCurrentHeight     += (speedPerCycle * 5);
                        springSprite.Scale       = new Vector2(springSprite.Scale.X, springCurrentHeight / springOriginalHeight);
                        springSprite2.Scale      = new Vector2(springSprite2.Scale.X, springCurrentHeight / springOriginalHeight);
                    }

                    if (springCurrentHeight <= 55)
                    {
                        AppMain.GetSoundManager().PlayJump();
                    }

                    else
                    {
                        springReleased = false;
                    }
                }
            }
            else if (beingPushed)
            {
                WindSpring(speed);
            }

            Vector2 touchPos = AppMain.GetTouchPosition();

            if ((touchPos.X - 100 < springSprite.Position.X) &&
                (touchPos.X + 125 > springSprite2.Position.X + springWidth) &&
                (touchPos.Y - (springTopHeight / 5) > springTopSprite.Position.Y))        // Touching spring
            {
                PushSpring();
            }

            if (Touch.GetData(0).ToArray().Length <= 0)
            {
                ReleaseSpring(true);
            }

            if (magmaTrap && missedSpring && AppMain.GetPlayer().GetPos().X > springSprite2.Position.X + springTopWidth * 1.5)
            {
                AppMain.GetPlayer().KillByFire();
            }


            if (!magmaTrap && missedSpring && AppMain.GetPlayer().GetPos().X > springSprite2.Position.X + springTopWidth * 1.5)
            {
                AppMain.GetPlayer().KillByFire();
            }
        }