void Start() { world.f_array_set_map((int)transform.position.x / 16, (int)transform.position.y / 16, 1); spriteAnimator.fps = 3; spriteAnimator.Play("s_bridge"); spriteAnimator.currentFrame = Random.Range(0, spriteAnimator.animations[0].frames.Length); }
void Start() { world.f_array_set_map((int)transform.position.x / 16, (int)transform.position.y / 16, 10000); x_visual = transform.position.x; y_visual = transform.position.y; sprite = new GameObject(); sprite.AddComponent <SpriteRenderer>(); sprite.GetComponent <SpriteRenderer>().sprite = spriteRenderer.sprite; sprite.GetComponent <SpriteRenderer>().material = spriteRenderer.material; sprite.GetComponent <SpriteRenderer>().sortingOrder = spriteRenderer.sortingOrder; sprite.name = "raft_sprite"; spriteRenderer.enabled = false; }
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(); }