Пример #1
0
        public Mario(Game1 game, Scene scene)
        {
            MarioFactory = new MarioFactory(game);
            currentSprite = (MarioSprite)MarioFactory.MakeProduct(1);
            powerupStateFactor = 0;
            actionStateFactor = 1;
            direction = 1;
            idle = new MarioIdleState(this);
            jump = new MarioJumpingState(this);
            walk = new MarioWalkingState(this);
            crouch = new MarioCrouchingState(this);
            fall = new MarioFallingState(this);
            standard = new MarioStandard(this);
            super = new MarioSuper(this);
            fire = new MarioFire(this);
            dead = new MarioDead(this);
            powerupState = standard;
            currentState = idle;
            previousState = currentState;
            previousSprite = currentSprite;
            this.game = game;
            this.scene = scene;
            gravity = scene.Gravity;

            isGrounded = false;

            points = 0;
            coins = 10;
            lives = 3;
            sounds = new SoundMachine(game);
        }
Пример #2
0
        public Mario(Game1 game, int posX, int posY)
        {
            MarioFactory = new MarioFactory(game);
            currentSprite = (MarioSprite)MarioFactory.MakeProduct(1);
            powerupStateFactor = 0;
            actionStateFactor = 1;
            direction = 1;
            idle = new MarioIdleState(this);
            jump = new MarioJumpingState(this);
            walk = new MarioWalkingState(this);
            crouch = new MarioCrouchingState(this);
            fall = new MarioFallingState(this);
            standard = new MarioStandard(this);
            super = new MarioSuper(this);
            fire = new MarioFire(this);
            dead = new MarioDead(this);

            powerupState = standard;
            currentState = idle;
            previousState = currentState;
            previousSprite = currentSprite;

            marioVec.X = posX;
            marioVec.Y = posY;
        }
Пример #3
0
        public void Update(float elapsed, GraphicsDeviceManager graphics, MarioCollision collision)
        {
            if (currentState == dead)
            {
                if (buffer < 1000)
                {
                    buffer += elapsed;
                }
                else
                {
                    buffer = 0;
                    if (lives > 0)
                    {
                        Vector2 latestCheck = game.scene.FindLatestCheckpoint();
                        int life = lives;
                        game.ResetCommand();//Why isn't the theme music playing?
                        game.scene.mario.MarioVec = latestCheck;
                        game.scene.mario.Lives = life;
                    }
                    else
                    {
                        game.scene.Mute();
                        sounds.PlayGameOver();
                        game.GameoverCommand();
                    }
                }

            }
            else
            {
                gravity = scene.Gravity;
                this.elapsed = elapsed;
                if (time > 1000)
                {
                    invincible = false;
                }
                if (invincible == true)
                {
                    time += elapsed;
                }

                marioVel += marioAccel * collision.CollisionTime / 5;
                marioVel = Vector2.Clamp(marioVel, new Vector2(-20, -40), new Vector2(20, 40));
                marioVec += marioVel * collision.CollisionTime / 5;

            }

                actionStateFactor = currentState.Factor();
                powerupStateFactor = powerupState.Factor();
                currentSprite = (MarioSprite)MarioFactory.MakeProduct(powerupStateFactor + actionStateFactor);
                currentSprite.CollisionBox.Physics(new Vector2(marioVec.X, marioVec.Y - CollisionBox.Height), marioVel, marioAccel);
                currentSprite.Update(elapsed, direction);
                currentState.Update(graphics, elapsed);

                //if (!isGrounded && currentState != jump)
                //{
                //    this.ToFall();
                //}
                Console.WriteLine(MarioVel);
                //////////////////////////////////////
                CheckBorders();
        }
Пример #4
0
 public void Update(float elapsed, GraphicsDeviceManager graphics)
 {
     actionStateFactor = currentState.Factor();
        powerupStateFactor = powerupState.Factor();
        currentSprite = (MarioSprite)MarioFactory.MakeProduct(powerupStateFactor + actionStateFactor);
        currentSprite.CollisionBox.Physics(new Vector2(MarioVec.X, MarioVec.Y-CollisionBox.Height), Vector2.Zero, Vector2.Zero);
        currentSprite.Update(elapsed, direction);
        currentState.Update(graphics);
 }