public override void Add_Tile(Vector3Int i_pos, TileBase i_tile) { Debug.Log("Tile added to energy"); bool is_valid = false; if (tm == null) { tm = GameObject.FindGameObjectWithTag("TileManager").GetComponent <Tile_Manager>(); } if (Check_Tiletype(system_tiles["Transmitters"], i_tile)) { energy_dictionary.Add(i_pos, Create_Energy_Tile(i_tile)); is_valid = true; } else if (Check_Tiletype(system_tiles["Generators"], i_tile)) { Debug.Log("Generator Added"); generator_dictionary.Add(i_pos, 1); is_valid = true; } else if (Check_Tiletype(system_tiles["Receptors"], i_tile)) { Energy_Receptor input_receptor; if (tm.Check_Layer_Name(i_tile, "Wheel")) { input_receptor = new Ship_Wheel(i_pos, tm.Grab_Ship_Layer(i_tile)); } else { if (is_ship_mode) { input_receptor = new Door(i_pos, i_tile, tm.Grab_Ship_Layer(i_tile)); } else { input_receptor = new Door(i_pos, i_tile, tm.Grab_Layer(i_tile)); } } receptor_dictionary.Add(i_pos, input_receptor); is_valid = true; } if (is_valid) { base.Add_Tile(i_pos, i_tile); } else { Debug.LogWarning("Invalid tile addition at:" + i_pos + " with " + i_tile); } }
private void Set_Tile_Colours() { Tilemap liquid_tilemap; foreach (var liquid_tile in liquid_dictionary) { liquid_tilemap = tm.Grab_Layer(liquid_tile.Value.tile); liquid_tilemap.SetTileFlags(liquid_tile.Key, TileFlags.None); liquid_tilemap.SetColor(liquid_tile.Key, new Color(1.0f, 1.0f, 1.0f, Mathf.Clamp(liquid_tile.Value.liquid_amount, min_water, max_water))); } }
protected override void System_Update() { if (!is_ship) { ship_rb.velocity = new Vector2(0.0f, 0.0f); ship_rb.position = new Vector2(0.0f, 0.0f); ship_rb.angularVelocity = 0.0f; ship_rb.rotation = 0.0f; } if (is_ship_control_activated) { is_ship_control_activated = false; Find_Wheel(); is_converting_to_ship = !is_converting_to_ship; if ((is_converting_to_ship) && (!is_ship)) { tm.Init_Ship_Systems(); Find_Wheel(); Tilemap wheel_tilemap = tm.Grab_Layer(system_tiles["Wheel"][0]); ship_movement.Set_Rotation(wheel_tilemap.GetTransformMatrix(wheel_pos).rotation); Debug.Log("Rotation: " + wheel_tilemap.GetTransformMatrix(wheel_pos).rotation); ship_tile_positions.Clear(); Convert_To_Ship(wheel_pos); Copy_Touching_Layers(tilemaps, ship_tilemaps, -1, false); movement.Set_Parent(ship_rb); player_self_movement = false; ship_movement.enabled = !player_self_movement; player_movement.Set_Independant_Movement(player_self_movement); is_converting_to_ship = false; is_ship = true; } else if (is_ship) { Debug.Log(ship_rb.angularVelocity); if (Mathf.Abs(ship_rb.angularVelocity) > 10.0f) { Debug.Log("Ship rotating too fast to dock"); } else if (Mathf.Abs(ship_rb.velocity.magnitude) > 5.0f) { Debug.Log("Ship moving too fast to dock"); } else { Rotation_Snap(); is_snap_in_progress = true; ship_default_angular_drag = ship_rb.angularDrag; } } } if (is_snap_in_progress) { if (Rotation_Snap()) { ship_rb.angularDrag = ship_default_angular_drag; is_snap_in_progress = false; ship_tile_positions.Clear(); Convert_To_World(wheel_pos); Copy_Touching_Layers(ship_tilemaps, tilemaps, -1, true); movement.Set_Parent(null); ship_movement.enabled = false; player_movement.Set_Independant_Movement(true); ship_rb.velocity = new Vector2(0.0f, 0.0f); ship_rb.position = new Vector2(0.0f, 0.0f); ship_rb.angularVelocity = 0.0f; ship_rb.rotation = 0.0f; ship_rb.useAutoMass = true; is_converting_to_ship = false; is_ship = false; } } }
// Update is called once per frame void Update() { Selection_Update(); inventory_debug_show.text = "Slot: " + slot_selection + ": " + tile_inventory[slot_selection].amount; Vector3Int rounded_cursor_pos = new Vector3Int(); rounded_cursor_pos.x = Mathf.FloorToInt(cursor_obj.Get_World_Position().x); rounded_cursor_pos.y = Mathf.FloorToInt(cursor_obj.Get_World_Position().y); rounded_cursor_pos.z = 0; RaycastHit2D hit = Physics2D.Raycast(transform.position, rounded_cursor_pos - transform.position, Vector3.Distance(transform.position, rounded_cursor_pos)); Vector3 hit_position; if (hit.collider != null) { hit_position = hit.point; } else { hit_position = cursor_obj.Get_World_Position(); } float distance = Vector2.Distance(hit_position, cursor_obj.Get_World_Position()); if (distance < 1.0f) { if ((Input.GetMouseButton(0)) && (tile_inventory[slot_selection].amount > 0)) { if (alternate_floor_tilemap.GetTile(ship_grid.WorldToCell(cursor_obj.Get_World_Position())) != null) { if (alternate_place_tilemap.GetTile(ship_grid.WorldToCell(cursor_obj.Get_World_Position())) == null) { tm.Ship_Add_Tile(ship_grid.WorldToCell(cursor_obj.Get_World_Position()), place_tile); tile_count--; } } else if (floor_tilemap.GetTile(default_grid.WorldToCell(cursor_obj.Get_World_Position())) != null) { if (tm.Grab_Layer(tile_inventory[slot_selection].tile).GetTile(default_grid.WorldToCell(cursor_obj.Get_World_Position())) == null) { tm.Add_Tile(default_grid.WorldToCell(cursor_obj.Get_World_Position()), tile_inventory[slot_selection].tile); tile_inventory[slot_selection].amount--; } } } if (Input.GetMouseButton(1)) { if (alternate_floor_tilemap.GetTile(ship_grid.WorldToCell(cursor_obj.Get_World_Position())) != null) { if (alternate_place_tilemap.GetTile(ship_grid.WorldToCell(cursor_obj.Get_World_Position())) == place_tile) { tm.Ship_Remove_Tile(ship_grid.WorldToCell(cursor_obj.Get_World_Position()), place_tile); tile_count++; } } else if (floor_tilemap.GetTile(default_grid.WorldToCell(cursor_obj.Get_World_Position())) != null) { TileBase temp = tm.Grab_Layer(tile_inventory[slot_selection].tile).GetTile(default_grid.WorldToCell(cursor_obj.Get_World_Position())); if (tm.Grab_Layer(tile_inventory[slot_selection].tile).GetTile(default_grid.WorldToCell(cursor_obj.Get_World_Position())) == tile_inventory[slot_selection].tile) { tm.Remove_Tile(default_grid.WorldToCell(cursor_obj.Get_World_Position()), tile_inventory[slot_selection].tile); tile_inventory[slot_selection].amount++; } } } } }
private void Convert_Neighbour(Vector3Int i_pos) { bool has_spread = false; TileBase spawner_tile; Tilemap spawner_tilemap; //spawner_tile = system_tiles["Spawner"][0]; spawner_tile = swarm_dictionary[i_pos].tile; if (is_ship_mode) { //spawner_tile = system_tiles["Spawner"][0]; spawner_tilemap = tm.Grab_Ship_Layer(spawner_tile); } else { spawner_tilemap = tm.Grab_Layer(spawner_tile); } Vector3Int up_neighbour = i_pos + Vector3Int.up; if ((spawner_tilemap.GetTile(up_neighbour) != null) && (Count_Swarm_Neighbours(up_neighbour) < 2)) { if (!swarm_dictionary.ContainsKey(up_neighbour)) { if (is_ship_mode) { tm.Ship_Add_Tile(up_neighbour, spawner_tile); } else { tm.Add_Tile(up_neighbour, spawner_tile); } has_spread = true; } } Vector3Int down_neighbour = i_pos + Vector3Int.down; if (((spawner_tilemap.GetTile(down_neighbour) != null) && (!has_spread)) && (Count_Swarm_Neighbours(down_neighbour) < 2)) { if (!swarm_dictionary.ContainsKey(down_neighbour)) { if (is_ship_mode) { tm.Ship_Add_Tile(down_neighbour, spawner_tile); } else { tm.Add_Tile(down_neighbour, spawner_tile); } has_spread = true; } } Vector3Int left_neighbour = i_pos + Vector3Int.left; if (((spawner_tilemap.GetTile(left_neighbour) != null) && (!has_spread)) && (Count_Swarm_Neighbours(left_neighbour) < 2)) { if (!swarm_dictionary.ContainsKey(left_neighbour)) { if (is_ship_mode) { tm.Ship_Add_Tile(left_neighbour, spawner_tile); } else { tm.Add_Tile(left_neighbour, spawner_tile); } has_spread = true; } } Vector3Int right_neighbour = i_pos + Vector3Int.right; if (((spawner_tilemap.GetTile(right_neighbour) != null) && (!has_spread)) && (Count_Swarm_Neighbours(right_neighbour) < 2)) { if (!swarm_dictionary.ContainsKey(right_neighbour)) { if (is_ship_mode) { tm.Ship_Add_Tile(right_neighbour, spawner_tile); } else { tm.Add_Tile(right_neighbour, spawner_tile); } has_spread = true; } } }