Esempio n. 1
0
        public Mario(Vector2 position) : base(SprintFourGame.GetInstance())
        {
            UpdateOrder = int.MaxValue;//update immediately before responsemanager
            Position = position;
            Sprite = new MarioSprite(this);
            invincibility = Utility.ZERO;
            CurrentState = new IdleMarioState(true, (int)MarioStateBase.PowerLevel.Small, this);
            ScoreMult = Utility.ONE;
            IsInWarpPipe = false;
            DrawOrder = Utility.MARIO_DRAW_ORDER;

        }
Esempio n. 2
0
        public override void Update(GameTime gameTime)
        {
            float elapsed = (float) gameTime.ElapsedGameTime.TotalSeconds;

            if (!(CurrentState is BigToSmallMarioState || CurrentState is FireToBigMarioState))
            {
                if (invincibility > Utility.ZERO) --invincibility;
                if (starTime > Utility.ZERO) --starTime;
                else if (SoundManager.State == BGMusicState.Star) SoundManager.State = BGMusicState.Normal;
            }
            
            if (invincibility < starTime) invincibility = starTime;
            if (fireBallDelay > Utility.ZERO) --fireBallDelay;

            Velocity *= new Vector2(Utility.ONE - elapsed * Friction, Utility.ONE);

            //Don't allow mario to move offscreen
            float effectiveX = Background.Camera.Position.X / Utility.CAMERA_SCALE;
            if (Position.X < effectiveX)
            {
                Position = new Vector2(effectiveX, Position.Y);
            }

            
            if (OnGround)
            {
                //Revert to standing if slow enough
                if (Math.Pow(Velocity.X,Utility.TWO) < Utility.VELOCITY_TOLERANCE)
                {
                    CurrentState = new IdleMarioState(CurrentState.FacingRight, CurrentState.Row, this);
                    Velocity = Vector2.Zero;
                }
                else
                {
                    //Walking off of cliffs, current implementation allows proper dashing over gaps
                    if (!SprintFourGame.GetInstance().level.BlockUnder(Bounds))
                    {
                        OnGround = false;
                        CurrentState = new JumpingMarioState(CurrentState.FacingRight, CurrentState.Row, this);                       
                    }
                }
            }
            else
            {
                if (SprintFourGame.GameState.Winning != SprintFourGame.GetInstance().CurrentGameState)
                    Velocity += Gravity*elapsed;
                else
                {
                    Velocity = new Vector2(Velocity.X, Gravity.Y* Utility.MARIO_FLAG_SLIDE_SPEED * elapsed);
                }
            }
            if (Position.Y > Background.Camera.WorldMax.Y + Background.Camera.ScreenDim.Y)
            {
                SprintFourGame.GetInstance().Reset();
            }
            if (IsInWarpPipe) CurrentState = new ForcedCrouchingMarioState(true, CurrentState.Row, this);
            CurrentState.Update();
            Sprite.Update();
            base.Update(gameTime);

        }