示例#1
0
        public override void Update(GameTime gameTime)
        {
            float seconds = (float)gameTime.ElapsedGameTime.TotalSeconds;

            #region Stabilization:
            //Correcting angle:
            mainBody.Rotation = mainBody.Rotation % MathHelper.TwoPi;
            //This object wont get high algunar speeds:
            mainBody.AngularVelocity = 0;
            //Stabilizators logic:
            StabilizeJoint.Enabled = false;
            if (leftwheelContacts == 0)
            {
                if (rightwheelContacts > 0)
                {
                    Vector2 worldImpulse = mainBody.GetWorldVector(Vector2.UnitY) * 10f * seconds;
                    Vector2 worldPoint   = mainBody.GetWorldPoint( ((CircleShape)WheelL.Shape).Position );
                    mainBody.ApplyLinearImpulse(worldImpulse, worldPoint);
                }
                else
                {
                    StabilizeJoint.Enabled = true;
                    StabilizeJoint.MaxImpulse = 1 / 200f;
                    StabilizeJoint.TargetAngle = 0f;
                    if (onAir)
                    {
                        StabilizeJoint.MaxImpulse = float.MaxValue;
                        StabilizeJoint.TargetAngle = MathHelper.ToRadians(lookingLeft ? 20f : -20f);
                    }
                }
            }
            else
            {
                if (rightwheelContacts == 0)
                {
                    Vector2 worldImpulse = mainBody.GetWorldVector(Vector2.UnitY) * 10f * seconds;
                    Vector2 worldPoint = mainBody.GetWorldPoint(((CircleShape)WheelR.Shape).Position);
                    mainBody.ApplyLinearImpulse(worldImpulse, worldPoint);
                }
                else
                {
                }
            }
            #endregion

            if (wheelContacts == 0) timeOnAir += seconds;
            else timeOnAir = 0f;
            jumpedTime += seconds;

            float linearSpeed = mainBody.LinearVelocity.Length();
            if (!onAir && isMoving)
            {

                if (linearSpeed < 10f)
                {
                    sprite = walkSprite;
                    sprite.framesPerSecond = Geom.line(linearSpeed, 0f, 4f, 10f, 18f);
                }
                else
                {
                    sprite = runSprite;
                    sprite.framesPerSecond = Geom.line(linearSpeed, 10f, 8f, 20f, 24f);
                }
                sprite.play();
            }
            else if (onAir)
            {
                sprite = fallSprite;
                sprite.play();
            }
            else if (linearSpeed > 0.1f)
            {
                sprite = runSprite;
                sprite.gotoAndStop(9);
            }
            else
            {
                sprite = standSprite;
                sprite.play();
            }

            if(mainBody.Awake) resetNTImpulses();

            sprite.rotation = getBody(0).Rotation;
            sprite.position = getBody(0).Position;
            sprite.Update(gameTime);

            base.Update(gameTime);
        }
示例#2
0
        protected virtual void loadContent(ContentManager content)
        {
            player.loadContent(content);
            scenario.loadContent(content);

            sf = content.Load<SpriteFont>("Fonts/gamefont");

            if (background == null)
            {
                background = content.Load<Texture2D>("Levels/FondoTest");
            }

            foreach (Collectible c in collectibles)
            {
                c.loadContent(content);
            }

            myEffect = content.Load<ParticleEffect>(@"Particles/BasicExplosion");
            myEffect.LoadContent(content);
            myEffect.Initialise();
            myRenderer.LoadContent(content);
            sbRenderer.LoadContent(content);

            special = new SpriteSheet(ScreenManager.Game, content.Load<Texture2D>("collectiblePez"), 2,2, ScreenManager.SpriteBatch);
            special.scale = 40f / special.frameWidth;

            simple = new SpriteSheet(ScreenManager.Game, content.Load<Texture2D>("collectibleLeche"), 2, 2, ScreenManager.SpriteBatch);
            simple.scale = 40f / simple.frameWidth;
            simple.gotoAndStop(1);

            debugView.LoadContent(ScreenManager.Game.GraphicsDevice, content);
        }