void LoadLevel() { Player.worldpos = new Vector3Int( last_player_pos.x * Grid.GetNodeLength, last_player_pos.y * Grid.GetNodeLength, last_player_pos.z * Grid.GetNodeLength); data_level dat = levels[currentLevNum]; Grid.ClearTiles(); Grid.worldsize = new Vector3Int(dat.size_x, dat.size_y, 45); Grid.Initialize(); for (int x = 0; x < Grid.worldsize.x - 1; x++) { for (int y = 0; y < Grid.worldsize.y - 1; y++) { for (int z = 0; z < Grid.worldsize.z - 1; z++) { data_level.data_block blok = dat.blocks.Find(bl => bl.x == x && bl.y == y && bl.z == z); data_level.data_door dr = dat.doors.Find(bl => bl.x == x && bl.y == y && bl.z == z); data_level.data_item it = dat.items.Find(bl => bl.x == x && bl.y == y && bl.z == z); if (blok != null) { o_block block = Grid.SpawnObject(blok.name, new Vector3Int(x, y, z)); } if (dr != null) { o_block block = Grid.SpawnObject(dr.name, new Vector3Int(x, y, z)); o_door door = block.GetComponent <o_door>(); door.location = dr.lev; door.teleport_position = new Vector3Int(dr.tele_x, dr.tele_y, dr.tele_z); door.locked = dr.locked; door.required_waterstones = dr.require; door.DOOR_STATE = (o_door.DOOR_MODE)dr.doortype; } if (it != null) { o_block block = Grid.SpawnObject(it.name, new Vector3Int(x, y, z)); o_item item = block.GetComponent <o_item>(); item.item = it.item; } } } } }
void ICharacter.Intialize() { defeated = false; current_item = null; actionPoints = maxActionPoints; health = maxHealth; hasdisapeared = false; GameObject manager = GameObject.Find("Manager"); if (GameObject.Find("CharacterManager") != null) { charctMnger = GameObject.Find("CharacterManager").GetComponent <s_charactermanager>(); } renderer = GetComponent <SpriteRenderer>(); grid = manager.GetComponent <s_grid>(); path = manager.GetComponent <s_pathfind>(); }
public void SaveLevel() { s_object[,,] objec = Grid.blocks; data_level da = new data_level(); da.blocks = new List <data_level.data_block>(); da.doors = new List <data_level.data_door>(); da.size_x = Grid.worldsize.x; da.size_y = Grid.worldsize.y; da.size_z = Grid.worldsize.z; da.name = inpfeild.text; for (int x = 0; x < Grid.worldsize.x - 1; x++) { for (int y = 0; y < Grid.worldsize.y - 1; y++) { for (int z = 0; z < Grid.worldsize.z - 1; z++) { if (objec[x, y, z]) { //This is a pretty crude approach, trying to save everything into seperate things if (objec[x, y, z].GetType() == typeof(o_door)) { o_door door = (o_door)objec[x, y, z]; if (door.location != "") { da.doors.Add(new data_level.data_door(x, y, z, door.locked, door.name, door.location, new Vector3Int( door.teleport_position.x, door.teleport_position.y, door.teleport_position.z ), door.DOOR_STATE, door.required_waterstones)); } else { da.doors.Add(new data_level.data_door(x, y, z, door.name, door.locked, new Vector3Int( door.teleport_position.x, door.teleport_position.y, door.teleport_position.z ), door.DOOR_STATE, door.required_waterstones )); } } else if (objec[x, y, z].GetType() == typeof(o_block)) { da.blocks.Add(new data_level.data_block(x, y, z, objec[x, y, z].name)); } else if (objec[x, y, z].GetType() == typeof(o_item)) { o_item item = (o_item)objec[x, y, z]; da.items.Add(new data_level.data_item(x, y, z, item.name, item.item)); } } } } } if (levels.Count == 0 || levels[currentLevNum].name != da.name) { levels.Add(da); } else if (levels[currentLevNum].name == da.name) { levels[currentLevNum] = da; } }