コード例 #1
0
ファイル: AI_Decluster.cs プロジェクト: jeromebyrne/Ninja
        //=========================================================================================
        /// <summary>
        /// Constructor. Creates the behaviour. A valid control character MUST be passed in.
        /// </summary>
        /// <param name="i"> 
        /// Importance of the behaviour to this character. Behaviour scores are scaled by this. 
        /// </param>
        /// <param name="c"> Character the behaviour is controlling. </param>
        /// <param name="b"> Behaviour set the AIBehaviour belongs to. </param>
        //=========================================================================================
        public AI_Decluster( float i , Character c , AIBehaviourSet b )
            : base(i , c , b)
        {
            // Get and save the character type:

            m_character_type = Type.GetType("NinjaGame.Character");
        }
コード例 #2
0
ファイル: AI_Rest.cs プロジェクト: jeromebyrne/Ninja
        //=========================================================================================
        /// <summary>
        /// Constructor. Creates the behaviour. A valid control character MUST be passed in.
        /// </summary>
        /// <param name="i"> 
        /// Importance of the behaviour to this character. Behaviour scores are scaled by this. 
        /// </param>
        /// <param name="c"> Character the behaviour is controlling. </param>
        /// <param name="b"> Behaviour set the AIBehaviour belongs to. </param>
        //=========================================================================================
        public AI_Rest( float i , Character c , AIBehaviourSet b )
            : base(i , c , b)
        {
            // Redo the time multiplier for increasing rest need:

            m_time_multiply = ( 1.0f - m_rest_randomness ) + (float) Core.Random.NextDouble() * m_rest_randomness;
        }
コード例 #3
0
        //=========================================================================================
        /// <summary>
        /// Constructor. Creates the behaviour. A valid control character MUST be passed in.
        /// </summary>
        /// <param name="i"> 
        /// Importance of the behaviour to this character. Behaviour scores are scaled by this. 
        /// </param>
        /// <param name="c"> Character the behaviour is controlling. </param>
        /// <param name="b"> Behaviour set the AIBehaviour belongs to. </param>
        //=========================================================================================
        public AI_Pursue_Jump_Gap( float i , Character c , AIBehaviourSet b )
            : base(i , c , b)
        {
            // Get the ninja type:

            m_ninja_type = Type.GetType("NinjaGame.Ninja");
        }
コード例 #4
0
        //=========================================================================================
        /// <summary>
        /// Constructor. Creates the behaviour. A valid control character MUST be passed in.
        /// </summary>
        /// <param name="i"> 
        /// Importance of the behaviour to this character. Behaviour scores are scaled by this. 
        /// </param>
        /// <param name="c"> Character the behaviour is controlling. </param>
        /// <param name="b"> Behaviour set the AIBehaviour belongs to. </param>
        //=========================================================================================
        public AI_Throw_Shuriken( float i , Character c , AIBehaviourSet b )
            : base(i , c , b)
        {
            // Get and save this character types:

            m_ninja_type = Type.GetType("NinjaGame.Ninja");

            // Complain if neither can be found:

            #if DEBUG

                if ( m_ninja_type == null ) throw new Exception("No ninja type exists");

            #endif
        }
コード例 #5
0
ファイル: AIBehaviourSet.cs プロジェクト: jeromebyrne/Ninja
        //=========================================================================================
        /// <summary>
        /// Creates the AI behaviour set. Must be given the character to which this behaviour 
        /// set belongs.
        /// </summary>
        /// <param name="control_character"> Character the AI behaviour is for. </param>
        //=========================================================================================
        public AIBehaviourSet( Character control_character )
        {
            // On windows debug if the control character is null then throw an exception:

            #if WINDOWS_DEBUG

                if ( control_character == null )
                {
                    throw new Exception("AIBehaviourSet must have a valid control character !!!");
                }

            #endif

            // Save the control character:

            m_character = control_character;
        }
コード例 #6
0
ファイル: AI_Patrol.cs プロジェクト: jeromebyrne/Ninja
        //=========================================================================================
        /// <summary>
        /// Constructor. Creates the behaviour. A valid control character MUST be passed in.
        /// </summary>
        /// <param name="i"> 
        /// Importance of the behaviour to this character. Behaviour scores are scaled by this. 
        /// </param>
        /// <param name="c"> Character the behaviour is controlling. </param>
        /// <param name="b"> Behaviour set the AIBehaviour belongs to. </param>
        //=========================================================================================
        public AI_Patrol( float i , Character c , AIBehaviourSet b )
            : base(i , c , b)
        {
            // Pick a random direction to patrol in:

            m_patrol_right = ( new Random().Next() & 1 ) == 1;

            // Give either left or right a big score to start off with:

            if ( m_patrol_right )
            {
                m_score_right = 1000;
            }
            else
            {
                m_score_left = 1000;
            }
        }
コード例 #7
0
ファイル: AIBehaviour.cs プロジェクト: jeromebyrne/Ninja
        //=========================================================================================
        /// <summary>
        /// Constructor. Creates the behaviour. A valid control character MUST be passed in.
        /// </summary>
        /// <param name="importance"> 
        /// Importance of the behaviour to this character. Behaviour scores are scaled by this. 
        /// </param>
        /// <param name="control_character"> Character the behaviour is controlling. </param>
        /// <param name="behaviour_set"> Behaviour set the AIBehaviour belongs to. </param>
        //=========================================================================================
        public AIBehaviour( float importance , Character control_character , AIBehaviourSet behaviour_set )
        {
            // On windows debug if the control character is null then throw an exception:

            #if WINDOWS_DEBUG

                if ( control_character == null )
                {
                    throw new Exception("AIBehaviour must have a valid control character !!!");
                }

            #endif

            // On windows debug if the behaviour set is null then throw an exception:

            #if WINDOWS_DEBUG

                if ( behaviour_set == null )
                {
                    throw new Exception("AIBehaviour must be part of a valid AIBeaviourSet!!!");
                }

            #endif

            // Save importance:

            m_importance = importance;

            // Save the control character:

            m_control_character = control_character;

            // Save behaviour set:

            m_behaviour_set = behaviour_set;

            // Save the name of the behaviour:

            m_name = GetType().Name;
        }
コード例 #8
0
ファイル: AI_Turn_Around.cs プロジェクト: jeromebyrne/Ninja
 //=========================================================================================
 /// <summary>
 /// Constructor. Creates the behaviour. A valid control character MUST be passed in.
 /// </summary>
 /// <param name="i"> 
 /// Importance of the behaviour to this character. Behaviour scores are scaled by this. 
 /// </param>
 /// <param name="c"> Character the behaviour is controlling. </param>
 /// <param name="b"> Behaviour set the AIBehaviour belongs to. </param>
 //=========================================================================================
 public AI_Turn_Around( float i , Character c , AIBehaviourSet b )
     : base(i , c , b)
 {
 }
コード例 #9
0
 //=========================================================================================
 /// <summary>
 /// Constructor. Creates the behaviour. A valid control character MUST be passed in.
 /// </summary>
 /// <param name="i"> 
 /// Importance of the behaviour to this character. Behaviour scores are scaled by this. 
 /// </param>
 /// <param name="c"> Character the behaviour is controlling. </param>
 /// <param name="b"> Behaviour set the AIBehaviour belongs to. </param>
 //=========================================================================================
 public AI_Pursue_Move_Around_Platform( float i , Character c , AIBehaviourSet b )
     : base(i , c , b)
 {
 }
コード例 #10
0
 //=========================================================================================
 /// <summary>
 /// Constructor. Creates the behaviour. A valid control character MUST be passed in.
 /// </summary>
 /// <param name="i"> 
 /// Importance of the behaviour to this character. Behaviour scores are scaled by this. 
 /// </param>
 /// <param name="c"> Character the behaviour is controlling. </param>
 /// <param name="b"> Behaviour set the AIBehaviour belongs to. </param>
 //=========================================================================================
 public AI_Pursue_Wall_Clear( float i , Character c , AIBehaviourSet b )
     : base(i , c , b)
 {
 }
コード例 #11
0
ファイル: AI_Sight.cs プロジェクト: jeromebyrne/Ninja
        //=========================================================================================
        /// <summary>
        /// Constructor. Creates the behaviour. A valid control character MUST be passed in.
        /// </summary>
        /// <param name="i"> 
        /// Importance of the behaviour to this character. Behaviour scores are scaled by this. 
        /// </param>
        /// <param name="c"> Character the behaviour is controlling. </param>
        /// <param name="b"> Behaviour set the AIBehaviour belongs to. </param>
        //=========================================================================================
        public AI_Sight( float i , Character c , AIBehaviourSet b )
            : base(i , c , b)
        {
            // Save this for later use

            m_ninja_type = Type.GetType("NinjaGame.Ninja");
        }
コード例 #12
0
ファイル: AI_Sight.cs プロジェクト: jeromebyrne/Ninja
        //=========================================================================================
        /// <summary>
        /// Scores the current behaviour and returns how relevant the AI thinks this action is
        /// </summary>
        /// <returns> A score for this current behaviour. </returns>
        //=========================================================================================
        public override float ScoreBehaviour()
        {
            // Clear the last raycast results:

            m_last_raycast_results.Clear();

            // Search for the player:

            m_player = (PlayerNinja) Core.Level.Search.FindByType("PlayerNinja");

            // If there is no player then return 0:

            if ( m_player == null )
            {
                // Reset all these variables

                m_in_sight              = false;
                m_sighted_last_frame    = false;
                m_out_of_sight_time     = 1;
                m_in_sight_time         = 0;

                // This action is not relevant

                return 0;
            }

            // Update the player's breadcrumbs:

            UpdatePlayerBreadcrumbs();

            // Update which breadcrumb we should be following:

            UpdatePlayerBreadcrumb();

            // Shorten things:

            LevelCollisionQuery c = Core.Level.Collision;

            // See if the player is inside the AI's vision cone:

            bool in_vision_cone = false;

            // If we have marked the player as being recently in sight then skip the vision cone check:

            if ( m_in_sight )
            {
                in_vision_cone = true;
            }
            else
            {
                in_vision_cone = IsPlayerInVisionCone();
            }

            // Otherwise raycast to the player: don't bother if the player is not inside the AIs vision cone:

            if ( in_vision_cone )
            {
                // Do the raycast:

                c.Intersect( ControlCharacter.Position , m_player.Position , null );

                // Save all the results for later use:

                for ( int i = 0 ; i < Core.Level.Collision.IntersectResultCount ; i++ )
                {
                    m_last_raycast_results.AddLast( Core.Level.Collision.IntersectResults[i] );
                }
            }

            // Save the previous visibility of the player here:

            bool prev_in_sight = m_in_sight;

            // See if the player is visible:

            if ( in_vision_cone == false || c.IntersectResultCount > 0 )
            {
                // Player is not in sight for this frame:

                m_sighted_last_frame = false;

                // Not visible: see if the ai has marked the player as visible ...

                if ( m_in_sight )
                {
                    // Increase the amount of time the player has been out of sight for:

                    m_out_of_sight_time += Core.Timing.ElapsedTime;

                    // If the out of sight time is past the maximum out of sight time then mark player as out of sight

                    if ( m_out_of_sight_time >= OUT_OF_SIGHT_TIME )
                    {
                        // Set the in sight time to zero: but only if the ninja falls outside of the vision cone: this is to combat a situation where the ai is rapidly turning around

                        if ( in_vision_cone == true ) m_in_sight_time = 0;

                        // No longer in sight:

                        m_in_sight = false;
                    }
                }
                else
                {
                    // Increase the out of sight time:

                    m_out_of_sight_time += Core.Timing.ElapsedTime;

                    // Set the in sight time to zero: but only if the ninja falls outside of the vision cone: this is to combat a situation where the ai is rapidly turning around

                    if ( in_vision_cone == true ) m_in_sight_time = 0;
                }
            }
            else
            {
                // Player is in sight for this frame:

                m_sighted_last_frame = true;

                // Visible: see if the ai has marked the player as visible

                if ( m_in_sight )
                {
                    // In sight: increase in sight time

                    m_in_sight_time += Core.Timing.ElapsedTime;

                    // Set the out of sight time to zero:

                    m_out_of_sight_time = 0;
                }
                else
                {
                    // Not marked in sight. Increase the time we are in sight for

                    m_in_sight_time += Core.Timing.ElapsedTime;

                    // If enough time has passed then mark the player as visible again:

                    if ( m_in_sight_time >= SIGHT_REGISTER_TIME )
                    {
                        // Set the out of sight time to zero:

                        m_out_of_sight_time = 0;

                        // Mark the player as being in sight:

                        m_in_sight = true;
                    }
                }
            }

            // See if there was a change in visibility:

            if ( m_in_sight != prev_in_sight )
            {
                // Change in visibility: set our score back to one

                m_current_score = 1;
            }
            else
            {
                // No change in visibility: decrease the importance of this module

                m_current_score *= 0.95f;
            }

            // Return our score:

            return m_current_score * Importance;
        }
コード例 #13
0
ファイル: ForceBox.cs プロジェクト: jeromebyrne/Ninja
        /// <summary>
        /// applies the force of the force box(m_power * m_direction) on a character object type
        /// </summary>
        public void ApplyForce_Character(Character character)
        {
            Vector2 force = new Vector2(m_power * m_direction.X , m_power * m_direction.Y);

            character.MoveVelocity += force;
        }