コード例 #1
0
        public static SpriteMario CreateHuDMario(Sprint4 game)
        {
            SpriteMario sprite = new SpriteMario(game);

            sprite.Info.manual = true;
            return(sprite);
        }
コード例 #2
0
        public static SpriteMario CreateMario(Sprint4 game)
        {
            if (SpriteFactory.mario != null)
            {
                return(SpriteFactory.mario);
            }

            return(SpriteFactory.mario = new SpriteMario(game));
        }
コード例 #3
0
        public StateMachineMarioPowerup(SpriteMario mario)
        {
            this.Mario = mario;

            this.Normal = new StatePowerupNormal(this);
            this.Super  = new StatePowerupSuper(this);
            this.Fire   = new StatePowerupFire(this);
            this.Star   = new StatePowerupStar(this);

            this.CurrentState = this.Normal;
            this.CurrentState.Enter(null);
        }
コード例 #4
0
        public StateMachineMarioAction(SpriteMario mario)
        {
            this.Mario = mario;

            this.Idle    = new StateMarioIdle(this);
            this.Walking = new StateMarioWalking(this);
            this.Jump    = new StateMarioJump(this);
            this.Dead    = new StateMarioDead(this);
            this.Falling = new StateMarioFalling(this);

            this.CurrentState = this.Idle;
            this.CurrentState.Enter(null);
        }
コード例 #5
0
        public static void HandleStop(Direction direction, SpriteCollection sprite, SpriteCollection other)
        {
            Rectangle bounds1 = new Rectangle((int)sprite.Info.position.X, (int)sprite.Info.position.Y, sprite.Info.spriteWidth, sprite.Info.spriteHeight);
            Rectangle bounds2 = new Rectangle((int)other.Info.position.X, (int)other.Info.position.Y, other.Info.spriteWidth, other.Info.spriteHeight);

            Rectangle intersection = Rectangle.Intersect(bounds1, bounds2);

            if (direction == Direction.LEFT || direction == Direction.RIGHT)
            {
                if (sprite.Info.bounce)
                {
                    sprite.Info.acceleration.X = -sprite.Info.acceleration.X;
                    sprite.Info.velocity.X     = -sprite.Info.velocity.X;
                }
                else
                {
                    if (direction == Direction.LEFT)
                    {
                        sprite.Info.position.X -= intersection.Width;
                    }
                    else
                    {
                        sprite.Info.position.X += intersection.Width;
                    }

                    sprite.Info.acceleration.X = 0;
                    sprite.Info.velocity.X     = 0;
                }
            }
            else if (direction == Direction.TOP || direction == Direction.BOTTOM)
            {
                if (direction == Direction.TOP)
                {
                    sprite.Info.position.Y -= intersection.Height;
                }
                else
                {
                    sprite.Info.position.Y += intersection.Height;
                }

                sprite.Info.acceleration.Y = 0;
                sprite.Info.velocity.Y     = 0;

                if (sprite is SpriteMario)
                {
                    SpriteMario m            = sprite as SpriteMario;
                    StateMario  currentState = m.StateMachineAction.CurrentState;

                    //Mario is landing
                    if (direction == Direction.TOP)
                    {
                        if (!(currentState is StateMarioWalking))
                        {
                            currentState.ToIdle();
                        }
                    }
                    //Mario is bumping his head
                    else
                    {
                        currentState.ToFall();
                    }
                }
            }
        }