Exemplo n.º 1
0
        public void Update(TileMap tileMap)
        {
            Vector2 move = target.position - position;

            move.Normalize();
            move *= speed;
            if (tileMap.Walkable(position + move) &&
                tileMap.Walkable(position + move + new Vector2(texture.Width, 0)) &&
                tileMap.Walkable(position + move + new Vector2(0, texture.Height)) &&
                tileMap.Walkable(position + move + new Vector2(texture.Width, texture.Height)))
            {
                position += move;
            }

            Rectangle rectE = new Rectangle(position.ToPoint(), new Point(texture.Width, texture.Height));
            Rectangle rectP = new Rectangle(target.position.ToPoint(), new Point(target.texture.Width, target.texture.Height));

            if (rectE.X < rectP.X + rectP.Size.X &&
                rectE.X + rectE.Size.X > rectP.X &&
                rectE.Y < rectP.Y + rectP.Size.Y &&
                rectE.Y + rectE.Size.Y > rectP.Y)
            {
                target.ApplyDamage(100);
            }
        }
Exemplo n.º 2
0
        void KeyboardInput()
        {
            KeyboardState key = Keyboard.GetState();

            move.Y += gForce;
            move.X  = 0;



            // KEY BLOCK

            if ((key.IsKeyDown(Keys.Left) || key.IsKeyDown(Keys.A)) && !(wallslideR || wallslideL || (phaseOne && walljumpL)))
            {
                if (!jump)
                {
                    move.X -= 2;
                }
                move.X -= 3;
            }

            if ((key.IsKeyDown(Keys.Right) || key.IsKeyDown(Keys.D)) && !(wallslideR || wallslideL || (phaseOne && walljumpR)))
            {
                if (!jump)
                {
                    move.X += 2;
                }
                move.X += 3;
            }

            if (key.IsKeyDown(Keys.Down) || key.IsKeyDown(Keys.S) && move.Y < 0)
            {
                move.Y     = 2;
                drop       = true;
                wallslideL = false;
                wallslideR = false;
            }

            if (key.IsKeyDown(Keys.Space) && !jump)
            {
                move.Y = -4;
                jump   = true;

                if (move.X < 0)
                {
                    jumpMove = -2;
                }
                if (move.X > 0)
                {
                    jumpMove = 2;
                }
                if (move.X == 0)
                {
                    jumpMove = 0;
                }

                if (wallslideR)
                {
                    wallslideR = false;
                    walljumpR  = true;
                }

                if (wallslideL)
                {
                    wallslideL = false;
                    walljumpL  = true;
                }
            }

            //EXECUTIV BLOCK

            if (walljumpR)
            {
                move.X -= 1;
                if (move.Y < 0)
                {
                    phaseOne = true;
                }
                else
                {
                    phaseOne = false;
                }
            }

            if (walljumpL)
            {
                move.X += 1;
                if (move.Y < 0)
                {
                    phaseOne = true;
                }
                else
                {
                    phaseOne = false;
                }
            }
            if (jump)
            {
                move.X += jumpMove;
            }



            // COLLISON BLOCK

            TileMap tileMap = GameStuff.Instance.tilemap;

            if (move.Y > 0 && (!tileMap.Walkable(new Vector2(position.X, position.Y + move.Y + texture.Height)) ||
                               !tileMap.Walkable(new Vector2(position.X + texture.Width, position.Y + move.Y + texture.Height))))
            {
                move.Y = 0;


                // DROP POINT
                jump       = false;
                drop       = false;
                wallslideL = false;
                wallslideR = false;
                walljumpL  = false;
                walljumpR  = false;
                phaseOne   = false;
            }

            if ((move.Y < 0 && (!tileMap.Walkable(new Vector2(position.X, position.Y + move.Y)) ||
                                !tileMap.Walkable(new Vector2(position.X + texture.Width, position.Y + move.Y)))))

            {
                move.Y = 0;
            }

            if ((move.X < 0 && (!tileMap.Walkable(new Vector2(position.X + move.X, position.Y)) ||
                                !tileMap.Walkable(new Vector2(position.X + move.X, position.Y + texture.Height)))) ||
                (move.X > 0 && (!tileMap.Walkable(new Vector2(position.X + move.X + texture.Width, position.Y)) ||
                                !tileMap.Walkable(new Vector2(position.X + move.X + texture.Width, position.Y + texture.Height)))))
            {
                if (tileMap.Walkable(new Vector2(position.X, 1 + position.Y + 3 * texture.Height)) &&
                    tileMap.Walkable(new Vector2(position.X, 1 + position.Y + 2 * texture.Height)) &&
                    tileMap.Walkable(new Vector2(position.X, 1 + position.Y + texture.Height)) &&
                    move.X < 0)
                {
                    wallslideL = true;
                    walljumpR  = false;
                    jump       = false;
                }

                if ((tileMap.Walkable(new Vector2(position.X + texture.Width, 1 + position.Y + 3 * texture.Height)) &&
                     tileMap.Walkable(new Vector2(position.X + texture.Width, 1 + position.Y + 2 * texture.Height)) &&
                     tileMap.Walkable(new Vector2(position.X + texture.Width, 1 + position.Y + texture.Height)) &&
                     move.X > 0))
                {
                    wallslideR = true;
                    walljumpL  = false;
                    jump       = false;
                }

                move.X = 0;
            }

            if (move.Y > 0)
            {
                jump = true;
            }

            position += move;
        }