Exemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            if (KeyPushed(Keys.Escape))
            {
                // Game.Exit();
            }

            var ctrlLeft  = SosEngine.Core.IsPlayerInputDown(0, SosEngine.Input.PlayerInput.Left) || currentKeyboardState.IsKeyDown(Keys.Left);
            var ctrlRight = SosEngine.Core.IsPlayerInputDown(0, SosEngine.Input.PlayerInput.Right) || currentKeyboardState.IsKeyDown(Keys.Right);
            var ctrlUp    = SosEngine.Core.IsPlayerInputDown(0, SosEngine.Input.PlayerInput.Up) || currentKeyboardState.IsKeyDown(Keys.Up);
            var ctrlDown  = SosEngine.Core.IsPlayerInputDown(0, SosEngine.Input.PlayerInput.Down) || currentKeyboardState.IsKeyDown(Keys.Down);
            var ctrlA     = SosEngine.Core.IsPlayerInputDown(0, SosEngine.Input.PlayerInput.A) || currentKeyboardState.IsKeyDown(Keys.LeftShift);
            var ctrlB     = SosEngine.Core.IsPlayerInputDown(0, SosEngine.Input.PlayerInput.B) || currentKeyboardState.IsKeyDown(Keys.Space);

            player.SetControls(ctrlLeft, ctrlRight, ctrlUp, ctrlDown);

            // Change speed depending on what type of ground player is walking on
            var block = level.GetBlockAtPixel("Block", (int)Math.Round(player.Position.X), (int)Math.Round(player.Position.Y));

            if (block == 15 || block == 16 || block == 35 || block == 36)
            {
                player.Speed = 2;
            }
            else
            {
                player.Speed = 1;
            }


            base.Update(gameTime);
        }
Exemplo n.º 2
0
        protected bool BlockBelowIsBounced()
        {
            int x = (int)Position.X + spriteFrame.Rectangle.Width / 2;
            int y = (int)Position.Y + spriteFrame.Rectangle.Height;
            int bx;
            int by;

            if (level.GetBlockAtPixel("Block", x + level.GetScrollX(), y + 1, out bx, out by) != 0)
            {
                if (level.IsBlockBouncing("Block", bx, by))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        public override void Update(GameTime gameTime)
        {
            if (!Visible)
            {
                return;
            }

            currentMouseState    = Mouse.GetState();
            mouseX               = (int)(SosEngine.Core.RenderWidth / (float)Game.GraphicsDevice.Viewport.Bounds.Width * currentMouseState.X);
            mouseY               = (int)(SosEngine.Core.RenderHeight / (float)Game.GraphicsDevice.Viewport.Bounds.Height * currentMouseState.Y);
            mouseCursor.Position = new Vector2(mouseX, mouseY);
            mouseCursor.SetState(currentMouseState.LeftButton == ButtonState.Pressed);

            leftMouseButtonClicked   = currentMouseState.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed;
            rightMouseButtonClicked  = currentMouseState.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed;
            middleMouseButtonClicked = currentMouseState.MiddleButton == ButtonState.Released && lastMouseState.MiddleButton == ButtonState.Pressed;

            leftMouseButtonJustPressed = currentMouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released;
            dragging = currentMouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Pressed;

            mouseDelta = new Vector2(mouseX, mouseY) - new Vector2(lastMouseX, lastMouseY);

            lastMouseX     = mouseX;
            lastMouseY     = mouseY;
            lastMouseState = currentMouseState;

            level.GetBlockAtPixel("Block", MouseX + 4, mouseY + 4, out mouseBx, out mouseBy);

            if (leftMouseButtonJustPressed)
            {
                level.PutBlock("Block", mouseBx, mouseBy, 64);
            }

            base.Update(gameTime);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Check if player can move to the left.
        /// </summary>
        /// <returns></returns>
        protected bool CanMoveLeft()
        {
            int y = (int)Math.Ceiling(Position.Y) + spriteFrame.Rectangle.Height - 1;
            int x = (int)Math.Floor(Position.X - 6) + spriteFrame.Rectangle.Width / 2;

            if (Helpers.LevelHelper.IsWall(level.GetBlockAtPixel("Block", x, y)))
            {
                return(false);
            }
            if (Helpers.LevelHelper.IsWall(level.GetBlockAtPixel("Block", x, y - 8)))
            {
                return(false);
            }
            if (!isTiny && !isSitting && Helpers.LevelHelper.IsWall(level.GetBlockAtPixel("Block", x, y - 16)))
            {
                return(false);
            }

            // Player can move 4 pixels outside of screen
            if (x < 1 - 4)
            {
                return(false);
            }

            return(true);
        }