コード例 #1
0
        public bool IsIdle(IScreenPad screenPad)
        {
            var keyboardIsIdle  = KeyboardIsIdle();
            var screenPadIsIdle = ScreenPadIsIdle(screenPad);

            return(keyboardIsIdle && screenPadIsIdle);
        }
コード例 #2
0
        protected virtual Rectangle GetAlivePlayerRectangle(IScreenPad screenPad, int tickCount)
        {
            var frameIndex            = 0;
            var frameIndexWhenIdle    = (tickCount / 2) % 2;
            var frameIndexWhenWalking = (frameIndex
                                         + (int)(Position.X)
                                         + (int)(Position.Y)) % 2;

            if (InputManager.Instance.IsIdle(screenPad))
            {
                frameIndex = frameIndexWhenIdle;
            }
            else
            {
                frameIndex = frameIndexWhenWalking;
            }

            var playerRectangle = new Rectangle(
                frameIndex * (int)(Size.X * TileWidth)
                , 0
                , (int)(Size.X * TileWidth)
                , (int)(Size.Y * TileWidth));

            return(playerRectangle);
        }
コード例 #3
0
        protected override Rectangle GetAlivePlayerRectangle(IScreenPad screenPad, int tickCount)
        {
            var frameIndex            = 0;
            var frameIndexWhenIdle    = 1;
            var frameIndexWhenWalking = (frameIndex
                                         + (int)(Position.X)
                                         + (int)(Position.Y)) % PLAYER_STEP_COUNT;

            if (InputManager.Instance.IsIdle(screenPad))
            {
                frameIndex = frameIndexWhenIdle;
            }
            else
            {
                frameIndex = frameIndexWhenWalking;
            }

            var spriteLine = SpriteLine.FaceUp;

            spriteLine = GetSpriteLine();

            var playerRectangle = new Rectangle(
                frameIndex * (int)(Size.X * TileWidth)
                , (int)spriteLine * (int)(Size.Y * TileWidth)
                , (int)(Size.X * TileWidth)
                , (int)(Size.Y * TileWidth));

            return(playerRectangle);
        }
コード例 #4
0
        public void ProcessGamePad(IScreenPad screenPad, PhysicalObject gameMap)
        {
            //var candidatePos = this.Position;
            //var candidateXPos = this.Position;
            //var candidateYPos = this.Position;

            //if (Math.Abs(screenPad.LeftStick.X) + Math.Abs(screenPad.LeftStick.Y) > 0)
            //{
            //    screenPad.LeftStick.Normalize();
            //    candidatePos = this.Position + new Vector2(screenPad.LeftStick.X, -screenPad.LeftStick.Y) * .5f;
            //    candidateXPos = this.Position + new Vector2(screenPad.LeftStick.X, 0) * .5f;
            //    candidateYPos = this.Position + new Vector2(0, -screenPad.LeftStick.Y) * .5f;
            //}

            //var collisionResult = gameMap.TestCollision(this, candidatePos);
            //var collisionXResult = gameMap.TestCollision(this, candidateXPos);
            //var collisionYResult = gameMap.TestCollision(this, candidateYPos);
            //if (collisionResult.CollisionType == CollisionType.None)
            //{
            //    this.Position = candidatePos;
            //}
            //else if (collisionXResult.CollisionType == CollisionType.None)
            //{
            //    this.Position = candidateXPos;
            //}
            //else if (collisionYResult.CollisionType == CollisionType.None)
            //{
            //    this.Position = candidateYPos;
            //}
        }
コード例 #5
0
 public PowerUp(Vector2 position, Player player)
     : base()
 {
     Size           = new Vector2(2, 2);
     StartPosition  =
         Position   = position;
     this.player    = player;
     this.screenPad = Resolver.Instance.Resolve <IScreenPad>();
 }
コード例 #6
0
 public Weapon(Vector2 position, IBasePlayer player)
     : base()
 {
     Size           = new Vector2(2, 2);
     StartPosition  =
         Position   = position;
     this.player    = player;
     this.screenPad = BaseResolver.Instance.Resolve <IScreenPad>();
 }
コード例 #7
0
        public void ProcessGamePad(IScreenPad screenPad, PhysicalObject gameMap, float scrollRows)
        {
            float stepLength = GetStepLength();

            var candidatePositions = SetupScreenPadCandidatePositions(screenPad, stepLength);

            candidatePositions = SetupKeyboardCandidatePositions(stepLength, candidatePositions);
            NormalizeDirection(candidatePositions);
            SetNewPosition(gameMap, scrollRows, candidatePositions);
        }
コード例 #8
0
 public ViewStateBase(GraphicsDeviceManager graphics, ContentManager content, ScreenPad screenPad, BossMovement bossMovement, int levelNumber, string levelName, IJsonMapManager jsonMapManager)
 {
     this.content        = content;
     this.graphics       = graphics;
     this.content        = content;
     this.screenPad      = BaseResolver.Instance.Resolve <IScreenPad>();
     this.levelNumber    = levelNumber;
     this.levelName      = levelName;
     this.topLeftCorner  = new Vector2((screenSize.X - gameScreenSize.X) / 2, (screenSize.Y - gameScreenSize.Y) / 2);
     this.jsonMapManager = jsonMapManager;
     camera2d            = BaseResolver.Instance.Resolve <ICamera2d>();
     DefineActions();
 }
コード例 #9
0
        private CandidatePositions SetupScreenPadCandidatePositions(IScreenPad screenPad, float stepLength)
        {
            var candidatePositions = new CandidatePositions(this.Position);

            if (!screenPad.LeftStickIsIdle)
            {
                screenPad.LeftStick.Normalize();
                candidatePositions.CandidatePos  = this.Position + new Vector2(screenPad.LeftStick.X, -screenPad.LeftStick.Y) * stepLength;
                candidatePositions.CandidateXPos = this.Position + new Vector2(screenPad.LeftStick.X, 0) * stepLength;
                candidatePositions.CandidateYPos = this.Position + new Vector2(0, -screenPad.LeftStick.Y) * stepLength;
            }
            return(candidatePositions);
        }
コード例 #10
0
        protected virtual Rectangle GetAlivePlayerRectangle(IScreenPad screenPad, int tickCount)
        {
            Rectangle playerRectangle;
            var       frameIndex = 0;

            if (screenPad.LeftStick.X + screenPad.LeftStick.Y == 0)
            {
                frameIndex = (tickCount / 2) % 2;
            }
            else
            {
                frameIndex =
                    (frameIndex
                     + (int)(Position.X)
                     + (int)(Position.Y)) % 2;
            }
            playerRectangle = new Rectangle(frameIndex * (int)(Size.X * tileWidth), 0, (int)(Size.X * tileWidth), (int)(Size.Y * tileWidth));
            return(playerRectangle);
        }
コード例 #11
0
 public BasePlayer()
     : base()
 {
     Size      = new Vector2(2f, 2f);
     screenPad = Resolver.Instance.Resolve <IScreenPad>();
 }
コード例 #12
0
        public void ProcessGamePad(IScreenPad screenPad, PhysicalObject gameMap, float scrollRows)
        {
            var candidatePos  = this.Position;
            var candidateXPos = this.Position;
            var candidateYPos = this.Position;

#if WINDOWS_PHONE_APP
            var stepLength = .25f;
#endif

#if WINDOWS_APP
            var stepLength = .15f;
#endif

            if (Math.Abs(screenPad.LeftStick.X) + Math.Abs(screenPad.LeftStick.Y) > 0)
            {
                screenPad.LeftStick.Normalize();
                candidatePos  = this.Position + new Vector2(screenPad.LeftStick.X, -screenPad.LeftStick.Y) * stepLength;
                candidateXPos = this.Position + new Vector2(screenPad.LeftStick.X, 0) * stepLength;
                candidateYPos = this.Position + new Vector2(0, -screenPad.LeftStick.Y) * stepLength;
            }

            var keyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
            {
                candidatePos -= new Vector2(stepLength, 0);
                candidateXPos = this.Position - new Vector2(stepLength, 0);
            }
            else if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
            {
                candidatePos += new Vector2(stepLength, 0);
                candidateXPos = this.Position + new Vector2(stepLength, 0);
            }

            if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
            {
                candidatePos -= new Vector2(0, stepLength);
                candidateYPos = this.Position - new Vector2(0, stepLength);
            }
            else if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
            {
                candidatePos += new Vector2(0, stepLength);
                candidateYPos = this.Position + new Vector2(0, stepLength);
            }

            direction = candidatePos - this.position;

            direction.Normalize();

            var collisionResult  = gameMap.TestCollision(this, candidatePos, scrollRows);
            var collisionXResult = gameMap.TestCollision(this, candidateXPos, scrollRows);
            var collisionYResult = gameMap.TestCollision(this, candidateYPos, scrollRows);
            if (collisionResult.CollisionType == CollisionType.None)
            {
                this.Position = candidatePos;
            }
            else if (collisionXResult.CollisionType == CollisionType.None)
            {
                this.Position = candidateXPos;
            }
            else if (collisionYResult.CollisionType == CollisionType.None)
            {
                this.Position = candidateYPos;
            }
        }
コード例 #13
0
 public virtual void RegisterGame(ContentManager content, IScreenPad screenPad)
 {
     RegisterInstance <IScreenPad>(screenPad);
     RegisterInstance <ICamera2d>(new Camera2d());
 }
コード例 #14
0
        public char GetInputCode(IScreenPad screenPad, int blinkCount)
        {
            var inputCode = InputCodes.Empty;

            if (GameSettings.Instance.PlatformType == PlatformType.WindowsPhone)
            {
                if (screenPad.GetState().Buttons.B == ButtonState.Pressed)
                {
                    buttonBPressed = true;
                }
                else if (screenPad.GetState().Buttons.B == ButtonState.Released && buttonBPressed)
                {
                    buttonBPressed = false;
                    inputCode      = InputCodes.B;
                }
                if (screenPad.GetState().Buttons.A == ButtonState.Pressed)
                {
                    buttonAPressed = true;
                }
                else if (screenPad.GetState().Buttons.A == ButtonState.Released && buttonAPressed)
                {
                    buttonAPressed = false;
                    inputCode      = InputCodes.A;
                }
                if (screenPad.GetState().Buttons.X == ButtonState.Pressed)
                {
                    buttonXPressed = true;
                    inputCode      = InputCodes.X;
                }
                else if (screenPad.GetState().Buttons.X == ButtonState.Released && buttonXPressed)
                {
                    buttonXPressed = false;
                }

                if (screenPad.LeftStick.Y > .75f && (inputCode != 'U' || blinkCount % 4 == 0))
                {
                    inputCode = InputCodes.U;
                }

                if (screenPad.LeftStick.Y < -.75f && (inputCode != 'D' || blinkCount % 4 == 0))
                {
                    inputCode = InputCodes.D;
                }
            }

            if (GameSettings.Instance.PlatformType == PlatformType.Windows ||
                GameSettings.Instance.PlatformType == PlatformType.WindowsUniversal)
            {
                var keyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();
                if (keyboardState.IsKeyDown(xInput.Keys.A))
                {
                    buttonAPressed = true;
                }
                else if (keyboardState.IsKeyUp(xInput.Keys.A) && buttonAPressed)
                {
                    buttonAPressed = false;
                    inputCode      = InputCodes.A;
                }

                if (keyboardState.IsKeyDown(xInput.Keys.B))
                {
                    buttonBPressed = true;
                }
                else if (keyboardState.IsKeyUp(xInput.Keys.B) && buttonBPressed)
                {
                    buttonBPressed = false;
                    inputCode      = InputCodes.B;
                }

                if (keyboardState.IsKeyDown(xInput.Keys.Space))
                {
                    buttonXPressed = true;
                    inputCode      = InputCodes.X;
                }

                if (keyboardState.IsKeyDown(xInput.Keys.Up))
                {
                    buttonUpPressed = true;
                }
                else if (keyboardState.IsKeyUp(xInput.Keys.Up) && buttonUpPressed)
                {
                    buttonUpPressed = false;
                    inputCode       = InputCodes.U;
                }

                if (keyboardState.IsKeyDown(xInput.Keys.Down))
                {
                    buttonDownPressed = true;
                }
                else if (keyboardState.IsKeyUp(xInput.Keys.Down) && buttonDownPressed)
                {
                    buttonDownPressed = false;
                    inputCode         = InputCodes.D;
                }
            }

            return(inputCode);
        }
コード例 #15
0
 private bool ScreenPadIsIdle(IScreenPad screenPad)
 {
     return(screenPad.LeftStick == Vector2.Zero);
 }
コード例 #16
0
 public PlayerBullet6(float damage, IBasePlayer player)
     : base(damage, player)
 {
     speed     = 20f;
     screenPad = Resolver.Instance.Resolve <IScreenPad>();
 }
コード例 #17
0
 public override void RegisterGame(ContentManager content, IScreenPad screenPad)
 {
     base.RegisterGame(content, screenPad);
     RegisterInstance <IScreenPad>(screenPad);
 }