public void update(Enemy parent, GameTime currentTime)
        {
            hittingWall = false;

            if (walkSwitchTimer == 0)
            {
                walkSwitchTimer = currentTime.TotalGameTime.TotalMilliseconds;
            }

            foreach (Entity en in Entity.globalEntityList)
            {
                if(isClimbing == true)
                {
                    parent.acceleration.Y = 0.00f;
                }

                if (en is climbWall)
                {
                    if (parent.hitTest(en))
                    {
                        hittingWall = true;
                    }
                }
            }

            if (hittingWall && chasePlayer)
            {
                if (temp > 0)
                {
                    parent.currentAnimation = "angrySawWalkLeft";
                }
                else
                {
                    parent.currentAnimation = "angrySawWalkRight";
                }
                isClimbing = true;
                parent.velocity.X = 0.00f;
                parent.velocity.Y = -0.15f;
                parent.acceleration.Y = 0.0f;
                parent.acceleration.X = 0.0f;
            }
            else
            {
                isClimbing = false;

                foreach (Entity en in Entity.globalEntityList)
                {
                    if (en is Player)
                    {
                        if (parent.PushTime < 1 && en.horizontal_pos - parent.horizontal_pos > -200 && en.horizontal_pos - parent.horizontal_pos < 200 && en.vertical_pos - parent.vertical_pos > -160 && en.vertical_pos - parent.vertical_pos < 160)
                        {
                            chasePlayer = true;
                        }
                        else
                        {
                            chasePlayer = false;
                        }

                        if (chasePlayer == true)
                        {
                            if (en.horizontal_pos - parent.horizontal_pos > -1000 && en.horizontal_pos - parent.horizontal_pos < -30 )
                            {

                                if (walkingLeft == false)
                                {
                                    walkingLeft = true;
                                }

                                parent.velocity.X = -2.5f * walkerSpeed;
                                temp = parent.velocity.X;
                            }
                            else if (en.horizontal_pos - parent.horizontal_pos > -16 && en.horizontal_pos - parent.horizontal_pos < 16)
                            {
                                parent.velocity.X = 0.0f;
                            }
                            else if (en.horizontal_pos - parent.horizontal_pos > 30 && en.horizontal_pos - parent.horizontal_pos < 1000)
                           {
                                if (walkingLeft == true)
                                {
                                    walkingLeft = false;
                                }
                                parent.velocity.X = 2.5f * walkerSpeed;
                                temp = parent.velocity.X;
                            }
                        }
                    }
                }

               if( chasePlayer == false)
               {
                    walkState.update(parent, currentTime);
               }
            }
        }
示例#2
0
        public void update(Enemy parent, GameTime currentTime)
        {
            if (!isEnabled)
            {
                return;
            }

            if (walkSwitchTimer == 0)
            {
                walkSwitchTimer = currentTime.TotalGameTime.TotalMilliseconds;
            }

            if (parent.onTheGround)
            {
                if (Math.Abs(parent.velocity.X) < 0.01f)
                {
                    walkingLeft = !walkingLeft;
                }

                if (walkingLeft && parent.velocity.X > -walkerSpeed)
                {
                    parent.acceleration.X = -0.001f;
                }
                else if (parent.velocity.X < walkerSpeed)
                {
                    parent.acceleration.X = 0.001f;
                }
                else if (parent.velocity.X < -walkerSpeed)
                {
                    //parent.velocity.X = -walkerSpeed;
                }
                else if (parent.velocity.X > walkerSpeed)
                {
                    //parent.velocity.X = walkerSpeed;
                }
            }

            bool touchingWalkMarker = false;
            foreach (Entity en in Entity.globalEntityList)
            {
                if (en is WalkMarker)
                {
                    if (parent.hitTest(en))
                    {
                        Entity player = null;
                        foreach (Entity p in Entity.globalEntityList)
                        {
                            if (p is Player)
                            {
                                player = p;
                            }
                        }

                        touchingWalkMarker = true;

                        if (!onWalkMarker && parent.PushTime <= 0)
                        {
                            onWalkMarker = true;

                            parent.velocity.X *= -1;
                        }
                    }
                }
            }

            if (!touchingWalkMarker && onWalkMarker)
            {
                onWalkMarker = false;
            }
        }