Exemple #1
0
 // get all map info to spawn monster and human
 public void SpawnCreatures()
 {
     for (int i = 0; i < GameSettings.GetInstance().MAP_TILE_ROW_COUNT; ++i)
     {
         for (int j = 0; j < GameSettings.GetInstance().MAP_TILE_COLUMN_COUNT; ++j)
         {
             if (collision_map_[i, j] == NodeType.mountain)
             {
                 if (GameSettings.GetInstance().MONSTER_SPAWN_CHANCE >= Random.Range(0, 100))
                 {
                     GameActor monster = GameActor.Create("Entity_Monster");
                     scene_game_.AddEntity(monster);
                     NavigationMap.GetInstance().RegisterActor(monster);
                     monster.transform.localPosition = new Vector3(GameSettings.GetInstance().TILE_SIZE *j, GameSettings.GetInstance().TILE_SIZE *i);
                     monster.transform.localScale    = new Vector3(1, 1, 1);
                 }
             }
             else if (collision_map_[i, j] == NodeType.grass)
             {
                 if (GameSettings.GetInstance().HUMAN_SPAWN_CHANCE >= Random.Range(0, 100))
                 {
                     GameActor human = GameActor.Create(GameSettings.GetInstance().HUMAN_PREFAB_NAME);
                     scene_game_.AddEntity(human);
                     NavigationMap.GetInstance().RegisterActor(human);
                     human.transform.localPosition = new Vector3(GameSettings.GetInstance().TILE_SIZE *j, GameSettings.GetInstance().TILE_SIZE *i);
                     human.transform.localScale    = new Vector3(1, 1, 1);
                 }
             }
         }
     }
 }
Exemple #2
0
 // Use this for initialization
 void Start()
 {
     game_manager  = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>();
     event_manager = game_manager.GetEventManager();
     map           = GameObject.FindGameObjectWithTag("Map");
     nav_map       = map.gameObject.GetComponent <NavigationMap>();
 }
Exemple #3
0
        public void AddRoutesbyConvention(IMXConventionBasedController controller)
        {
            var controllerConvention = controller.Convention;

            // add default controller route
            if (controllerConvention.DefaultActionName != null)
            {
                var routeDescription = PatternGenerator.Generate(controllerConvention);
                NavigationMap.Add(routeDescription.Pattern, controller, routeDescription.DefaultParameters);
            }

            // add controller routes for each action
            foreach (var actionConvention in controllerConvention.ActionConventions)
            {
                // within each action, there can be multiple routes - e.g. when default parameter values are available.
                // we have to be very careful with default parameter values because:
                // - some people have experienced crashes in some MonoDroid builds near to default parameters
                // - Windows Phone 7 reflection does not supply access to default values (it supplies null instead)
                foreach (
                    var routeDescription in
                    new MXRouteDescriptionSet(PatternGenerator, controllerConvention, actionConvention))
                {
                    NavigationMap.Add(routeDescription.Pattern, controller, routeDescription.DefaultParameters);
                }
            }
        }
Exemple #4
0
    // Use this for initialization
    void Start()
    {
        game_manager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>();
        RT_manager   = game_manager.GetGameSparksRTManager();
        net_manager  = game_manager.GetNetworkManager();
        nav_map      = GameObject.FindGameObjectWithTag("Map").GetComponent <NavigationMap>();

        StartCoroutine(SendTimeStamp());

        // Inform the server that the match is ready
        using (RTData data = RTData.Get())
        {
            data.SetLong(1, 0);
            RT_manager.SendData(103, GameSparks.RT.GameSparksRT.DeliveryIntent.UNRELIABLE_SEQUENCED, data, new int[] { 0 }); // send to peerId -> 0, which is the server
        }

        StartCoroutine(DelayTurnStart());

        turn_info.turn = turn_type.stop;
        curr_action    = action.wait;

        attack_button.gameObject.SetActive(false);
        finish_player_turn.gameObject.SetActive(false);
        state_text.gameObject.SetActive(false);

        card1.gameObject.SetActive(false);
        card2.gameObject.SetActive(false);
        card3.gameObject.SetActive(false);
    }
Exemple #5
0
 void StartTurn()
 {
     playersTurn             = true;
     remainingMovementPoints = movementPointsPerTurn;
     UIController.Instance.SetRemainingMovmentPointsTextValue(remainingMovementPoints);
     pathMap = NavigationScript.CreatePathsTreeFromStart(startingTile);
 }
Exemple #6
0
    IEnumerator PlayerMovement(WalkingArea selectedTile)
    {
        StartAnimatingWalk();
        moving = true;
        var path = NavigationScript.CreatePathToTarget(pathMap.paths, selectedTile);

        while (path.Count > 0 && !died)
        {
            var nextStep = path.Last();
            path.Remove(nextStep);
            while ((transform.position - nextStep.CharacterSocket.position).sqrMagnitude > 0.003f)
            {
                if (!footAudioSource.isPlaying)
                {
                    footAudioSource.PlayOneShot(footstepsClips[Random.Range(0, footstepsClips.Length)]);
                }
                PlayerPosition     = transform.position;
                transform.position = Vector2.MoveTowards(transform.position, nextStep.CharacterSocket.position, speed * Time.deltaTime);
                yield return(null);
            }
        }

        startingTile = selectedTile;
        StopWalkingAnimation();

        pathMap = NavigationScript.CreatePathsTreeFromStart(startingTile);
        moving  = false;
    }
Exemple #7
0
    private void GenerateBaseTile(int col, int row, NodeType nt)
    {
        string texture_path;

        if (nt == NodeType.blocked)
        {
            texture_path = "Texture/water";
        }
        else if (nt == NodeType.food)
        {
            texture_path = "Texture/tree_a";
        }
        else if (nt == NodeType.grass)
        {
            texture_path = "Texture/grass";
        }
        else if (nt == NodeType.normal)
        {
            texture_path = "Texture/sand";
        }
        else
        {
            texture_path = "Texture/hills_a";
        }

        GameObject prefab   = Resources.Load("Prefabs/BaseTile", typeof(GameObject)) as GameObject;
        Base_Tile  basetile = ((GameObject)GameObject.Instantiate(prefab)).gameObject.GetComponent <Base_Tile>();

        basetile.init(texture_path);
        basetile.transform.parent        = SceneManager.GetInstance().entities_parent.transform;
        basetile.transform.localPosition = new Vector3(col * tile_height, row * tile_width, 2);
        basetile.transform.localScale    = new Vector3(64, 1, 64);

        NavigationMap.GetInstance().SetCollisionMapType(row, col, nt);
    }
Exemple #8
0
    /// <summary>
    /// Inicializa A*
    /// </summary>
    protected void InitSearchAStart()
    {
        NavigationMap navigationMap = GameMgr.GetInstance().GetCustomMgrs().GetServer <NavigationMap>();
        WayPoint      wpInit        = navigationMap.FindWayPointNear(this.transform.position);
        WayPoint      wpEnd         = navigationMap.FindWayPointNear(m_target.transform.position);

        // TODO: En vez de devolver solo el último punto llamar al PathfindingJob
        if (m_pathfinding)
        {
            NativeArray <Vector3> wayPoints   = new NativeArray <Vector3>(10, Allocator.TempJob);
            NativeArray <int>     numelements = new NativeArray <int>(1, Allocator.TempJob);
            PathfindingJob        pathJob     = new PathfindingJob(navigationMap.getMap(), wpInit.ID, wpEnd.ID, ref wayPoints, ref numelements);
            JobHandle             handle      = pathJob.Schedule();
            handle.Complete();
            m_waypointList.Clear();
            for (int i = numelements[0]; i > 0; --i)
            {
                m_waypointList.Add(wayPoints[i - 1]);
            }
            wayPoints.Dispose();
            numelements.Dispose();
            pathJob.Delete();
            NextWaypoint();
        }
        else
        {
            m_waypointList.Clear();
            m_waypointList.Add(wpInit.transform.position);
            m_waypointList.Add(wpEnd.transform.position);
        }
    }
Exemple #9
0
 public void AddEmptyRoute(IMXController defaultController, string actionName)
 {
     NavigationMap.Add(string.Empty, defaultController,
                       new Dictionary <string, string>()
     {
         { MXConventionConstants.ActionParameterKeyName, actionName }
     });
 }
Exemple #10
0
        public override void OnAppLoad()
        {
            // add controllers to navigation map
            NavigationMap.Add("Home", new Controllers.HomeController());
            NavigationMap.Add("About", new Controllers.AboutController());

            NavigateOnLoad = "Home";
        }
 public static NavigationMap GetInstance()
 {
     if ( !s_instance ) {
         s_instance = (NavigationMap)GameObject.FindObjectOfType ( typeof ( NavigationMap ) );
         if ( !s_instance )
             Debug.LogError("There needs to be one active GameMap script on a GameObject in your scene.");
     }
     return s_instance;
 }
        public void Reset(TimeSpan totalGameTime, HelicopterScenario scenario, NavigationMap heightmap)
        {
            Console.WriteLine(@"Resetting helicopter.");

            _scenario = scenario;


            // TODO We would rather want to do Autopilot.Reset() than this fugly code
            Autopilot.IsAtDestination = false;
            Autopilot      = Autopilot.Clone();
            Autopilot.Task = scenario.Task.Clone();
            Autopilot.Map  = heightmap;


            Vector3    startPosition     = scenario.StartPosition;
            Vector3    startVelocity     = Vector3.Zero;
            Vector3    startAcceleration = Vector3.Zero;
            Quaternion startOrientation  = Quaternion.Identity;

            if (Task.HoldHeightAboveGround > 0)
            {
                startPosition.Y = Autopilot.Map.GetAltitude(VectorHelper.ToHorizontal(startPosition)) + Task.HoldHeightAboveGround;
            }

            var startPhysicalState = new PhysicalHeliState(
                startOrientation, startPosition, startVelocity, startAcceleration);
            var initialState = new SimulationStepResults(startPhysicalState, totalGameTime);

            _physicalState = startPhysicalState;

            // Re-create the state provider when resetting because some sensors will have to re-initialize.
            _physics = new HeliPhysics(_collision, UseTerrainCollision);
            _sensors = new SensorModel(_sensorSpecifications, Autopilot.Map, startPosition, startOrientation);
            _perfectStateProvider   = new PerfectState();
            _estimatedStateProvider = new SensorEstimatedState(_sensors, startPhysicalState);

            // Wait for state to become stable.
//            while (!_perfectStateProvider.Ready)
//            {
            // TODO GPS will require N seconds of startup time
//                _perfectStateProvider.Update(initialState, 0, 0, new JoystickOutput());
//                Sensors.Update(initialState, new JoystickOutput());
            //                Thread.Sleep(100);
//            }

            // When resetting, use perfect state as starting point.
            // TODO It should not be necessary to create this waypoint since it should never be used for navigation! Delete if safe.
            // Use start position and start orientation instead.
            const float defaultWaypointRadius = 5;
            var         startWaypoint         = new Waypoint(startPosition, 0, WaypointType.Intermediate, defaultWaypointRadius);

            _trueState      = StateHelper.ToHeliState(startPhysicalState, GetHeightAboveGround(startPhysicalState.Position), startWaypoint, new JoystickOutput());
            _estimatedState = _trueState;

            Log.Clear();
        }
Exemple #13
0
        private void EditCommand_Execute()
        {
            Uri destination           = NavigationMap.ResolveDestination(NavigationDestination.ClientAddEdit, SelectedClient.Id.ToString());
            NavigationMessage message = new NavigationMessage()
            {
                NavigateTo = destination
            };

            Messenger.Default.Send(message);
        }
Exemple #14
0
        public override void OnAppLoad()
        {
            Title = "Hello World!";

            // add controllers to navigation map
            NavigationMap.Add("", new Controllers.MessageController());

            // set navigate on load endpoint
            NavigateOnLoad = "";
        }
Exemple #15
0
        private void AddCommand_Execute()
        {
            Uri destination           = NavigationMap.ResolveDestination(NavigationDestination.ClientAddEdit);
            NavigationMessage message = new NavigationMessage()
            {
                NavigateTo = destination
            };

            Messenger.Default.Send(message);
        }
Exemple #16
0
    public virtual IEnumerator ExecuteTurn()
    {
        bool endTurn = false;

        if (nextWaypoint == null)
        {
            nextWaypoint = waypoints.First();
        }
        StartAnimatingWalk();
        StartTurn();
        var path = NavigationScript.CreatePathToTarget(map.paths, nextWaypoint);

        while (!endTurn)
        {
            int movementPoints = remainingMovementPoints;
            yield return(StartCoroutine(CheckForAttack()));

            if (!(movementPoints == remainingMovementPoints))
            {
                StartAnimatingWalk();
            }
            var nextStep = path.Last();
            if (nextStep.IsSocketOccupied)
            {
                endTurn = true;
            }
            else
            {
                path.Remove(nextStep);
                SpendMovementPoints(map.costs[nextStep]);
                transform.localScale = new Vector3(Mathf.Sign(nextStep.CharacterSocket.position.x - transform.position.x), 1, 1);
                while ((transform.position - nextStep.CharacterSocket.position).sqrMagnitude > 0.003f)
                {
                    transform.position = Vector2.MoveTowards(transform.position, nextStep.CharacterSocket.position, speed * Time.deltaTime);
                    yield return(null);
                }
                startingTile = nextStep;
            }

            if (nextWaypoint == startingTile)
            {
                nextWaypoint = nextWaypoint == waypoints.Last() ? waypoints[0] : waypoints[waypoints.IndexOf(nextWaypoint) + 1];
                map          = NavigationScript.CreatePathsTreeFromStart(startingTile);
                path         = NavigationScript.CreatePathToTarget(map.paths, nextWaypoint);
            }
            nextStep = path.Last();

            endTurn = endTurn?true:(remainingMovementPoints - nextStep.cost) < 0;
            if (endTurn)
            {
                StopWalkingAnimation();
            }
            yield return(null);
        }
    }
Exemple #17
0
        public override void OnAppLoad()
        {
            // Set the application title.
            Title = "Set Text"; // TODO: put in config file.

            // Add navigation mappings.
            NavigationMap.Add("", new SetTextController());

            // Set default navigation URI.
            NavigateOnLoad = "";
        }
Exemple #18
0
 public static NavigationMap GetInstance()
 {
     if (!s_instance)
     {
         s_instance = (NavigationMap)GameObject.FindObjectOfType(typeof(NavigationMap));
         if (!s_instance)
         {
             Debug.LogError("There needs to be one active GameMap script on a GameObject in your scene.");
         }
     }
     return(s_instance);
 }
Exemple #19
0
    protected override void _Disposer()
    {
        base._Disposer();

        // give your food back to the map
        if (is_spawner_)
        {
            int cur_map_x = (int)this.map_pos.x;
            int cur_map_y = (int)this.map_pos.y;
            NavigationMap.GetInstance().SetNodeType(NodeType.food, cur_map_y, cur_map_x);
        }
    }
Exemple #20
0
        public override void OnAppLoad()
        {
            // Set the application title.
            Title = ResourceHelper.Titles.SetText;

            // Add navigation mappings.
            NavigationMap.Add("", new SetTextController());
            NavigationMap.Add("{Action}", new SetTextController());

            // Set default navigation URI.
            NavigateOnLoad = "";
        }
        public override void OnAppLoad()
        {
            // Set the application title
            Title = "Best Sellers";

            // Add navigation mappings
            NavigationMap.Add("", new CategoryListController());
            NavigationMap.Add("{Category}", new BookListController());
            NavigationMap.Add("{Category}/{Book}", new BookController());

            // Set default navigation URI
            NavigateOnLoad = "";
        }
Exemple #22
0
    public void ReduceHealth(int amount)
    {
        if (health_ <= 0)
        {
            return;
        }

        health_ -= amount;
        if (health_ <= 0)
        {
            remove_count_down_ = 1;
            NavigationMap.GetInstance().UnRegisterActor(this);
        }
    }
Exemple #23
0
        public override void OnAppLoad()
        {
            // Set the application title
            Title = "Customer Management";

            // Add navigation mappings
            NavigationMap.Add("Customers", new CustomerListController());

            CustomerController customerController = new CustomerController();

            NavigationMap.Add("Customers/{CustomerId}", customerController);
            NavigationMap.Add("Customers/{CustomerId}/{Action}", customerController);

            // Set default navigation URI
            NavigateOnLoad = "Customers";
        }
Exemple #24
0
    public static NavigationMap CreatePathsTreeFromStart(WalkingArea start)
    {
        var tilesChecked  = new HashSet <WalkingArea>();
        var toBeChecked   = new List <WalkingArea>();
        var previousPoint = new Dictionary <WalkingArea, WalkingArea>();
        var travelCost    = new Dictionary <WalkingArea, int>();

        travelCost.Add(start, 0);
        toBeChecked.Add(start);

        while (toBeChecked.Count > 0)
        {
            toBeChecked.Sort((x, y) => travelCost[y] - travelCost[x]);
            WalkingArea current = toBeChecked.Last();
            toBeChecked.Remove(current);
            tilesChecked.Add(current);
            foreach (var next in current.neighbours)
            {
                //Debug.Log ("checking tile " + next.transform.name);
                if (!tilesChecked.Contains(next))
                {
                    var nextCost = travelCost[current] + next.cost;
                    if (travelCost.ContainsKey(next))
                    {
                        //Debug.Log ("path to tile " + next.transform.name+ "already exists");
                        if (nextCost < travelCost[next])
                        {
                            //Debug.Log ("path to tile " + next.transform.name+ "has lower cost");
                            travelCost[next] = nextCost;
                            previousPoint.Add(next, current);
                        }
                    }
                    else
                    {
                        //Debug.Log ("path to tile " + next.transform.name+ "didn't exist, adding");
                        travelCost.Add(next, nextCost);
                        previousPoint.Add(next, current);
                    }
                    toBeChecked.Add(next);
                }
            }
        }
        var map = new NavigationMap(previousPoint, travelCost);

        return(map);
    }
Exemple #25
0
        public SensorModel(SensorSpecifications sensorSpecifications, NavigationMap map, Vector3 startPosition, Quaternion startOrientation)
        {
            _sensorSpecifications = sensorSpecifications;

            Console.WriteLine("Using sensors:\n" + sensorSpecifications);


            // Instantiate sensors and populate properties and sensor list
            const bool isPerfect = false;

            _sensors = new List <ISensor>
            {
                (GPS = new GPS(sensorSpecifications, isPerfect, true)),
                (IMU = new IMU(sensorSpecifications, startOrientation, isPerfect)),
                (Magnetometer = new Magnetometer3Axis(sensorSpecifications, isPerfect)),
                (GroundRangeFinder = new SonicRangeFinder(sensorSpecifications, isPerfect, map)),
                (PressureGauge = new StaticPressureGauge(sensorSpecifications, isPerfect)),
            };
        }
Exemple #26
0
        public override void OnAppLoad()
        {
            // Set the application title
            Title = "Example App";

            // Add navigation mappings
            var welcome = new WelcomeScreenController();

            NavigationMap.Add("WelcomeScreen", welcome);
            NavigationMap.Add("WelcomeScreen/Data/{DataID}", welcome);

            DashboardController dashboardController = new DashboardController();

            NavigationMap.Add("Dashboard", dashboardController);
            NavigationMap.Add("Dashboard/CreateData/{name}", dashboardController);
            NavigationMap.Add("Dashboard/{UserId}", dashboardController);

            // Set default navigation URI
            NavigateOnLoad = "WelcomeScreen";
        }
Exemple #27
0
    protected override void _Resolver(Hashtable args)
    {
        base._Resolver(args);

        result_human_win.active   = false;
        result_monster_win.active = false;

        game_end_text_ = this.GetComponentInChildren <GUIText>();
        if (game_end_text_ == null)
        {
            Debug.LogError("<Scene_Game::_Resolver> invalid game_end_text_");
        }
        game_end_text_.text = "";

//		if (args.Contains("Scene_Game")) {
//			scene_game_ =(Scene_Game)args["Scene_Game"];
//		}

//		GameDataShare.forest_sand_percentage = 0.2f;
//		GameDataShare.mountain_percentage = 0.1f;
        NavigationMap.GetInstance().Init("Scene_Game", this);

//		Entity target_entity = null;

//		GameActor human = GameActor.Create ( GameSettings.GetInstance().HUMAN_PREFAB_NAME );
//		AddEntity ( human );
//		NavigationMap.GetInstance().RegisterActor ( human );
//
//		GameActor monster = GameActor.Create ( "Entity_Monster" );
//		AddEntity ( monster );
//		monster.transform.localPosition = new Vector3 ( 64 * 5, 64 * 4 );
//		NavigationMap.GetInstance().RegisterActor ( monster );

        tile_map_ = new Tile_Map();
        tile_map_.Init();

        audio_background_.Play();
//		monster_ = GameActor.Create ( "BaseEntity" );
//		AddEntity ( monster_ );
//		monster_.transform.localPosition = new Vector3 ( GameSettings.GetInstance().TILE_SIZE, 0, 0 );
    }
Exemple #28
0
 public SonicRangeFinder(SensorSpecifications sensorSpecifications, bool isPerfect, NavigationMap map)
     : base(isPerfect)
 {
     _map = map;
     _relativeRangeDirection = Vector3.Down;
 }
Exemple #29
0
    protected override void _Thinker()
    {
        base._Thinker();

        int row    = 0;
        int column = 0;

        bool processed = false;

        // see if you can move
//		if ( false ) {
//			processed = true;
//		}

        if (!processed && is_spawner_)
        {
            int        cur_map_x  = (int)this.map_pos.x;
            int        cur_map_y  = (int)this.map_pos.y;
            Scene_Game scene_game = (Scene_Game)SceneManager.GetInstance().cur_scene;
            scene_game.AddActorSpawner(ActorType.human, cur_map_y, cur_map_x);
            processed = true;
        }

        // see if he see a monster
        if (!processed && NavigationMap.GetInstance().GetNearestMonster(this, out row, out column))
        {
            int cur_map_x  = (int)this.map_pos.x;
            int cur_map_y  = (int)this.map_pos.y;
            int diff_map_x = Mathf.Abs(cur_map_x - column);
            int diff_map_y = Mathf.Abs(cur_map_y - row);
            int distance   = diff_map_x + diff_map_y;
            if (distance <= GameSettings.GetInstance().HUMAN_AVOID_DISTANCE)
            {
                int new_map_x = 0;
                int new_map_y = 0;
                if (NavigationMap.GetInstance().MoveAway(this, row, column, out new_map_x, out new_map_y))
                {
                    NavigationMap.GetInstance().UnRegisterActor(this);
                    // get away for that area!
                    this.pos = new Vector3(new_map_x * GameSettings.GetInstance().TILE_SIZE,
                                           new_map_y * GameSettings.GetInstance().TILE_SIZE,
                                           0.0f);
                    NavigationMap.GetInstance().RegisterActor(this);
//					Debug.Log ( "<Human::_Thinker>, running away from monster, heading to " + new_map_x + ", " + new_map_y );
                    processed = true;
                }
//				else {
//					if ( NavigationMap.GetInstance().GetRandomNearBy ( this, out new_map_y, out new_map_x ) ) {
//						NavigationMap.GetInstance().UnRegisterActor ( this );
//						this.pos = new Vector3 (new_map_x * GameSettings.GetInstance().TILE_SIZE,
//												new_map_y * GameSettings.GetInstance().TILE_SIZE,
//												0.0f );
//						NavigationMap.GetInstance().RegisterActor ( this );
//					}
//				}
            }
        }

        // check if he see food
        if (!processed && NavigationMap.GetInstance().GetNearestFood(this, out row, out column))
        {
            int new_map_x = 0;
            int new_map_y = 0;

            if (NavigationMap.GetInstance().MoveForward(this, row, column, out new_map_x, out new_map_y))
            {
                NavigationMap.GetInstance().UnRegisterActor(this);
                this.pos = new Vector3(new_map_x * GameSettings.GetInstance().TILE_SIZE,
                                       new_map_y * GameSettings.GetInstance().TILE_SIZE,
                                       0.0f);
                NavigationMap.GetInstance().RegisterActor(this);

                int cur_map_x = (int)this.map_pos.x;
                int cur_map_y = (int)this.map_pos.y;
                if (cur_map_x == column && cur_map_y == row)
                {
                    NavigationMap.GetInstance().EatFood(this, new_map_y, new_map_x);
                    Scene_Game scene_game = (Scene_Game)SceneManager.GetInstance().cur_scene;
//					scene_game.AddActorSpawner ( ActorType.human, cur_map_y, cur_map_x );
                    is_spawner_       = true;
                    moving_to_target_ = false;
                }
            }
//			else {
//				if ( NavigationMap.GetInstance().GetRandomNearBy ( this, out new_map_y, out new_map_x ) ) {
//					NavigationMap.GetInstance().UnRegisterActor ( this );
//					this.pos = new Vector3 (new_map_x * GameSettings.GetInstance().TILE_SIZE,
//											new_map_y * GameSettings.GetInstance().TILE_SIZE,
//											0.0f );
//					NavigationMap.GetInstance().RegisterActor ( this );
//				}
//			}

            processed = true;
//			Debug.Log ( "<Human::_Thinker>, running to food, heading to " + column + ", " + row );
        }

        if (moving_to_target_)
        {
            moving_to_target_ = !processed;
        }

        if (!processed && !moving_to_target_)
        {
            if (NavigationMap.GetInstance().GetRandomPos(this, out target_row_, out target_column_))
            {
                moving_to_target_ = true;
//				Debug.Log ( "<Human::_Thinker>, walking to random pos, heading to " + target_column_ + ", " + target_row_ );
                processed = true;
            }
        }

        if (moving_to_target_)
        {
            int new_map_x = 0;
            int new_map_y = 0;

            if (NavigationMap.GetInstance().MoveForward(this, target_row_, target_column_, out new_map_x, out new_map_y))
            {
                NavigationMap.GetInstance().UnRegisterActor(this);
                this.pos = new Vector3(new_map_x * GameSettings.GetInstance().TILE_SIZE,
                                       new_map_y * GameSettings.GetInstance().TILE_SIZE,
                                       0.0f);
                NavigationMap.GetInstance().RegisterActor(this);

                int cur_map_x = (int)this.map_pos.x;
                int cur_map_y = (int)this.map_pos.y;

                if (cur_map_x == target_column_ && cur_map_y == target_row_)
                {
                    moving_to_target_ = false;
                }
                processed = true;
//				Debug.Log ( "<Human::_Thinker>, continue walking to random pos, heading to " + target_column_ + ", " + target_row_ );
            }
//			else {
//				if ( NavigationMap.GetInstance().GetRandomNearBy ( this, out new_map_y, out new_map_x ) ) {
//					NavigationMap.GetInstance().UnRegisterActor ( this );
//					this.pos = new Vector3 (new_map_x * GameSettings.GetInstance().TILE_SIZE,
//											new_map_y * GameSettings.GetInstance().TILE_SIZE,
//											0.0f );
//					NavigationMap.GetInstance().RegisterActor ( this );
//				}
//			}
        }
    }
Exemple #30
0
 public void AddEmptyRoute(IMXController defaultController)
 {
     NavigationMap.Add(string.Empty, defaultController);
 }
Exemple #31
0
    protected override void _Thinker()
    {
        base._Thinker();

        bool processed = false;
        // check if he see
//		if ( false ) {
//			processed = true;
//		}

        int row    = -1;
        int column = -1;

        if (!processed && NavigationMap.GetInstance().GetNearestHumanForMonster(this, out row, out column))
        {
            int new_map_x = 0;
            int new_map_y = 0;
            int distance  = NavigationMap.GetInstance().CalculateDistance(this, row, column);
            if (distance <= GameSettings.GetInstance().MONSTER_SIGHT&&
                NavigationMap.GetInstance().MoveForward(this, row, column, out new_map_x, out new_map_y))
            {
                NavigationMap.GetInstance().UnRegisterActor(this);
                this.pos = new Vector3(new_map_x * GameSettings.GetInstance().TILE_SIZE,
                                       new_map_y * GameSettings.GetInstance().TILE_SIZE,
                                       0.0f);
                NavigationMap.GetInstance().RegisterActor(this);

                int cur_map_x = (int)this.map_pos.x;
                int cur_map_y = (int)this.map_pos.y;

                if (cur_map_x == column && cur_map_y == row)
                {
                    int kill_counter = NavigationMap.GetInstance().EatHuman(this, cur_map_y, cur_map_x);

                    // spawn monsters
                    if (kill_counter > 0)
                    {
                        Scene_Game scene_game = (Scene_Game)SceneManager.GetInstance().cur_scene;
                        for (int i = 0; i < kill_counter; ++i)
                        {
                            scene_game.AddActorSpawner(ActorType.monster, cur_map_y, cur_map_x);
                        }
//						Debug.Log ( "<Monster::_Thinker>, human eaten!" );
                    }
                }
                else
                {
//					Debug.Log ( "<Monster::_Thinker>, running to human, heading to " + column + ", " + row );
                }

                processed = true;
            }
        }

        if (moving_to_target_)
        {
            moving_to_target_ = !processed;
        }

        if (!processed && !moving_to_target_)
        {
            if (NavigationMap.GetInstance().GetRandomPos(this, out target_row_, out target_column_))
            {
                moving_to_target_ = true;
//				Debug.Log ( "<Monster::_Thinker>, random walking, heading to " + target_column_ + ", " + target_row_ );
                processed = true;
            }
        }

        if (moving_to_target_)
        {
            int cur_map_x = (int)this.map_pos.x;
            int cur_map_y = (int)this.map_pos.y;

            if (cur_map_x == target_column_ && cur_map_y == target_row_)
            {
                moving_to_target_ = false;
            }
            else
            {
                int new_map_x = 0;
                int new_map_y = 0;
                if (NavigationMap.GetInstance().MoveForward(this, target_row_, target_column_, out new_map_x, out new_map_y))
                {
//					Debug.Log ( this.gameObject.name + " is moving to " + new_map_x + ", " + new_map_y );
                    NavigationMap.GetInstance().UnRegisterActor(this);
                    this.pos = new Vector3(new_map_x * GameSettings.GetInstance().TILE_SIZE,
                                           new_map_y * GameSettings.GetInstance().TILE_SIZE,
                                           0.0f);
                    NavigationMap.GetInstance().RegisterActor(this);
                }

//				Debug.Log ( "<Monster::_Thinker>, continue random walk " + target_column_ + ", " + target_row_ );
                processed = true;
            }
        }
    }