Esempio n. 1
0
    public void f_items_add()
    {
        // Look for a suitable position in the world and instantiate the player
        // and one axe there.
        bool _found = false;

        while (!_found)
        {
            var _i = Random.Range(world.i_max / 4, 3 * world.i_max / 4 + 1);
            var _j = Random.Range(world.j_max / 4, 3 * world.j_max / 4 + 1);

            if (world.map[_i, _j] > 0 && world.map[_i, _j + 1] > 0 && world.forest[_i, _j] < -1 && world.forest[_i, _j + 1] < -4)
            {
                if ((world.map[_i - 1, _j] <= -100 ||
                     world.map[_i - 1, _j - 1] <= -100 ||
                     world.map[_i - 1, _j + 1] <= -100 ||
                     world.map[_i + 1, _j] <= -100 ||
                     world.map[_i + 1, _j - 1] <= -100 ||
                     world.map[_i + 1, _j + 1] <= -100 ||
                     world.map[_i, _j + 1] <= -100 ||
                     world.map[_i, _j - 1] <= -100 ||
                     world.map[_i, _j - 2] <= -100 ||
                     world.map[_i, _j + 2] <= -100 ||
                     world.map[_i + 2, _j] <= -100 ||
                     world.map[_i - 2, _j] <= -100) &&
                    (world.forest[_i - 1, _j] > 0 ||
                     world.forest[_i - 1, _j - 1] > 0 ||
                     world.forest[_i - 1, _j + 1] > 0 ||
                     world.forest[_i + 1, _j] > 0 ||
                     world.forest[_i + 1, _j - 1] > 0 ||
                     world.forest[_i + 1, _j + 1] > 0 ||
                     world.forest[_i, _j + 1] > 0 ||
                     world.forest[_i, _j - 1] > 0 ||
                     world.forest[_i, _j - 2] > 0 ||
                     world.forest[_i, _j + 2] > 0 ||
                     world.forest[_i + 2, _j] > 0 ||
                     world.forest[_i - 2, _j] > 0))
                {
                    playerInstance = Instantiate(player, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                    GameObject _item_instance = Instantiate(axe, new Vector3(_i * 16, (_j + 1) * 16, 0), Quaternion.identity) as GameObject;
                    axes.Add(_item_instance);
                    _found = true;
                }
            }
        }

        // Get the position of the player so we can create items around that spot.
        var _I = (int)playerInstance.transform.position.x / 16;
        var _J = (int)playerInstance.transform.position.y / 16;

        // main shovel
        _found = false;
        while (!_found)
        {
            int _r = 12 + 4 * gameController.difficulty;
            int _i = _I + Random.Range(-_r, _r + 1);
            int _j = _J + Random.Range(-_r, _r + 1);
            if (world.map[_i, _j] > 0 && Utils.point_distance(_i, _j, _I, _J) > _r * 3 / 4 && Utils.point_distance(_i, _j, _I, _J) < _r)
            {
                if (world.forest[_i, _j] > 0)
                {
                    world.f_forest_destroy(_i, _j);
                    world.f_forest_destroy(_i + Random.Range(-1, 1), _j + 1);
                    world.f_forest_destroy(_i, _j + Random.Range(-1, 1 + 1));
                }
                GameObject _item_instance = Instantiate(shovel, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                shovels.Add(_item_instance);
                _found = true;
            }
        }

        // main hoe
        _found = false;
        while (!_found)
        {
            int _r = 16 + 6 * gameController.difficulty;
            int _i = _I + Random.Range(-_r, _r + 1);
            int _j = _J + Random.Range(-_r, _r + 1);
            if (world.map[_i, _j] > 0 && Utils.point_distance(_i, _j, _I, _J) > _r * 3 / 4 && Utils.point_distance(_i, _j, _I, _J) < _r)
            {
                if (world.forest[_i, _j] > 0)
                {
                    world.f_forest_destroy(_i, _j);
                    world.f_forest_destroy(_i + Random.Range(-1, 1), _j + 1);
                    world.f_forest_destroy(_i, _j + Random.Range(-1, 1 + 1));
                }
                GameObject _item_instance = Instantiate(hoe, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                hoes.Add(_item_instance);
                _found = true;
            }
        }

        // map
        _found = false;
        while (!_found)
        {
            int _r = 20 + 8 * gameController.difficulty;
            int _i = _I + Random.Range(-_r, _r + 1);
            int _j = _J + Random.Range(-_r, _r + 1);
            if (world.map[_i, _j] > 0 && Utils.point_distance(_i, _j, _I, _J) > _r * 3 / 4 && Utils.point_distance(_i, _j, _I, _J) < _r)
            {
                if (world.forest[_i, _j] > 0)
                {
                    world.f_forest_destroy(_i, _j);
                    world.f_forest_destroy(_i + Random.Range(-1, 1), _j + 1);
                    world.f_forest_destroy(_i, _j + Random.Range(-1, 1 + 1));
                }
                GameObject _item_instance = Instantiate(map, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                maps.Add(_item_instance);
                _found = true;
            }
        }

        // main food
        for (int i = 0; i < 6; i++)
        {
            _found = false;
            while (!_found)
            {
                int _i = _I + Random.Range(-24, 24 + 1);
                int _j = _J + Random.Range(-24, 24 + 1);

                if (world.map[_i, _j] > 0 && world.forest[_i, _j] < 0 && Utils.point_distance(_i, _j, _I, _J) > 8 && Utils.point_distance(_i, _j, _I, _J) < 24)
                {
                    GameObject _item_instance = Instantiate(food, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                    foods.Add(_item_instance);
                    _found = true;
                }
            }
        }

        // food!
        for (int i = 0; i < 40; i++)
        {
            _found = false;
            while (!_found)
            {
                int _i = Random.Range(10, world.i_max - 10 + 1);
                int _j = Random.Range(10, world.j_max - 10 + 1);
                if (world.map[_i, _j] > 0)
                {
                    if (world.forest[_i, _j] > 0)
                    {
                        if (Utils.f_chance(0.25f))
                        {
                            world.f_forest_destroy(_i, _j);
                            world.f_forest_destroy(_i + Random.Range(-1, 1), _j + 1);
                            world.f_forest_destroy(_i, _j + Random.Range(-1, 1 + 1));
                            GameObject _item_instance = Instantiate(food, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                            foods.Add(_item_instance);
                            _found = true;
                        }
                    }
                    else
                    {
                        GameObject _item_instance = Instantiate(food, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                        foods.Add(_item_instance);
                        _found = true;
                    }
                }
            }
        }

        // more tools!
        for (int i = 0; i < 13 - 4 * gameController.difficulty; i++)
        {
            _found = false;
            while (!_found)
            {
                int _i = Random.Range(10, world.i_max - 10 + 1);
                int _j = Random.Range(10, world.j_max - 10 + 1);
                if (world.map[_i, _j] > 0)
                {
                    if (world.forest[_i, _j] > 0)
                    {
                        world.f_forest_destroy(_i, _j);
                        world.f_forest_destroy(_i + Random.Range(-1, 1), _j + 1);
                        world.f_forest_destroy(_i, _j + Random.Range(-1, 1 + 1));
                    }
                    int _rand = Random.Range(1, 4);
                    switch (_rand)
                    {
                    case 1:
                        GameObject axe_instance = Instantiate(axe, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                        hoes.Add(axe_instance);
                        break;

                    case 2:
                        GameObject shovel_instance = Instantiate(shovel, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                        hoes.Add(shovel_instance);
                        break;

                    case 3:
                        GameObject hoe_instance = Instantiate(hoe, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                        hoes.Add(hoe_instance);
                        break;
                    }
                    _found = true;
                }
            }
        }

        // puzzle pieces!!!
        _found = false;
        while (!_found)
        {
            int _i = Random.Range(30, world.i_max - 30 + 1);
            int _j = Random.Range(30, world.j_max - 30 + 1);
            if (world.map[_i, _j] > 0 && Utils.point_distance(_i, _j, world.i_max / 2, world.j_max / 2) > 32)
            {
                if (world.forest[_i, _j] > 0)
                {
                    world.f_forest_destroy(_i, _j);
                    world.f_forest_destroy(_i + Random.Range(-1, 1), _j + 1);
                    world.f_forest_destroy(_i, _j + Random.Range(-1, 1 + 1));
                }
                GameObject _item_instance = Instantiate(puzzle_piece_A, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                puzzle_pieces_A.Add(_item_instance);
                _found = true;
            }
        }

        _found = false;
        while (!_found)
        {
            int _i = Random.Range(30, world.i_max - 30 + 1);
            int _j = Random.Range(30, world.j_max - 30 + 1);
            if (world.map[_i, _j] > 0 && Utils.point_distance(_i, _j, world.i_max / 2, world.j_max / 2) > 32)
            {
                if (world.forest[_i, _j] > 0)
                {
                    world.f_forest_destroy(_i, _j);
                    world.f_forest_destroy(_i + Random.Range(-1, 1), _j + 1);
                    world.f_forest_destroy(_i, _j + Random.Range(-1, 1 + 1));
                }
                GameObject _item_instance = Instantiate(puzzle_piece_B, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                puzzle_pieces_B.Add(_item_instance);
                _found = true;
            }
        }

        _found = false;
        while (!_found)
        {
            int _i = Random.Range(30, world.i_max - 30 + 1);
            int _j = Random.Range(30, world.j_max - 30 + 1);
            if (world.map[_i, _j] > 0 && Utils.point_distance(_i, _j, world.i_max / 2, world.j_max / 2) > 32)
            {
                if (world.forest[_i, _j] > 0)
                {
                    world.f_forest_destroy(_i, _j);
                    world.f_forest_destroy(_i + Random.Range(-1, 1), _j + 1);
                    world.f_forest_destroy(_i, _j + Random.Range(-1, 1 + 1));
                }
                GameObject _item_instance = Instantiate(puzzle_piece_C, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                puzzle_pieces_C.Add(_item_instance);
                _found = true;
            }
        }

        _found = false;
        while (!_found)
        {
            int _i = Random.Range(30, world.i_max - 30 + 1);
            int _j = Random.Range(30, world.j_max - 30 + 1);
            if (world.map[_i, _j] > 0 && Utils.point_distance(_i, _j, world.i_max / 2, world.j_max / 2) > 32)
            {
                if (world.forest[_i, _j] > 0)
                {
                    world.f_forest_destroy(_i, _j);
                    world.f_forest_destroy(_i + Random.Range(-1, 1), _j + 1);
                    world.f_forest_destroy(_i, _j + Random.Range(-1, 1 + 1));
                }
                GameObject _item_instance = Instantiate(puzzle_piece_D, new Vector3(_i * 16, _j * 16, 0), Quaternion.identity) as GameObject;
                puzzle_pieces_D.Add(_item_instance);
                _found = true;
            }
        }

        // Whenever an item was set to spawn on a tile where there was forest we
        // destroyed that forest, this resulted in a lot of logs being generated.
        // Destroy all these logs before the game begins.
        foreach (GameObject log in logs)
        {
            Destroy(log);
        }
        logs.Clear();
    }
    void Update()
    {
        if (!gameController.start)
        {
            return;
        }

        if (energy > 0)
        {
            if (sleeping)
            {
                sleeping = false;
                spriteAnimator.Play("s_player_south");
            }

            _h = input._h;
            _v = input._v;

            // Assign transform position to variables similarily named as those in
            // Game Maker for ease of use.
            x = transform.position.x;
            y = transform.position.y;

            if (input._A)
            {
                left_hand_counter++;
            }
            else if (left_hand_counter < 15 && left_hand_counter > 0)
            {
                // pick up or drop
                left_hand_counter = 0;

                int _x = Mathf.RoundToInt(x / 16) * 16;
                int _y = Mathf.RoundToInt(y / 16) * 16;

                if (left_hand == "none")
                {
                    f_item_pickup(_x, _y, ref left_hand, ref left_hand_game_object);
                    // see if anything can be picked up
                }
                else if (world.f_array_get_map(_x / 16, _y / 16, -1000) > 0)   // not on a raft
                {
                    f_item_drop(_x, _y, ref left_hand, ref left_hand_game_object);
                }
            }
            else
            {
                left_hand_counter = 0;
            }

            if (input._B)
            {
                right_hand_counter++;
            }
            else if (right_hand_counter < 15 && right_hand_counter > 0)
            {
                // pick up or drop
                right_hand_counter = 0;

                int _x = Mathf.RoundToInt(x / 16) * 16;
                int _y = Mathf.RoundToInt(y / 16) * 16;

                if (right_hand == "none")
                {
                    f_item_pickup(_x, _y, ref right_hand, ref right_hand_game_object);
                    // see if anything can be picked up
                }
                else if (world.f_array_get_map(_x / 16, _y / 16, -1000) > 0)   // not on a raft
                {
                    f_item_drop(_x, _y, ref right_hand, ref right_hand_game_object);
                }
            }
            else
            {
                right_hand_counter = 0;
            }

            if (_v < 0)
            {
                spriteAnimator.Play("s_player_south");
            }
            else if (_h < 0)
            {
                spriteAnimator.Play("s_player_west");
            }
            else if (_h > 0)
            {
                spriteAnimator.Play("s_player_east");
            }
            else if (_v > 0)
            {
                spriteAnimator.Play("s_player_north");
            }

            bool _chopping  = false;
            bool _rafting   = false;
            bool _bridging  = false;
            bool _tilling   = false;
            bool _planting  = false;
            bool _reaping   = false;
            bool _mapping   = false;
            bool _secreting = false;

            if (x % 16 == 0 && y % 16 == 0)
            {
                int _i = Mathf.RoundToInt(x / 16);
                int _j = Mathf.RoundToInt(y / 16);

                int   _map = world.f_array_get_map(_i + _h, _j + _v, -1000);
                float _for = world.f_array_get_forest(_i + _h, _j + _v, -1);

                if (_map >= 0 && _for < 0 && (_h != 0 || _v != 0) && !(world.f_array_get_map(_i + _h, _j, -1000) < 0 && world.f_array_get_map(_i, _j + _v, -1000) < 0))   // walking
                {
                    move_h = _h;
                    move_v = _v;

                    Instantiate(items.floor_bits, new Vector3(x, y - 2, 0), Quaternion.identity);

                    energy -= energy_step;

                    spriteAnimator.fps = 10;
                }
                else if (world.f_array_get_map(_i, _j, 10000) == 10000 && _map <= -100 && (_h != 0 || _v != 0))   // moving on a raft
                {
                    move_h = _h * 0.5f;
                    move_v = _v * 0.5f;

                    spriteAnimator.currentFrame = 0;
                    spriteAnimator.fps          = 0;

                    energy -= energy_paddle;

                    // Find the raft beneath us and move it with us.
                    int i = 0;
                    foreach (GameObject raft in items.rafts)
                    {
                        if (raft.transform.position.x == x && raft.transform.position.y == y)
                        {
                            raft.transform.position += new Vector3(
                                _h * 16,
                                _v * 16,
                                0
                                );
                        }
                        i++;
                    }

                    // Set the position we came from to be deep water.
                    world.f_array_set_map(_i, _j, -100);
                    // Set the position we're going to to be raft.
                    world.f_array_set_map(_i + _h, _j + _v, 10000);
                }
                else   // not moving, so do other checks...
                {
                    move_h = 0;
                    move_v = 0;

                    spriteAnimator.currentFrame = 0;
                    spriteAnimator.fps          = 0;

                    // chop that tree?
                    if (_for >= 0 && ((left_hand == "axe" && left_hand_counter > 0) || (right_hand == "axe" && right_hand_counter > 0)))
                    {
                        counter_chop++;
                        _chopping = true;
                        if (Utils.f_chance(0.4f))
                        {
                            Instantiate(items.wood_bits, new Vector3(x + _h * 12, y + _v * 12, 0), Quaternion.identity);
                        }
                        SoundController.instance.PlaySound("snd_hit", 0.4f);

                        if (counter_chop >= 60)
                        {
                            // CHOP THAT TREE
                            counter_chop = 0;
                            for (int i = 0; i < 10; i++)
                            {
                                Instantiate(items.wood_bits, new Vector3(x + _h * 16, y + _v * 16, 0), Quaternion.identity);
                            }
                            SoundController.instance.PlaySound("snd_hit_done");
                            energy -= energy_chop;
                            world.f_forest_destroy(_i + _h, _j + _v);
                        }
                    }
                    // build that bridge?
                    else if (_map > -100 && _map < 0 && ((left_hand == "log" && left_hand_counter > 0) || (right_hand == "log" && right_hand_counter > 0)))
                    {
                        counter_bridge++;
                        _bridging = true;
                        if (Utils.f_chance(0.5f))
                        {
                            Instantiate(items.wood_bits, new Vector3(x + _h * 12, y + _v * 12, 0), Quaternion.identity);
                        }
                        SoundController.instance.PlaySound("snd_hit", 0.4f);
                        if (counter_bridge >= 90)
                        {
                            // BUILD THAT BRIDGE
                            counter_bridge = 0;
                            for (int i = 0; i < 10; i++)
                            {
                                Instantiate(items.wood_bits, new Vector3(x + _h * 8, y + _v * 8, 0), Quaternion.identity);
                            }
                            SoundController.instance.PlaySound("snd_hit_done");
                            energy -= energy_bridge;
                            Instantiate(items.bridge, new Vector3((_i + _h) * 16, (_j + _v) * 16, 0), Quaternion.identity);
                            if (left_hand == "log")
                            {
                                left_hand = "none";
                                Destroy(left_hand_game_object);
                            }
                            else
                            {
                                right_hand = "none";
                                Destroy(right_hand_game_object);
                            }
                        }
                    }
                    // build that raft?
                    else if (_map <= -100 && ((left_hand == "log" && left_hand_counter > 0) || (right_hand == "log" && right_hand_counter > 0)))
                    {
                        counter_raft++;
                        _rafting = true;
                        if (Utils.f_chance(0.666f))
                        {
                            Instantiate(items.wood_bits, new Vector3(x + _h * 12, y + _v * 12, 0), Quaternion.identity);
                        }
                        SoundController.instance.PlaySound("snd_hit", 0.4f);
                        if (counter_raft >= 120)
                        {
                            // BUILD THAT RAFT
                            counter_raft = 0;
                            for (int i = 0; i < 10; i++)
                            {
                                Instantiate(items.wood_bits, new Vector3(x + _h * 8, y + _v * 8, 0), Quaternion.identity);
                            }
                            SoundController.instance.PlaySound("snd_hit_done");
                            energy -= energy_raft;
                            GameObject instantiatedRaft = Instantiate(items.raft, new Vector3((_i + _h) * 16, (_j + _v) * 16, 0), Quaternion.identity) as GameObject;
                            items.rafts.Add(instantiatedRaft);
                            if (left_hand == "log")
                            {
                                left_hand = "none";
                                Destroy(left_hand_game_object);
                            }
                            else
                            {
                                right_hand = "none";
                                Destroy(right_hand_game_object);
                            }
                        }
                    }
                    // till that ground?
                    else if (_map >= 0 && _for < 0 && ((left_hand == "shovel" && left_hand_counter > 0) || (right_hand == "shovel" && right_hand_counter > 0)))
                    {
                        counter_till++;
                        bool _skip = false;
                        for (int i = 0; i < items.soils.Count; i++)
                        {
                            if (items.soils[i].transform.position.x == x && items.soils[i].transform.position.y == y)
                            {
                                _skip = true;
                            }
                        }
                        if (!_skip)
                        {
                            _tilling = true;
                            if (Utils.f_chance(0.333f))
                            {
                                Instantiate(items.light_bits, new Vector3(x, y - 3, 0), Quaternion.identity);
                            }
                            SoundController.instance.PlaySound("snd_dig");
                        }
                        if (counter_till >= 90)
                        {
                            for (int i = 0; i < items.treasures.Count; i++)
                            {
                                if (items.treasures[i].transform.position.x == x && items.treasures[i].transform.position.y == y)
                                {
                                    // you win!
                                    _skip = true;
                                    if (!items.treasures[i].GetComponent <Treasure>().dug_up)
                                    {
                                        items.treasures[i].GetComponent <Treasure>().dug_up = true;
                                        for (int j = 0; j < 20; j++)
                                        {
                                            Instantiate(items.light_bits, new Vector3(x, y - 3, 0), Quaternion.identity);
                                        }
                                        for (int j = 0; j < 10; j++)
                                        {
                                            Instantiate(items.wood_bits, new Vector3(x, y, 0), Quaternion.identity);
                                        }
                                        SoundController.instance.PlaySound("snd_dig_done");
                                    }
                                }
                            }

                            // TILL THAT GROUND
                            counter_till = 0;
                            if (!_skip)
                            {
                                SoundController.instance.PlaySound("snd_dig_done");
                                energy -= energy_till;
                                GameObject instantiatedSoil = Instantiate(items.soil, new Vector3((_i + _h) * 16, (_j + _v) * 16, 0), Quaternion.identity) as GameObject;
                                items.soils.Add(instantiatedSoil);
                            }
                        }
                    }
                    // eat that turnip?
                    else if (_map >= 0 && _for < 0 && ((left_hand == "food" && left_hand_counter > 0) || (right_hand == "food" && right_hand_counter > 0)) && food < food_max)
                    {
                        counter_plant++;
                        _planting = true;
                        if (counter_plant >= 60)
                        {
                            for (int i = 0; i < 10; i++)
                            {
                                Instantiate(items.light_bits, new Vector3(x, y + 2, 0), Quaternion.identity);
                            }
                            SoundController.instance.PlaySound("snd_eat");
                            // EAT THAT TURNIP
                            counter_plant = 0;
                            if (left_hand == "food")
                            {
                                left_hand = "none";
                                Destroy(left_hand_game_object);
                            }
                            else
                            {
                                right_hand = "none";
                                Destroy(right_hand_game_object);
                            }
                            food++;
                        }
                    }
                    // check out that map?
                    else if ((left_hand == "map" && left_hand_counter > 0) || (right_hand == "map" && right_hand_counter > 0))
                    {
                        counter_map++;
                        _mapping = true;
                    }
                    // puzzle that secret?
                    else if ((left_hand == "puzzle" && left_hand_counter > 0) || (right_hand == "puzzle" && right_hand_counter > 0))
                    {
                        counter_secret++;
                        _secreting = true;
                    }
                    // reap that ground?
                    else if (_map >= 0 && _for < 0 && ((left_hand == "hoe" && left_hand_counter > 0) || (right_hand == "hoe" && right_hand_counter > 0)))
                    {
                        counter_reap++;

                        bool _skip = true;
                        for (int i = 0; i < items.soils.Count; i++)
                        {
                            if (items.soils[i].transform.position.x == x && items.soils[i].transform.position.y == y && items.soils[i].GetComponent <Soil>().filled)
                            {
                                _skip = false;
                            }
                        }

                        if (!_skip)
                        {
                            _reaping = true;
                            if (Utils.f_chance(0.2f))
                            {
                                Instantiate(items.light_bits, new Vector3(x, y - 3, 0), Quaternion.identity);
                            }
                            SoundController.instance.PlaySound("snd_dig");
                        }

                        if (counter_reap >= 60)
                        {
                            for (int i = 0; i < 10; i++)
                            {
                                Instantiate(items.light_bits, new Vector3(x, y - 3, 0), Quaternion.identity);
                            }
                            SoundController.instance.PlaySound("snd_dig_done");
                            // REAP THAT GROUND
                            counter_reap = 0;
                            for (int i = 0; i < items.soils.Count; i++)
                            {
                                if (items.soils[i].transform.position.x == x && items.soils[i].transform.position.y == y && items.soils[i].GetComponent <Soil>().filled)
                                {
                                    int        _temp         = Random.Range(0, 2);
                                    GameObject food_instance = Instantiate(items.food, new Vector3(x, y, 0), Quaternion.identity) as GameObject;
                                    food_instance.GetComponent <SpriteAnimator>().currentFrame = _temp;
                                    items.foods.Add(food_instance);
                                    if (items.soils[i].GetComponent <Soil>().stage == 3)
                                    {
                                        GameObject food_instance2 = Instantiate(items.food, new Vector3(x, y, 0), Quaternion.identity) as GameObject;
                                        food_instance2.GetComponent <SpriteAnimator>().currentFrame = _temp + 2;
                                        items.foods.Add(food_instance2);
                                    }
                                    energy -= energy_reap;
                                    items.soils[i].GetComponent <Soil>().filled = false;
                                    items.soils[i].GetComponent <Soil>().stage  = 0;
                                }
                            }
                        }
                    }
                }
            }

            // Show the map.
            if (counter_map > 15)
            {
                mapController.mapObject.SetActive(true);
            }
            else if (counter_secret > 15)
            {
                mapController.secretObject.SetActive(true);
            }
            else
            {
                mapController.mapObject.SetActive(false);
                mapController.secretObject.SetActive(false);
            }

            if (!_chopping)
            {
                counter_chop = 0;
            }
            if (!_rafting)
            {
                counter_raft = 0;
            }
            if (!_bridging)
            {
                counter_bridge = 0;
            }
            if (!_tilling)
            {
                counter_till = 0;
            }
            if (!_planting)
            {
                counter_plant = 0;
            }
            if (!_reaping)
            {
                counter_reap = 0;
            }
            if (!_mapping)
            {
                counter_map = 0;
            }
            if (!_secreting)
            {
                counter_secret = 0;
            }
        }
        else if (!sleeping && !dying)
        {
            if (x % 16 == 0 && y % 16 == 0)
            {
                move_h   = 0;
                move_v   = 0;
                sleeping = true;
                SoundController.instance.PlaySound("snd_sleep");
                spriteAnimator.Play("s_player_sleeping");
                spriteAnimator.fps = 7;
                for (int i = 0; i < 6; i++)
                {
                    Instantiate(items.light_bits, new Vector3(x, y - 3, 0), Quaternion.identity);
                }
            }
        }

        if (dying)
        {
            move_h = 0;
            move_v = 0;
            if (spriteAnimator.currentFrame >= 14)
            {
                spriteAnimator.currentFrame = 14;
            }
        }

        if (move_h != 0 || move_v != 0)
        {
            if (move_h != 0)
            {
                x += 2 * move_h;
            }

            if (move_v != 0)
            {
                y += 2 * move_v;
            }

            transform.position = new Vector3(x, y, transform.position.z);
        }

        Camera.main.transform.position = new Vector3(transform.position.x + 8, transform.position.y, Camera.main.transform.position.z);

        // Draw any items we're currently holding.
        DrawItems();
    }