public void InitialiseChunkPooling() { for (var i = 0; i < numberOfPool; i++) { GameObject chunk = Instantiate((GameObject)Resources.Load("Prefabs/Chunk"), new Vector3(0, 0, 0), transform.rotation); chunk.gameObject.SetActive(false); chunk.transform.parent = worldMapTransform; Tilemap[] tilemaps = chunk.GetComponentsInChildren <Tilemap>(); Tilemap tilemap = chunk.GetComponentInChildren <Tilemap>(); TileMapScript tileMapScript = tilemap.GetComponent <TileMapScript>(); Chunk ck = chunk.GetComponent <Chunk>(); ck.tilemap = tilemap; ck.cycleDay = cycleDay; ck.tilemapLight = tilemapLight; ck.tilemapWall = tilemapWall; ck.tilesLightMap = tilesLightMap; ck.wallTilesMap = wallTilesMap; ck.chunkSize = chunkSize; ck.lightService = lightService; ck.tilebaseDictionary = tilebaseDictionary; ck.tilesMap = null; ck.tilesObjetMap = tilesObjetMap; ck.tilesShadowMap = tilesShadowMap; ck.tilemapShadow = tilemapShadow; ck.indexX = -1; ck.indexY = -1; ck.tileMapScript = tileMapScript; ck.tileMapScript.tilesWorldMap = tilesWorldMap; unUsedChunk.Add(ck); } }
private void Awake() { if (!instance) { instance = this; } else { Destroy(gameObject); } Assert.IsNotNull(groundTileMap, "No ground tilemap found!"); Assert.IsNotNull(ApplePrefab, "No food prefab found!"); GameObject tileMapObject = GameObject.Find("GroundTilemap"); tileMap = tileMapObject.GetComponent <TileMapScript>(); GameObject snakeObject = GameObject.Find("Snake"); snake = snakeObject.GetComponent <Snake>(); SpawnFood(); GameObject foodObject = GameObject.Find("ApplePrefab(Clone)"); food = foodObject.GetComponent <FoodScript>(); if (scoreEvent == null) { scoreEvent = new GameModeEvent(); } }
// Update is called once per frame void Update() { //int startx=3, starty=3; if (Input.GetKey(KeyCode.Space) && Time.realtimeSinceStartup > lastRun + 0.25f) { TileMapScript tm = GetComponent <TileMapScript>(); //for(int i = 0; i < 10000; i++) endpos.x = Random.Range(0f, 640f); endpos.y = Random.Range(0f, 640f); startpos.x = Random.Range(0f, 640f); startpos.y = Random.Range(0f, 640f); coords = tm.GetPath(startpos, endpos); //(startx,starty,x,y); Debug.Log("Path: (" + startpos.ToString() + ") to (" + endpos.ToString() + "), isnull: " + (coords == null).ToString()); //Debug.Log("Coords got to (" + x.ToString() + ", " + y.ToString() + "), isnull: " + (coords == null).ToString()); lastRun = Time.realtimeSinceStartup; if (null == coords) { lastRun -= 0.1f; } x += 1; if (x > 9) { x = 0; y++; y %= 10; } } Debug.DrawLine(startpos, endpos, Color.yellow); if (!(null == coords)) { Vector3 start = new Vector3(), end = new Vector3(); //end.x = startx * 64 + 32; //end.y = starty * 64 + 32; end = startpos; Color c = Color.red; for (int i = 0; i <= coords.GetUpperBound(0); i++) { start.x = coords[i].x; // * 64 + 32; start.y = coords[i].y; // * 64 + 32; Debug.DrawLine(start, end, c); end = start; if (Color.red == c) { c = Color.blue; } else if (Color.blue == c) { c = Color.green; } else { c = Color.red; } } } }
public static TileMapScript exampleMap() {/* * int[,] map = new int[50, 50]; * for (int i = 0; i < 8; i++) * map[3, i] = 1;*/ TileMapScript map = FindObjectOfType <TileMapScript>(); return(map); }
private TileMapScript loadMap(string destination) { // get the map data TileMapScript map_data = new TileMapScript(); destination = destination.Substring(2); map_data.loadMap(destination + "_map_data.bin"); map_data.print_map(); return map_data; }
protected override void prepare_scene(string destination, string source) { Debug.Log("in scene"); _player.GetComponent<PlayerController>().stop_moving(); if (destination.Substring(1, 1) == "S") { map = loadMap(destination); GameObject.FindGameObjectWithTag("NetworkManager").GetComponent<NetworkManager>().StartHost(); na.nPlaceMap(map); } }
public void StartSpawning(List<Vector3> pListWaveStartPositions, List<Vector3> pListWaveEndPositions, TileMapScript pMap, NodeScript[,] pGraph, int pLevel) { _listWaveStartPositions = pListWaveStartPositions; _listWaveEndPositions = pListWaveEndPositions; _map = pMap; _graph = pGraph; _spawningStarted = true; _currentLevel = pLevel; FindObjectOfType<WaveIndicatorScript>().SetWaveIndicator(_currentWave, _levelList[_currentLevel - 1].WaveList.Count); }
// Use this for initialization void Start() { time = FindObjectOfType<GameTimeScript>(); tile_map = FindObjectOfType<TileMapScript>(); schedule = FindObjectOfType<ScheduleScript>(); path_finder = gameObject.AddComponent<WorldGenerator>(); is_moving = false; schedule.loadSchedule("schedule_data.bin"); Application.runInBackground = true; }
// for debug; public void RenderPartialMapForTest() { GameObject chunk = Instantiate((GameObject)Resources.Load("Prefabs/Chunk"), new Vector3(0, 0, 0), transform.rotation); chunk.transform.parent = worldMapTransform; Tilemap[] tilemaps = chunk.GetComponentsInChildren <Tilemap>(); Tilemap tilemap = chunk.GetComponentInChildren <Tilemap>(); TileMapScript tileMapScript = tilemap.GetComponent <TileMapScript>(); Chunk ck = chunk.GetComponent <Chunk>(); ck.tilemap = tilemap; ck.cycleDay = cycleDay; ck.tilemapLight = tilemapLight; ck.tilemapWall = tilemapWall; ck.tilesLightMap = tilesLightMap; ck.wallTilesMap = wallTilesMap; ck.tilesObjetMap = tilesObjetMap; ck.lightService = lightService; ck.tilesShadowMap = tilesShadowMap; ck.tilemapShadow = tilemapShadow; ck.chunkSize = 64; ck.tilebaseDictionary = tilebaseDictionary; ck.indexX = 0; ck.indexY = 0; ck.tileMapScript = tileMapScript; ck.tileMapScript.tilesWorldMap = tilesWorldMap; for (var x = 0; x < 1024; x++) { for (var y = 0; y < 1024; y++) { int tileIndex = tilesWorldMap[x, y]; if (tileIndex > 0) { tilemap.SetTile(new Vector3Int(x, y, 0), tilebaseDictionary[tileIndex]); } else { tilemap.SetTile(new Vector3Int(x, y, 0), null); } } } }
// Use this for initialization //Load all the Variables and Prepare the Radial Menu void Start() { //Get all the prefabs of the Idle towers level 1 _towerArrowIdle = (GameObject)Resources.Load("Towers/TreeIdleLevel1"); _towerCannonIdle = (GameObject)Resources.Load("Towers/TrollIdleLevel1"); _towerSpiderIdle = (GameObject)Resources.Load("Towers/SpiderIdleLevel1"); _check = GameObject.FindObjectOfType<CheckForMusicScript>(); _tileMap = FindObjectOfType<TileMapScript>(); _baseScript = GameObject.FindObjectOfType<BaseScript>(); _calculateEverything(); //Check if there is audio source and get all the sources if (_check.Check == true) { _troll1 = GameObject.Find("Troll1").GetComponent<AudioSource>(); _troll2 = GameObject.Find("Troll2").GetComponent<AudioSource>(); _spider1 = GameObject.Find("Spider1").GetComponent<AudioSource>(); _spider2 = GameObject.Find("Spider2").GetComponent<AudioSource>(); _tree1 = GameObject.Find("Tree1").GetComponent<AudioSource>(); _tree2 = GameObject.Find("Tree2").GetComponent<AudioSource>(); } }
public void nPlaceMap(TileMapScript map_data) { // place each tile var map_container = new GameObject("Map"); for (int i = 0; i < map_data.getMapHeight(); ++i) { for (int j = 0; j < map_data.getMapWidth(); ++j) { var tile = map_data.getTile(i, j); var world_pos = new Vector3(i, 0, j); //GameObject new_game_object = null; switch (tile.get_type()) { case Type.OVERWORLD_WALKABLE: { GameObject new_game_object = Instantiate(walkable_tile_prefab, world_pos, Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); } break; case Type.OVERWORLD_NONWALKABLE: { GameObject new_game_object = Instantiate(nonwalkable_tile_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); } break; case Type.ALT_OVERWORLD_WALKABLE: case Type.DUNGEON_PORTAL_BORDER: case Type.ENTRY_PORTAL_BORDER: { GameObject new_game_object = Instantiate(nonwalkable_tile_two_prefab, world_pos, Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); } break; case Type.TOWN: { GameObject new_game_object = Instantiate(town_tile_prefab, world_pos, Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); } break; case Type.TOWN_NPC: { var new_tile = Instantiate(town_tile_prefab, world_pos, Quaternion.identity) as GameObject; new_tile.transform.SetParent(map_container.transform); GameObject new_game_object = Instantiate(npc_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); } break; case Type.ENTRY_PORTAL: { GameObject new_game_object = Instantiate(walkable_tile_prefab, world_pos, Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); GameObject portal = Instantiate(portal_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject; NetworkServer.Spawn(portal); } break; case Type.DUNGEON_PORTAL: { GameObject new_game_object = Instantiate(walkable_tile_prefab, world_pos, Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); var dungeon_portal = Instantiate(dungeon_portal_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject; NetworkServer.Spawn(dungeon_portal); } break; } //if (new_game_object != null) { // new_game_object.transform.SetParent(map_container.transform); //} } } }
public OriginDestination() { map=new TileMapScript(); }
/*The Merchant iterates through the list and follows the direction at the current position in the list.*/ // private int[,] map; //Returns the length of the List "path". I did not call it getPathLength so as not to confuse it with "path length" as in how much he has to walk. public void setMap(TileMapScript aMap) { map = aMap; }
// create an entry that begins at the given time between two key points. return the time the next entry should begin at. private int build_schedule_part(int start_min, KeyPoint from, KeyPoint to, ref ScheduleData schedule_data, string map_id, TileMapScript map_data) { var from_point = map_data.get_key_point(from); var to_point = map_data.get_key_point(to); // get the path between the two points var path = world_generator.get_path(from_point, to_point, map_data.get_raw_data(), false); // make sure that a path exists first (if not there's a bug somewhere. this shouldn't happen because world gen ensures a path exists.) if (path.Count == 0) { Debug.Log(string.Format("Can't make entry in {4} from ({0}, {1}) to ({2},{3})", from_point[0], from_point[1], to_point[0], to_point[1], map_id)); map_data.print_map(); return(-1); } var path_length = path.Count - 1; var MERCHANT_MIN_PER_TILE = 1.0f; // the time to be at the destination is proportional to the length of the path times the merchant's speed // it's set so that it gives the perfect amount of time for the merchant to get there on time int finish_time = start_min + (int)(MERCHANT_MIN_PER_TILE * path_length); schedule_data.insertEntry(create_schedule_entry(start_min, map_id, from_point[0], from_point[1])); schedule_data.insertEntry(create_schedule_entry(finish_time, map_id, to_point[0], to_point[1])); // return the next time to create an entry at, which is WAITING_TIME more than the finish time, because the merchant waits at the spot for WAITING_TIME var WAITING_TIME_IN_MIN = 25; finish_time += WAITING_TIME_IN_MIN; return(finish_time); }
public OriginDestination() { map = new TileMapScript(); }
public void setMap(TileMapScript aMap) { currentOriginDestination.setMap (aMap); }
public void nPlaceMap(TileMapScript map_data) { // place each tile var map_container = new GameObject("Map"); for (int i = 0; i < map_data.getMapHeight(); ++i) { for (int j = 0; j < map_data.getMapWidth(); ++j) { var tile = map_data.getTile(i, j); var world_pos = new Vector3(i, 0, j); //GameObject new_game_object = null; switch (tile.get_type()) { case Type.OVERWORLD_WALKABLE:{ GameObject new_game_object = Instantiate(walkable_tile_prefab, world_pos, Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); } break; case Type.OVERWORLD_NONWALKABLE: { GameObject new_game_object = Instantiate(nonwalkable_tile_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); } break; case Type.ALT_OVERWORLD_WALKABLE: case Type.DUNGEON_PORTAL_BORDER: case Type.ENTRY_PORTAL_BORDER: { GameObject new_game_object = Instantiate(nonwalkable_tile_two_prefab, world_pos, Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); } break; case Type.TOWN: { GameObject new_game_object = Instantiate(town_tile_prefab, world_pos, Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); } break; case Type.TOWN_NPC: { var new_tile = Instantiate(town_tile_prefab, world_pos, Quaternion.identity) as GameObject; new_tile.transform.SetParent(map_container.transform); GameObject new_game_object = Instantiate(npc_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); } break; case Type.ENTRY_PORTAL: { GameObject new_game_object = Instantiate(walkable_tile_prefab, world_pos, Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); GameObject portal = Instantiate(portal_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject; NetworkServer.Spawn(portal); } break; case Type.DUNGEON_PORTAL: { GameObject new_game_object = Instantiate(walkable_tile_prefab, world_pos, Quaternion.identity) as GameObject; NetworkServer.Spawn(new_game_object); var dungeon_portal = Instantiate(dungeon_portal_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject; NetworkServer.Spawn(dungeon_portal); } break; } //if (new_game_object != null) { // new_game_object.transform.SetParent(map_container.transform); //} } } }
private void Awake() { tileMap = GetComponent <TileMapScript>(); }
// create an entry that begins at the given time between two key points. return the time the next entry should begin at. private int build_schedule_part(int start_min, KeyPoint from, KeyPoint to, ref ScheduleData schedule_data, string map_id, TileMapScript map_data) { var from_point = map_data.get_key_point(from); var to_point = map_data.get_key_point(to); // get the path between the two points var path = world_generator.get_path(from_point, to_point, map_data.get_raw_data(), false); // make sure that a path exists first (if not there's a bug somewhere. this shouldn't happen because world gen ensures a path exists.) if (path.Count == 0) { Debug.Log(string.Format("Can't make entry in {4} from ({0}, {1}) to ({2},{3})", from_point[0], from_point[1], to_point[0], to_point[1], map_id)); map_data.print_map(); return -1; } var path_length = path.Count - 1; var MERCHANT_MIN_PER_TILE = 1.0f; // the time to be at the destination is proportional to the length of the path times the merchant's speed // it's set so that it gives the perfect amount of time for the merchant to get there on time int finish_time = start_min + (int) (MERCHANT_MIN_PER_TILE * path_length); schedule_data.insertEntry(create_schedule_entry(start_min, map_id, from_point[0], from_point[1])); schedule_data.insertEntry(create_schedule_entry(finish_time, map_id, to_point[0], to_point[1])); // return the next time to create an entry at, which is WAITING_TIME more than the finish time, because the merchant waits at the spot for WAITING_TIME var WAITING_TIME_IN_MIN = 25; finish_time += WAITING_TIME_IN_MIN; return finish_time; }
// Use this for initialization void Start() { map = transform.root.gameObject.GetComponent<TileMapScript>(); if(!map) { Debug.Log("Error: Trouble retrieving map object from tile"); } favorList = new List<Favor>(); }
private void Awake() { instance = this; }
public void setMap(TileMapScript aMap) { currentOriginDestination.setMap(aMap); }