コード例 #1
0
ファイル: AIStateBark.cs プロジェクト: Yuma-Shi/GLhf
 public override AIState execute(NPE a_agent)
 {
     if (a_agent is GuardDog)
     {
         GuardDog t_guardDog = (GuardDog)a_agent;
         Player t_player = Game.getInstance().getState().getPlayer();
         if (t_player.getCurrentState() == Player.State.Hiding)
         {
             if (!t_guardDog.isChargeing())
             {
                 t_guardDog.setChargeing(true);
             }
             if (t_guardDog.getPosition().getGlobalX() < t_player.getPosition().getGlobalX() - BARKDISTANCE)
             {
                 if (t_guardDog.getHorizontalSpeed() <= 0)
                 {
                     t_guardDog.goRight();
                 }
             }
             else if (t_guardDog.getPosition().getGlobalX() > t_player.getPosition().getGlobalX() + BARKDISTANCE)
             {
                 if (t_guardDog.getHorizontalSpeed() >= 0)
                 {
                     t_guardDog.goLeft();
                 }
             }
             else if (! t_guardDog.isBarking())
             {
                 t_guardDog.startBarking();
             }
             return this;
         }
         else
         {
             if (t_guardDog.canSensePlayer())
             {
                 t_guardDog.setChargePoint(Math.Sign(Game.getInstance().getState().getPlayer().getPosition().getGlobalX()
                     - t_guardDog.getPosition().getGlobalX()) * AIStateChargeing.CHARGEDISTANCE
                     + Game.getInstance().getState().getPlayer().getPosition().getGlobalX());
                 return AIStateChargeing.getInstance();
             }
             else
             {
                 t_guardDog.forgetChaseTarget();
                 return AIStatepatroling.getInstance();
             }
         }
     }
     else
     {
         throw new ArgumentException("Only dogs can bark");
     }
 }
コード例 #2
0
ファイル: AIStateChargeing.cs プロジェクト: theKyuu/GLhf
 public override AIState execute(NPE a_agent, GameTime a_gameTime)
 {
     if (a_agent is GuardDog)
     {
         GuardDog t_guardDog = (GuardDog)a_agent;
         if (t_guardDog.isFacingTowards(t_guardDog.getChargeingPoint()))
         {
             if (! t_guardDog.isChargeing())
             {
                 t_guardDog.setChargeing(true);
             }
             if (t_guardDog.ifFaceingRight())
             {
                 if (t_guardDog.getHorizontalSpeed() <= 0)
                 {
                     t_guardDog.goRight();
                 }
             }
             else
             {
                 if (t_guardDog.getHorizontalSpeed() >= 0)
                 {
                     t_guardDog.goLeft();
                 }
             }
             return this;
         }
         else
         {
             t_guardDog.setChargeing(false);
             return AIStatepatroling.getInstance();
         }
     }
     else
     {
         throw new ArgumentException("Only dogs can charge. noob.");
     }
 }
コード例 #3
0
ファイル: AIStatePatrolling.cs プロジェクト: theKyuu/GLhf
 public override AIState execute(NPE a_agent, GameTime a_gameTime)
 {
     if(a_agent==null)
     {
         throw new ArgumentException("The Agent cannot be null");
     }
     if(a_agent is Guard)
     {
         Guard t_guard = (Guard)a_agent;
         if (t_guard.canHearPlayer())
         {
             t_guard.setChaseTarget(Game.getInstance().getState().getPlayer());
             if (t_guard.isFacingRight())
             {
                 Game.getInstance().getState().addObject(new Particle(
                     t_guard.getPosition().getGlobalCartesian() + new Vector2(60,-20),
                     "Images//Sprite//Guard//qmark",
                     20f,
                     t_guard.getLayer()));
             }
             else
             {
                 Game.getInstance().getState().addObject(new Particle(
                     t_guard.getPosition().getGlobalCartesian() + new Vector2(-20, -10),
                     "Images//Sprite//Guard//qmark",
                     20f,
                     t_guard.getLayer()));
             }
             t_guard.getHuhSound().play();
             return new AIStateObserving(((float)a_gameTime.TotalGameTime.TotalMilliseconds) + 2000f, t_guard.isFacingRight());
         }
         else if (!t_guard.hasNoLampSwitchTargets())
         {
             return AIStateGoingToTheSwitch.getInstance();
         }
         else
         {
             if (t_guard.isCarryingFlash() != t_guard.isFlashLightAddicted() && t_guard.hasFlash())
             {
                 t_guard.toggleFlashLight();
             }
             else if (t_guard.isRunning())
             {
                 t_guard.setRunning(false);
             }
             else if (t_guard.hasPatrol())
             {
                 if (t_guard.getPosition().getGlobalCartesian().X < t_guard.getLeftPatrolPoint())
                 {
                     t_guard.goRight();
                 }
                 else if (t_guard.getPosition().getGlobalCartesian().X > t_guard.getRightPatrolPoint())
                 {
                     t_guard.goLeft();
                 }
                 else if (t_guard.getHorizontalSpeed() == 0)
                 {
                     if (t_guard.isFacingRight())
                     {
                         t_guard.goRight();
                     }
                     else
                     {
                         t_guard.goLeft();
                     }
                 }
             }
             else
             {
                 float t_guardPoint = t_guard.getLeftPatrolPoint();
                 if (t_guard.getPosition().getGlobalCartesian().X - 10 > t_guardPoint)
                 {
                     if (t_guard.getHorizontalSpeed() >= 0)
                     {
                         t_guard.goLeft();
                     }
                 }
                 else if (t_guard.getPosition().getGlobalCartesian().X + 10 < t_guardPoint)
                 {
                     if (t_guard.getHorizontalSpeed() <= 0)
                     {
                         t_guard.goRight();
                     }
                 }
                 else
                 {
                     if (t_guard.getHorizontalSpeed() == 0)
                     {
                         if (t_guard.guardFaceRight())
                         {
                             if (!t_guard.isFacingRight())
                             {
                                 t_guard.goRight();
                             }
                         }
                         else if(t_guard.isFacingRight())
                         {
                             t_guard.goLeft();
                         }
                     }
                     else
                     {
                         t_guard.stop();
                     }
                 }
             }
             return this;
         }
     }
     else if (a_agent is GuardDog)
     {
         GuardDog t_guardDog = (GuardDog)a_agent;
         if (t_guardDog.canSensePlayer())
         {
             if (t_guardDog.isBarkingPrefered())
             {
                 //om hunden föredrar att skälla så ser vi honom att jaga spelaren tills han är tillräkligt nära för att skälla.
                 t_guardDog.chasePlayer();
                 return AIStateChasing.getInstance();
             }
             else
             {
                 t_guardDog.setChargePoint(Math.Sign(Game.getInstance().getState().getPlayer().getPosition().getGlobalX() - t_guardDog.getPosition().getGlobalX()) * AIStateChargeing.CHARGEDISTANCE
                     + Game.getInstance().getState().getPlayer().getPosition().getGlobalX());
                 t_guardDog.setFacing(t_guardDog.getChargeingPoint() > t_guardDog.getPosition().getGlobalX());
                 return AIStateChargeing.getInstance();
             }
         }
         else
         {
             if (t_guardDog.haspatrol())
             {
                 if (t_guardDog.isChargeing())
                 {
                     t_guardDog.setChargeing(false);
                 }
                 if (t_guardDog.getPosition().getGlobalCartesian().X < t_guardDog.getLeftPatrolPoint())
                 {
                     if (t_guardDog.getHorizontalSpeed() <= 0)
                     {
                         t_guardDog.goRight();
                     }
                 }
                 else if (t_guardDog.getPosition().getGlobalCartesian().X > t_guardDog.getRightPatrolPoint())
                 {
                     if (t_guardDog.getHorizontalSpeed() >= 0)
                     {
                         t_guardDog.goLeft();
                     }
                 }
                 else if (t_guardDog.getHorizontalSpeed() == 0)
                 {
                     t_guardDog.goLeft();
                 }
             }
             else
             {
                 float t_guardPoint = t_guardDog.getLeftPatrolPoint();
                 if (t_guardDog.getPosition().getGlobalCartesian().X - 10 > t_guardPoint)
                 {
                     if (t_guardDog.getHorizontalSpeed() >= 0)
                     {
                         t_guardDog.goRight();
                     }
                 }
                 else if (t_guardDog.getPosition().getGlobalCartesian().X + 10 < t_guardPoint)
                 {
                     if (t_guardDog.getHorizontalSpeed() <= 0)
                     {
                         t_guardDog.goLeft();
                     }
                 }
                 else
                 {
                     if (t_guardDog.getHorizontalSpeed() != 0)
                     {
                         t_guardDog.stop();
                     }
                 }
             }
             return this;
         }
     }
     else if(a_agent is GuardCamera)
     {
         GuardCamera t_gc = (GuardCamera)a_agent;
         if (t_gc.canSeePlayer())
         {
             t_gc.chasePlayer();
             return AIStateChasing.getInstance();
         }
         else
         {
             if (t_gc.getRotation() < t_gc.getLeftRotationPoint() && t_gc.getRotation() > t_gc.getRightRotationPoint())
             {
                 if (t_gc.getRotationSpeed() == 0 && t_gc.isTurnReady())
                 {
                     t_gc.rotateCounter();
                 }
             }
             else
             {
                 float t_rotationGoal = ((t_gc.getLeftRotationPoint() + t_gc.getRightRotationPoint()) / 2f) % ((float)(Math.PI * 2));
                 bool t_goClock = (t_gc.getRotation() > t_rotationGoal + Math.PI) || ((t_gc.getRotation() > t_rotationGoal - Math.PI) && (t_gc.getRotation() < t_rotationGoal));
                 if (t_gc.getRotationSpeed() == 0 && t_gc.isTurnReady())
                 {
                     if (t_goClock)
                     {
                         t_gc.rotateClockW();
                     }
                     else
                     {
                         t_gc.rotateCounter();
                     }
                 }
                 else if ((t_goClock && t_gc.getRotationSpeed() < 0) || ((!t_goClock) && t_gc.getRotationSpeed() > 0))
                 {
                     t_gc.stop();
                 }
             }
             return this;
         }
     }
     else
     {
         throw new ArgumentException("Only guards, guardcameras and guarddogs can patrol");
     }
 }
コード例 #4
0
ファイル: AIState.cs プロジェクト: Yuma-Shi/GLhf
 public abstract AIState execute(NPE a_agent);
コード例 #5
0
ファイル: AIState.cs プロジェクト: theKyuu/GLhf
 public abstract AIState execute(NPE a_agent, GameTime a_gameTime);
コード例 #6
0
ファイル: AIStateObserving.cs プロジェクト: melburn/GLhf
 public override AIState execute(NPE a_agent, GameTime a_gameTime)
 {
     if (a_agent is Guard)
     {
         Guard t_guard = (Guard)a_agent;
         if (t_guard.getChaseTarget() is Player)
         {
             Player t_chaseTarget = (Player)t_guard.getChaseTarget();
             if (t_chaseTarget.getListLayer() == t_guard.getListLayer() && (t_chaseTarget.getCenterPoint() - t_guard.getCenterPoint()).Length() <= s_minimumRange)
             {
                 t_guard.chasePlayer();
                 return AIStateChasing.getInstance();
             }
             else if (timeOver(a_gameTime))
             {
                 if (t_guard.canHearPlayer() ||
                     (t_guard.getCenterPoint() - t_chaseTarget.getCenterPoint()).Length() < s_minimumRange)
                 {
                     t_guard.chasePlayer();
                     return AIStateChasing.getInstance();
                 }
                 else
                 {
                     t_guard.setChaseTarget(null);
                     if (m_prevFacingRight)
                     {
                         if (!t_guard.isFacingRight())
                         {
                             t_guard.goRight();
                         }
                     }
                     else if (t_guard.isFacingRight())
                     {
                         t_guard.goLeft();
                     }
                     return AIStateGoingToTheSwitch.getInstance();
                 }
             }
             else if (t_guard.getHorizontalSpeed() != 0)
             {
                 t_guard.stop();
             }
             else
             {
                 t_guard.faceTowards(t_chaseTarget.getCenterPoint().X);
             }
         }
         else if (timeOver(a_gameTime))
         {
             if (m_prevFacingRight)
             {
                 if (!t_guard.isFacingRight())
                 {
                     t_guard.goRight();
                 }
             }
             else if (t_guard.isFacingRight())
             {
                 t_guard.goLeft();
             }
             return AIStateGoingToTheSwitch.getInstance();
         }
         return this;
     }
     else
     {
         throw new ArgumentException("Only guards can observe");
     }
 }
コード例 #7
0
ファイル: AIStateChasing.cs プロジェクト: theKyuu/GLhf
        public override AIState execute(NPE a_agent, GameTime a_gameTime)
        {
            if (a_agent == null)
            {
                throw new ArgumentNullException("The Agent cannot be null");
            }
            if(a_agent is Guard)
            {
                Guard t_guard = (Guard)a_agent;
                Entity t_target = t_guard.getChaseTarget();
                if (t_target == null)
                {
                    return AIStatepatroling.getInstance();
                }
                if (! t_guard.isRunning())
                {
                    t_guard.setRunning(true);
                }
                if (Math.Abs(t_guard.getPosition().getGlobalX() - t_target.getPosition().getGlobalX()) < MINIMUMDISTANCE)
                {
                    if(t_guard.getHorizontalSpeed() != 0)
                    {
                        t_guard.stop();
                    }
                    if (t_guard.canStrike())
                    {
                        //return AIStateStriking.getInstance();
                        //sur på strikingstate

                        t_guard.strike();
                    }
                }
                else
                {
                    if (t_guard.getPosition().getGlobalX() < t_target.getPosition().getGlobalX())
                    {
                        if (t_guard.getHorizontalSpeed() <= 0)
                        {
                            t_guard.goRight();
                        }
                    }
                    else
                    {
                        if (t_guard.getHorizontalSpeed() >= 0)
                        {
                            t_guard.goLeft();
                        }
                    }
                }
                return this;
            }
            else if (a_agent is GuardDog)
            {
                GuardDog t_guardDog = (GuardDog)a_agent;
                if (t_guardDog.canSensePlayer() && ! t_guardDog.isBarkingPrefered())
                {
                    t_guardDog.forgetChaseTarget();
                    t_guardDog.setChargePoint(Math.Sign(Game.getInstance().getState().getPlayer().getPosition().getGlobalX() - t_guardDog.getPosition().getGlobalX()) * AIStateChargeing.CHARGEDISTANCE
                            + Game.getInstance().getState().getPlayer().getPosition().getGlobalX());
                    return AIStateChargeing.getInstance();
                }
                if ((Game.getInstance().getState().getPlayer().getPosition().getGlobalCartesian() - t_guardDog.getPosition().getGlobalCartesian()).Length() <= AIStateBark.BARKDISTANCE)
                {
                    return AIStateBark.getInstance();
                }
                else
                {
                    return this;
                }
            }
            else if (a_agent is GuardCamera)
            {
                GuardCamera t_gc = (GuardCamera)a_agent;
                if (t_gc.canSeePlayer())
                {
                    float t_pointDirection = t_gc.getPosition().getAngleTo(t_gc.getTarget().getPosition().getGlobalCartesian() + new Vector2(30,30));
                    t_gc.setRotation(t_pointDirection);
                    return this;
                }
                else
                {
                    return AIStatepatroling.getInstance();
                }
            }
            else
            {
                throw new ArgumentException("Only guards, cameras and dogs can chase");
            }
        }
コード例 #8
0
 public override AIState execute(NPE a_agent)
 {
     if(a_agent==null)
     {
         throw new ArgumentNullException("The Agent cannot be null");
     }
     if (a_agent is Guard)
     {
         Guard t_guard = (Guard)a_agent;
         if (t_guard.hasNoLampSwitchTargets())
         {
             return AIStatepatroling.getInstance();
         }
         else
         {
             if (!t_guard.isCarryingFlash() && t_guard.hasFlash())
             {
                 t_guard.toggleFlashLight();
             }
             else
             {
                 LampSwitch t_lampSwitch = t_guard.getFirstLampSwitchTarget();
                 while (Math.Abs(t_lampSwitch.getPosition().getGlobalX() - a_agent.getPosition().getGlobalX()) < 10)
                 {
                     if (!t_lampSwitch.isOn())
                     {
                         t_lampSwitch.toggleSwitch();
                     }
                     foreach (GameObject t_g in Game.getInstance().getState().getCurrentList())
                     {
                         if (t_g is Guard)
                         {
                             ((Guard)t_guard).removeLampSwitchTarget(t_lampSwitch);
                         }
                     }
                     if (t_guard.hasNoLampSwitchTargets())
                     {
                         return AIStatepatroling.getInstance();
                     }
                     t_lampSwitch = t_guard.getFirstLampSwitchTarget();
                 }
                 if (t_guard.isRunning())
                 {
                     t_guard.setRunning(false);
                 }
                 else if (t_guard.getPosition().getGlobalX() < t_lampSwitch.getPosition().getGlobalX())
                 {
                     if (t_guard.getHorizontalSpeed() <= 0)
                     {
                         t_guard.goRight();
                     }
                 }
                 else if (t_guard.getPosition().getGlobalX() > t_lampSwitch.getPosition().getGlobalX())
                 {
                     if (t_guard.getHorizontalSpeed() >= 0)
                     {
                         t_guard.goLeft();
                     }
                 }
             }
             return this;
         }
     }
     else
     {
         throw new ArgumentException("Only guards can go to the switch");
     }
 }