public override void UpdateThis()
        {
            if (CirCollisionD() != "down")
            {
                E.IncGrav();
                Position    += E.GetGrav();
                base.s       = State.Jump;
                base.texture = G.MegaDictionary[c][s].Tex;
                isFalling    = true;
            }

            else
            {
                E.SetGrav(Vector2.Zero);
                IsJumping      = false;
                isFalling      = false;
                E.JumpConstant = 50f;
            }



            if (base.s != State.Damaged)
            {
                if (keys.IsAttackPressed())
                {
                    base.s       = State.Attack;
                    base.texture = G.MegaDictionary[c][s].Tex;
                }


                if (IsJumping == true)
                {
                    base.s       = State.Jump;
                    base.texture = G.MegaDictionary[c][s].Tex;
                }

                if (CirCollisionU() != "up")
                {
                    if (keys.IsUpPressed() && IsJumping == false)
                    {
                        IsJumping = true;
                    }

                    if (IsJumping == true)
                    {
                        Position = E.Jump(Position);
                    }
                }



                //The following if Statments check wether there was collision from each side
                //Respectively, and if so does not enter the movment is statment.
                //If there is no collision, Cheks if the Movment Key has been pressed,
                //And if so moves the player.
                if (CirCollisionL() != "left")
                {
                    if (keys.IsLeftPressed())
                    {
                        Position += new Vector2(-11, 0);
                        if (IsJumping == false && isFalling == false)
                        {
                            base.s       = State.Walk;
                            this.texture = G.MegaDictionary[c][s].Tex;
                        }
                        Effects = SpriteEffects.FlipHorizontally;
                    }
                }

                if (CirCollisionR() != "right")
                {
                    if (keys.IsRightPressed())
                    {
                        Position += new Vector2(11, 0);
                        if (IsJumping == false && isFalling == false)
                        {
                            base.s       = State.Walk;
                            base.texture = G.MegaDictionary[c][s].Tex;
                        }
                        Effects = SpriteEffects.None;
                    }
                }
            }

            CirCollisionLW();

            base.UpdateThis();
        }
Пример #2
0
        public override void UpdateThis()
        {
            PLeftOrRight = "null";



            if (base.s != State.Damaged)
            {
                // If the bot is moving left
                if (Keys.IsLeftPressed())
                {
                    Keys.SetAttack(false);
                    base.s       = State.Walk;
                    base.texture = G.MegaDictionary[c][s].Tex;

                    if (base.MovingSpeed == 0)
                    {
                        base.s       = State.Stand;
                        base.texture = G.MegaDictionary[c][s].Tex;
                    }

                    //Cheks the distance to the wall.
                    Ray2Wall = G.map.Ray_to_wall(Position, lookLeft);


                    //if its too close, turns around.
                    if (G.map.IsWallClose(Position, Ray2Wall))
                    {
                        Keys.SetLeft(false);
                        Keys.SetRight(true);

                        Effects = SpriteEffects.None;
                    }

                    else
                    {
                        Position += new Vector2(-10 * base.MovingSpeed, 0);
                    }
                }

                //If the bot is moving right
                if (Keys.IsRightPressed())
                {
                    Keys.SetAttack(false);
                    base.s       = State.Walk;
                    base.texture = G.MegaDictionary[c][s].Tex;
                    if (base.MovingSpeed == 0)
                    {
                        base.s       = State.Stand;
                        base.texture = G.MegaDictionary[c][s].Tex;
                    }

                    //Cheks the distance to the wall.
                    Ray2Wall = G.map.Ray_to_wall(Position, lookRight);

                    //if its too close, turns around.
                    if (G.map.IsWallClose(Position, Ray2Wall))
                    {
                        Keys.SetLeft(true);
                        Keys.SetRight(false);

                        Effects = SpriteEffects.FlipHorizontally;
                    }

                    else
                    {
                        Position += new Vector2(10 * base.MovingSpeed, 0);
                    }
                }



                //Checks if the player is Close and if so from whitch direction.
                //will later be used to detirmne if the Enemy needs to attack.
                if ((G.map.IsPlayerClose(Position, Player.Position, out PLeftOrRight) &&
                     Keys.IsRightPressed() && PLeftOrRight == "right") ||

                    (G.map.IsPlayerClose(Position, Player.Position, out PLeftOrRight) &&
                     Keys.IsLeftPressed() && PLeftOrRight == "left"))
                {
                    Keys.SetAttack(true);
                    Keys.SetLeft(false);
                    Keys.SetRight(false);
                }

                else
                {
                    if (Effects == SpriteEffects.None)
                    {
                        Keys.SetRight(true);
                    }

                    if (Effects == SpriteEffects.FlipHorizontally)
                    {
                        Keys.SetLeft(true);
                    }
                }


                if (Keys.IsAttackPressed())
                {
                    base.s       = State.Attack;
                    base.texture = G.MegaDictionary[c][s].Tex;
                }
            }



            base.UpdateThis();
        }