} // end Update function // Attempts to pick up a resource for the character. public void PickupResource(Resource resource, int amount) { // Check if picking up this resource will put the character overweight. if ((ResourceWeight + resource.WeightValue) * amount <= MaxWeight) { // Check if there is enough room for this resource. if (m_resourceList.TotalSize + resource.SizeValue <= MaxInventory) { // Add the resource. m_resourceList.AddResource(resource, amount); // Get the resource's position. Vector3 tmp = transform.localPosition; // Change the z to make tiles work. tmp.z = -0.01f; TileDictionary.RemoveResource(TileManager.ToPixels(tmp)); } // end if size else { print("Pickup failed. Max inventory capacity reached."); } // end else size } // end if weight else { print("Pickup failed. Max inventory weight reached."); } // end else weight } // end PickupResource function
private void RemoveNegativeTileTextureId(Point tile) { if (TileDictionary[tile].TextureId == -1) { TileDictionary.Remove(tile); } }
public MapLoader() // initializes the variables { toBuild = new List <HexCell>(); toSize = new List <HexCell>(); toType = new List <HexCell>(); dictionary = new TileDictionary(); }
/// <summary> /// Fills tiles with given textureid /// </summary> /// <param name="tile"></param> /// <param name="targetTexture"></param> /// <param name="replacementTexture"></param> public void FillTiles(Point tile, int targetTexture) { if (!_gridHandler.IsTileInsideGrid(tile)) { return; } if (!TileDictionary.ContainsKey(tile)) { AddTile(tile, -1); } if (targetTexture == SelectedTileTextureId) { RemoveNegativeTileTextureId(tile); return; } if (TileDictionary[tile].TextureId != targetTexture) { RemoveNegativeTileTextureId(tile); return; } TileDictionary[tile].TextureId = SelectedTileTextureId; FillTiles(new Point(tile.X + 1, tile.Y), targetTexture); FillTiles(new Point(tile.X, tile.Y + 1), targetTexture); FillTiles(new Point(tile.X - 1, tile.Y), targetTexture); FillTiles(new Point(tile.X, tile.Y - 1), targetTexture); }
private void OnEnable() { archi = (Archi)target; lineMaterial = Resources.Load <Material>("Materials/Line"); grid = archi.grid; gridHash = GridUtility.GenerateHash(grid, Color.white); _rootElement = new VisualElement(); _visualTree = Resources.Load <VisualTreeAsset>("UXML/MainWindow"); materialPreviews = new List <GUIContent>(archi.materials.Count); tilePreviews = new List <GUIContent>(archi.Tiles.Count); archi.tools = new Tools.Tool[] { new Brush(Resources.Load <Texture2D>("Icons/brush")), new Rectangle(Resources.Load <Texture2D>("Icons/rectangle")), new FilledRectangle(Resources.Load <Texture2D>("Icons/filledrect")), }; //print(archi.tools.Length); toolPreviews = new List <GUIContent>(); for (int i = 0; i < archi.tools.Length; i++) { toolPreviews.Add(new GUIContent(archi.tools[i].icon, archi.tools[i].GetType().ToString())); } UpdateMaterialPreviews(); UpdateTilePreviews(); selectedTile = archi.selectedTile; tiles = archi.tiles; MouseCellWorldPos = Vector3.zero; }
/// <summary> /// Add borders to neighbouring tiles if in the same group /// </summary> /// <param name="tile"></param> private void AddBorders(Point tile, int groupId) { if (BorderControlled.Contains(tile)) { return; } if (!_gridHandler.IsTileInsideGrid(tile)) { return; } if (!TileDictionary.ContainsKey(tile)) { return; } if (!TilePropertyDictionary.ContainsKey(GetTile(tile).TextureId)) { return; } if (GetTileProperty(GetTile(tile).TextureId).GroupId != groupId) { return; } if (GetTileProperty(GetTile(tile).TextureId).GroupId == -1 || groupId == -1) { return; } Point TileTop = new Point(tile.X, tile.Y - 1); Point TileBottom = new Point(tile.X, tile.Y + 1); Point TileLeft = new Point(tile.X - 1, tile.Y); Point TileRight = new Point(tile.X + 1, tile.Y); int groupPosition = CalculateGroupPosition( GetTileGroup(TileTop) == groupId ? true : false, GetTileGroup(TileBottom) == groupId ? true : false, GetTileGroup(TileLeft) == groupId ? true : false, GetTileGroup(TileRight) == groupId ? true : false ); if (groupPosition == -1) { return; } int newTextureId = FindTilePropertyWithGroupPosition(groupId, groupPosition); if (newTextureId == -1) { return; } TileDictionary[tile].TextureId = newTextureId; BorderControlled.Add(tile); // Recursion ?! AddBorders(TileTop, groupId); AddBorders(TileBottom, groupId); AddBorders(TileLeft, groupId); AddBorders(TileRight, groupId); }
/// <summary> /// Returns the tile at given point /// </summary> /// <param name="tile"></param> /// <returns></returns> public Tile GetTile(Point position) { if (!TileDictionary.ContainsKey(position)) { return(null); } return(TileDictionary[position]); }
/// <summary> /// 构建当前缩放层级的瓦片 /// </summary> /// <param name="bound"></param> /// <param name="zoom"></param> void Build(GBound bound, int zoom) { int _tileSize = Projection.TileSize; //构建裁剪边界的矩形,用于整体裁剪 IGeometry _boundGeometry = bound.ToInsertPolygon(); //瓦片多尺度缓存 if (TileDictionary.ContainsKey(zoom)) { TileDictionary[zoom].Clear(); } else { TileDictionary[zoom] = new List <GTileElement>(); } //1.获取坐上右下坐标 Coordinate p0 = bound.Min; Coordinate p1 = bound.Max; //2.分尺度计算格网位置 //2.1 转换成尺度下的pixel Coordinate min = Projection.LatlngToPoint(p0, zoom); Coordinate max = Projection.LatlngToPoint(p1, zoom); //2.2 计算pixel下边界范围 GBound pixelBound = new GBound(new List <Coordinate>() { min, max }); //2.3 通过pixelbound计算range GBound range = new GBound(new List <Coordinate>() { new Coordinate((int)Math.Floor(pixelBound.Min.X / _tileSize), (int)Math.Floor(pixelBound.Min.Y / _tileSize)), new Coordinate((int)Math.Ceiling(pixelBound.Max.X / _tileSize) - 1, (int)Math.Ceiling(pixelBound.Max.Y / _tileSize) - 1), }); //2.3统计区域内瓦片的编号,边界经纬度等信息 for (int j = Convert.ToInt32(range.Min.Y); j <= Convert.ToInt32(range.Max.Y); j++) { for (int i = Convert.ToInt32(range.Min.X); i <= Convert.ToInt32(range.Max.X); i++) { //反算每块瓦片的边界经纬度 List <Coordinate> coordinates = new List <Coordinate>(); coordinates.Add(Projection.PointToLatLng(new Coordinate(i * 256, j * 256), zoom)); coordinates.Add(Projection.PointToLatLng(new Coordinate(i * 256 + 256, j * 256 + 256), zoom)); // GTileElement tile = new GTileElement() { X = i, Y = j, Z = zoom, Bound = new GBound(coordinates) }; TileDictionary[zoom].Add(tile); } } }
public void ResetMap() { TileDictionary = new TileDictionary(); for (var x = 0; x < BoardWidth; x++) { for (var y = 0; y < BoardHeight; y++) { TileDictionary.Add(new Coordinate(x, y), new Tile()); } } }
public Ship(Coordinate[] location, string name) { Name = name; Location = location; Hull = new TileDictionary(); foreach (var coord in location) { Hull.Add(coord, new Tile { OnHit = WhenHit, Status = TileStatus.Ship }); } }
/// <summary> /// Removes tile at given position /// </summary> /// <param name="position"></param> public void RemoveTile(Point position) { if (position == new Point(-1, -1)) { return; } if (TileDictionary.ContainsKey(position)) { TileDictionary.Remove(position); return; } }
//takes a string (our tiles) and the x,y position it needs to be placed with the camera's position as reference to place 1 tile. //placeTile is used in generateMap() private void placeTile(string tileType, int x, int y, Vector3 camPos) { int tileIndex = int.Parse(tileType); TileManager nextTile = Instantiate(tiles[tileIndex]).GetComponent <TileManager>(); TileDictionary.Add(new Point(x, y), nextTile); nextTile.Setup(new Point(x, y), new Vector3(camPos.x + (tileSize * x), camPos.y - (tileSize * y), 0), map); if (tileType == "0") { nextTile.ableToWalk = false; } if (tileType == "1") { nextTile.IsEmpty = false; } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var dict = new TileDictionary(); var cr = new Coordinate(); var started = true; while (reader.Read()) { switch (reader.TokenType) { default: break; case JsonToken.StartObject: started = true; break; case JsonToken.EndObject: if (!started) { return(dict); } started = false; break; case JsonToken.PropertyName: var readerValue = reader.Value.ToString().Split(','); if (readerValue.Length == 2) { cr = new Coordinate(int.Parse(readerValue[0]), int.Parse(readerValue[1])); } break; case JsonToken.Integer: dict.Add(cr, new Tile { Status = (TileStatus)Enum.Parse(typeof(TileStatus), reader.Value.ToString()) }); break; } } return(dict); }
void Awake() { if (tiles == null) { tiles = new TileDictionary(); } if (materials == null) { materials = new List <Material>(); } if (Tiles == null) { Tiles = new List <GameObject>(); } if (grid == null) { grid = GetComponent <Grid>(); } }
public void CreateNewGrid() { container = new GameObject(stageName).transform; editorPositions = new List <EditorGridPosition>(); tileDictionary = new TileDictionary(); Vector3 placePosition = centerStartPos ? new Vector3(-(startWidth * scaledWidth) * .5f + scaledWidth * .5f, 0, 0) : startPosition; for (int i = 0; i < startWidth; i++) { for (int j = 0; j < startLength; j++) { float isoX = (i * scaledWidth * .5f) + (j * scaledWidth * .5f); float isoY = (j * scaledHeight * .5f) - (i * scaledHeight * .5f); float depth = i - j; Vector3 worldPosition = placePosition + new Vector3(isoX, isoY, -depth); GridPosition gridPosition = new GridPosition(i, j); editorPositions.Add(new EditorGridPosition(gridPosition, worldPosition, 0)); } } }
/// <summary> /// Add tile with textureid /// </summary> /// <param name="position"></param> /// <param name="textureId"></param> public void AddTile(Point position, int textureId) { if (position == new Point(-1, -1)) { return; } int tilePropertyId = (textureId == -1) ? SelectedTileTextureId : textureId; if (!TilePropertyDictionary.ContainsKey(tilePropertyId)) { CreateTileProperty(tilePropertyId); } if (TileDictionary.ContainsKey(position)) { TileDictionary[position].TextureId = textureId; StartAddBorders(position, TilePropertyDictionary[tilePropertyId].GroupId); return; } TileDictionary[position] = new Tile(position, textureId); StartAddBorders(position, TilePropertyDictionary[tilePropertyId].GroupId); }
//================================================================================================= //-----------------------------------Functions----------------------------------------------------- //================================================================================================= void Start() //------------------------------------------------------------------ // Start() runs when the object if first instantiated // -Because this object will occur once through the game, // these values are the beginning of game values // -Values should be updated at EndTurn State of StateMachine() //------------------------------------------------------------------- { // Clear the dictionary TileDictionary.Clean(); // Set the dimensions and generate/add the tiles TileManager.SetDimensions(64, 20, 16); TileManager.GenerateAndAddTiles(); #region End Scene Initialisation stuff // Create the empty game object. m_endSceneCharData = new GameObject("EndSceneCharData"); // Tag it as end scene char data. m_endSceneCharData.tag = "EndSceneCharDataTag"; // Add the end scene char data component. m_endSceneCharData.AddComponent <EndSceneData>(); // Set it to not destroy on load. DontDestroyOnLoad(m_endSceneCharData); // Defaults to true. m_runEndStuff = true; #endregion //#region Menu Data Initialisation Stuff // Get the game object with the menu data tag. GameObject menuData = GameObject.FindGameObjectWithTag("MenuDataTag"); // Only proceed of the data object isn't null. if (menuData != null) { // Get its menu data script. MenuData menuDataScript = menuData.GetComponent <MenuData>(); // Copy the value into the state machine. m_GUINumOfPlayers = menuDataScript.NumberPlayers; } // Finally, destroy the menu data object. Destroy(menuData); //#endregion //initialize empty lists m_playerList = new List <GameObject>(); m_playerScriptList = new List <GSP.Char.Character>(); m_PlayerResourceList = new List <GSP.Char.ResourceList>(); //Add Players Instances AddPlayers(m_GUINumOfPlayers); //Beginning State m_gamePlayState = GamePlayState.BEGINTURN; //get scripts needed m_DieScript = GameObject.FindGameObjectWithTag("DieTag").GetComponent <DieInput>(); m_GUIMapEventsScript = GameObject.FindGameObjectWithTag("GUIMapEventSpriteTag").GetComponent <GUIMapEvents>(); m_GUIMovementScript = GameObject.FindGameObjectWithTag("GUIMovementTag").GetComponent <GSP.GUIMovement>(); //m_NEWGUIMapEventScript = GameObject.FindGameObjectWithTag ("GUIMapEventSpriteTag").GetComponent<GSP.JAVIERGUI.NewGUIMapEvent>(); //used during testing m_MapEventScript = GameObject.FindGameObjectWithTag("DieTag").GetComponent <GSP.MapEvent>(); m_GUIBottomBarScript = this.GetComponent <GSP.JAVIERGUI.GUIBottomBar>(); m_DieScript.Dice.Reseed(System.Environment.TickCount); //text for the action button m_GUIActionString = "Action\nButton"; //no map event at start; m_MapEventString = "NOTHING"; m_MapEventResultString = null; //this initializes things after Start() m_initAfterStart = true; //Init audio audioSrc = GameObject.FindGameObjectWithTag("AudioSourceTag"); } //END start()
public virtual void SetUpTile(TileDictionary tileDictionary) { this.tileDictionary = tileDictionary; SetSprite(); }
//Calls map event and returns string public string DetermineEvent(GameObject player) { //Set up player script m_player = player; m_playerCharScript = m_player.GetComponent <Character>(); //Gather tile Vector3 tmp = m_player.transform.localPosition; // Change by Damien to get tiles to work again. tmp.z = -0.01f; // Original: tmp.z = 0.0f; Tile currentTile = TileDictionary.GetTile(TileManager.ToPixels(tmp)); //If no tile found if (currentTile == null) { //return "This is not a valid \ntile. No event occured."; m_GUIResult = "This is not a valid \ntile. No event occured."; return("NOTHING"); } //end if //If no resource at tile else if (currentTile.ResourceType == ResourceType.NONE) { int dieResult = m_die.Roll(1, 100); if (dieResult < m_enemyChance) { return("ENEMY"); } //end if ENEMY else if (dieResult < m_allyChance + m_enemyChance && dieResult >= m_enemyChance) { return("ALLY"); } //end else if ALLY else if (dieResult < m_itemChance + m_allyChance + m_enemyChance && dieResult >= m_allyChance + m_enemyChance) { return("ITEM"); } //end else if ITEM else { //return "Die roll was " + dieResult + ".\nNo map event occured."; m_GUIResult = "No map event occured."; return("NOTHING"); } //end else if NOTHING } //end if NORMAL TILE //If resource at tile else { //Create temp resource Resource temp = new Resource(); // Turn temp into type of resource temp.SetResource(currentTile.ResourceType.ToString()); //Pick up resource m_playerCharScript.PickupResource(temp, 1); //Declare what was landed on m_GUIResult = "You got a resource:\n" + temp.ResourceName; //Play found for what was landed on if (temp.ResourceName == "Fish") { audioSrc.audio.PlayOneShot(GSP.AudioReference.sfxFishing); //Play fish sound } //end if else if (temp.ResourceName == "Wood") { audioSrc.audio.PlayOneShot(GSP.AudioReference.sfxWoodcutting); //Play wood sound } //end else if else if (temp.ResourceName == "Wool") { audioSrc.audio.PlayOneShot(GSP.AudioReference.sfxShearing); //Play wool sound } //end else if else { audioSrc.audio.PlayOneShot(GSP.AudioReference.sfxMining); //Play ore sound } //end else return("RESOURCE"); } //end else if RESOURCE TILE } //end DetermineEvent(GameObject player)
public override void SetUpTile(TileDictionary tileDictionary) { // Debug.Log(gameObject.transform.position); this.tileDictionary = tileDictionary; SetSpriteBasedOnSuroundingTiles(); }
/// <summary> /// Clears the tiles /// </summary> public void Clear() { TileDictionary.Clear(); }
/// <summary> /// Resets and initializes the tile dictionary. /// </summary> public void InitTilesDictionary() { _tiles = new TileDictionary(); }