public override void Execute() { parentMenu.gameObject.SetActive(false); Debug.Log("Move! - " + combatant); BattleOrder order = new BattleOrder(); order.Action = "move"; order.SourceCombatant = combatant; MapManager map = GameObject.FindGameObjectWithTag("Map").GetComponent <MapManager>(); //List<Tile> tiles = map.GetTilesInRange(combatant.Tile, combatant.Stats.Movement, false); List <Tile> tiles = map.GetTilesInRangeThreadsafe(combatant.Tile.TileData, combatant.Stats.Movement).ConvertAll(t => t.Tile); tiles = TileUtility.FilterOutOccupiedTiles(tiles); // TODO also maybe cache tilepicker results GameObject objToSpawn = new GameObject("Tile Picker - Move"); objToSpawn.AddComponent <TilePicker>(); TilePicker tilePicker = objToSpawn.GetComponent <TilePicker>(); tilePicker.SetTileParamsMove(combatant); //tilePicker.SetTiles(tiles); tilePicker.battleStateTracker.previous = this.parentMenu.battleStateTracker; tilePicker.SetBattleOrder(order); parentMenu.CleanUp(); }
public void CreatePreset_CreateDefaultTile_HasPresetTileProperties() { Tile presetTile = TileUtility.DefaultTile(m_Sprite) as Tile; Assert.IsNotNull(presetTile); presetTile.color = Color.red; var preset = new Preset(presetTile); var defaultPreset = new DefaultPreset(String.Empty, preset); var presetType = preset.GetPresetType(); AssetDatabase.CreateAsset(preset, kPresetAssetPath); Preset.SetDefaultPresetsForType(presetType, new[] { defaultPreset }); m_Tile = TileUtility.CreateDefaultTile(); var tile = m_Tile as Tile; Assert.AreEqual(typeof(Tile), m_Tile.GetType()); Assert.IsNotNull(tile); Assert.AreEqual(m_Sprite, tile.sprite); Assert.NotNull(tile.sprite); Assert.AreEqual(Color.red, tile.color); Assert.AreNotEqual(Color.white, tile.color); Object.DestroyImmediate(presetTile); Preset.SetDefaultPresetsForType(presetType, null); }
void InitLevel(string[] rows) { GameFieldModel fieldModel = new GameFieldModel(rows); PlayerModel playerModel = new PlayerModel(new FieldBounds(fieldModel.Width, fieldModel.Height), TileUtility.GetTiles(TileType.Body, fieldModel.Tiles)); GameFieldView fieldView = gameField.GetComponent <GameFieldView> (); Player playerView = player.GetComponent <Player> (); PlayerController playerController = new PlayerController(playerModel, playerView); GameFieldController gameFieldController = new GameFieldController(fieldModel, fieldView); LevelModel levelModel = new LevelModel(); LevelView levelView = GetComponent <LevelView> (); StepTimer tickTimer = GetComponent <StepTimer> (); StepTimerController timerController = new StepTimerController(levelModel, playerView, tickTimer); StatusPanelView statusView = statusPanel.GetComponent <StatusPanelView> (); StatusPanelController statusPanelController = new StatusPanelController(levelModel, statusView); SpawnController spawnController = new SpawnController(fieldModel, playerModel); LevelController levelController = new LevelController(playerModel, fieldModel, levelModel, levelView, tickTimer); }
public bool Move(Vector3Int origin, Vector3Int movementInt) { Vector3Int examinePos = origin + movementInt; bool bloodOnPath = false; while (true) { TileBase tile = tilemap.GetTile(examinePos); if (tile == null || (bloodOnPath && TileUtility.IsHole(tile))) { break; } if (!TileUtility.IsBlood(tile)) { return(false); } else { bloodOnPath = true; } examinePos += movementInt; } PushObjectsOnPath(origin, movementInt, examinePos); return(true); }
Tile SpawnPointsTile() { List <Tile> possibleTiles = TileUtility.GetTiles(TileType.Empty, fieldModel.Tiles); Tile tile = possibleTiles [Random.Range(0, possibleTiles.Count)]; return(new Tile(tile.x, tile.y, TileType.Points)); }
// Update is called once per frame void Update() { if (player == null) { player = GameObject.FindGameObjectWithTag("Player"); boss = GameObject.FindGameObjectWithTag("boss"); fighters = GameObject.FindGameObjectsWithTag("fighter"); servants = GameObject.FindGameObjectsWithTag("servant"); tileUtility = new TileUtility(); winRoom = new Vector2Int(-2, 1); } var playerRoom = CalcRoom(player.transform.position); bool alert = false; var attachTo = player.GetComponent <PlayerController>().attatchTo; foreach (var servant in servants) { if (servant == null || servant == attachTo) { continue; } if (CalcRoom(servant.transform.position) != null && CalcRoom(servant.transform.position) == playerRoom) { alert = true; //musicController.alert(); break; } } foreach (var fighter in fighters) { if (fighter == null || fighter == attachTo) { continue; } if (CalcRoom(fighter.transform.position) != null && CalcRoom(fighter.transform.position) == playerRoom) { Lose(); } } if (boss == null && playerRoom == winRoom) { Win(); } if (alertSecond > 0) { alertSecond -= Time.deltaTime; if (alertSecond < 0) { unAlert(); } } if (alert == true) { alertFighter(playerRoom); } }
public void CreateDefaultTileWithSprite_HasDefaultTileProperties() { m_Tile = TileUtility.DefaultTile(m_Sprite); var tile = m_Tile as Tile; Assert.AreEqual(typeof(Tile), m_Tile.GetType()); Assert.IsNotNull(tile); Assert.AreEqual(m_Sprite, tile.sprite); Assert.AreEqual(Color.white, tile.color); }
// Use this for initialization void Start() { player = GameObject.FindWithTag("Player"); //playerPos = player.transform.position; tileUtility = new TileUtility(); storyImg = this.GetComponent <Image>(); //故事点1 storyPosList.Add(new Vector3Int(6, -6, 0)); //故事点2 storyPosList.Add(new Vector3Int(6, -4, 0)); }
static public List <TileData> Find(TileMap tileMap, TileData sourceTile, TileData destinationTile, int moveThroughMask) { List <TileData> shortestPath = new List <TileData>(); List <TileData> unvisited = new List <TileData>(tileMap.TileDataList); FindShorestPathDTO dto = new FindShorestPathDTO(); dto.Destination = destinationTile; dto.MoveThroughMask = moveThroughMask; if (moveThroughMask != TeamId.MOVE_THROUGH_ALL) { unvisited = TileUtility.FilterOutOccupiedTiles(unvisited, moveThroughMask); // TODO support enemyteam unvisited.Add(sourceTile); } dto.TileToDistance.Add(sourceTile, 0); TileData currentTile = null; int count = 0; while (unvisited.Count > 0 && count < 100) { count++; currentTile = TileWithMinDistance(dto.TileToDistance, unvisited); unvisited.Remove(currentTile); CalculateDistanceAndUpdatePath(currentTile, tileMap.TopNeighbor(currentTile), dto); CalculateDistanceAndUpdatePath(currentTile, tileMap.BottomNeighbor(currentTile), dto); CalculateDistanceAndUpdatePath(currentTile, tileMap.LeftNeighbor(currentTile), dto); CalculateDistanceAndUpdatePath(currentTile, tileMap.RightNeighbor(currentTile), dto); } Debug.Log("starting return path - " + count); TileData returnTile = destinationTile; shortestPath.Add(returnTile); count = 0; while (returnTile != sourceTile && count < 100) { count++; Debug.Log("finding last hop for " + returnTile.ToString()); try { returnTile = dto.TileToOptimalPrevious[returnTile]; } catch (Exception ex) { Debug.LogError(ex); Debug.LogError("oh shit error couldn't find " + returnTile.ToString()); } Debug.Log("found " + returnTile); shortestPath.Add(returnTile); } Debug.Log("finish return path - TILEDATA"); shortestPath.Reverse(); return(shortestPath); }
void Start() { //tilemap = GetComponent<Tilemap>(); shadeTilemap = GameObject.FindGameObjectWithTag("shadeTile").GetComponent <Tilemap>(); tileUtility = new TileUtility(); player = GameObject.FindGameObjectWithTag("Player");//.GetComponent<PlayerCountroller>(); playerController = player.GetComponent <PlayerController>(); playerTransform = player.transform; //测试 //changeToReplaceTile(tilemap, player.GetComponent<PlayerCountroller>().getPlayerPosInTilemap(), replaceTiles[0]); }
void Update() { anim.ResetTrigger("Moved"); anim.ResetTrigger("Spiked"); Vector3 movement = Vector3.zero; if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) { movement = Vector3.up; } else if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)) { movement = Vector3.right; } else if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) { movement = Vector3.down; } else if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)) { movement = Vector3.left; } if (movement == Vector3.zero) { return; } Vector3Int originCellPos = tilemap.WorldToCell(transform.position); Vector3Int movementInt = Vector3Int.RoundToInt(movement); TileBase destinationTile = tilemap.GetTile(originCellPos + movementInt); anim.SetInteger("Horizontal", movementInt.x); anim.SetInteger("Vertical", movementInt.y); if (gameController.Move(originCellPos, movementInt)) { anim.SetTrigger("Moved"); moveEvent.Invoke(); transform.position += Vector3.Scale(tilemap.cellSize, movement); Bleed(originCellPos, movementInt); } else if (canSpike && TileUtility.CheckIfSpiked(destinationTile, movementInt)) { anim.SetTrigger("Spiked"); hurtEvent.Invoke(); HitSpike(movementInt); gameController.ApplyBloodToSpike(Vector3Int.RoundToInt(originCellPos + movementInt)); } }
// Use this for initialization void Start() { alertSecond = 0f; mapConfig = GameObject.FindObjectOfType <AutoGenerateMap>().config; pathFinder = new PathFinder(mapConfig); pathFinder.init(); player = GameObject.FindGameObjectWithTag("Player"); boss = GameObject.FindGameObjectWithTag("boss"); fighters = GameObject.FindGameObjectsWithTag("fighter"); servants = GameObject.FindGameObjectsWithTag("servant"); tileUtility = new TileUtility(); winRoom = new Vector2Int(-2, 1); }
/// <summary> /// When input is received, check that the player is free and used an action button /// If so, attempt open the shop if it exists /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e) { //context and button check if (!Context.CanPlayerMove) { return; } //Resets the boolean I use to check if a menu used to move the player around came from my mod //and lets me return them to their original location SourceLocation = null; _playerPos = Vector2.Zero; //checks if i've changed marnie's stock already after opening her menu _changedMarnieStock = false; if (Constants.TargetPlatform == GamePlatform.Android) { if (e.Button != SButton.MouseLeft) { return; } if (e.Cursor.GrabTile != e.Cursor.Tile) { return; } if (VerboseLogging) { monitor.Log("Input detected!"); } } else if (!e.Button.IsActionButton()) { return; } Vector2 clickedTile = Helper.Input.GetCursorPosition().GrabTile; //check if there is a tile property on Buildings layer IPropertyCollection tileProperty = TileUtility.GetTileProperty(Game1.currentLocation, "Buildings", clickedTile); if (tileProperty == null) { return; } //if there is a tile property, attempt to open shop if it exists CheckForShopToOpen(tileProperty, e); }
static public List <Tile> Find(TileMap tileMap, Tile sourceTile, Tile destinationTile, bool moveThroughOccupied) { List <Tile> shortestPath = new List <Tile>(); Dictionary <Tile, int> tileToDistance = new Dictionary <Tile, int>(); Dictionary <Tile, Tile> tileToOptimalPrevious = new Dictionary <Tile, Tile>(); List <Tile> unvisited = new List <Tile>(tileMap.GetTiles()); if (!moveThroughOccupied) { unvisited = TileUtility.FilterOutOccupiedTiles(unvisited); unvisited.Add(sourceTile); } tileToDistance.Add(sourceTile, 0); Tile currentTile = null; int count = 0; while (unvisited.Count > 0 && count < 100) { count++; currentTile = TileWithMinDistance(tileToDistance, unvisited); unvisited.Remove(currentTile); CalculateDistanceAndUpdatePath(currentTile, tileMap.TopNeighbor(currentTile), tileToDistance, tileToOptimalPrevious, moveThroughOccupied); CalculateDistanceAndUpdatePath(currentTile, tileMap.BottomNeighbor(currentTile), tileToDistance, tileToOptimalPrevious, moveThroughOccupied); CalculateDistanceAndUpdatePath(currentTile, tileMap.LeftNeighbor(currentTile), tileToDistance, tileToOptimalPrevious, moveThroughOccupied); CalculateDistanceAndUpdatePath(currentTile, tileMap.RightNeighbor(currentTile), tileToDistance, tileToOptimalPrevious, moveThroughOccupied); } Debug.Log("starting return path - " + count); Tile returnTile = destinationTile; shortestPath.Add(returnTile); count = 0; while (returnTile != sourceTile && count < 100) { count++; Debug.Log("finding last hop for " + returnTile.TileData); returnTile = tileToOptimalPrevious[returnTile]; Debug.Log("found " + returnTile.LocationString()); shortestPath.Add(returnTile); } Debug.Log("finish return path"); shortestPath.Reverse(); return(shortestPath); }
// Use this for initialization void Start() { int mapSizeRow = 17; int mapSizeColumn = 17; int startX = -8; int startY = 8; int roomNum = 16; config = new MapConfig(mapRow, mapColumn); tileUtility = new TileUtility(); tilemaps = GameObject.Find("Tilemap"); wallTilemap = GameObject.FindWithTag("wallTile").GetComponent <Tilemap>(); lobbyTilemap = GameObject.FindWithTag("lobbyTile").GetComponent <Tilemap>(); musicController = GameObject.Find("AudioController").GetComponent <AudioFX>(); autoGenerate(); }
public void SetCombatant(Combatant combatant) { this.combatant = combatant; sourceTile = combatant.Tile; MapManager map = GameObject.FindGameObjectWithTag("Map").GetComponent <MapManager>(); List <Tile> tiles = map.GetTilesInRange(combatant.Tile, 3, false); tiles = TileUtility.FilterOutOccupiedTiles(tiles); GameObject objToSpawn; objToSpawn = new GameObject("Tile Picker"); objToSpawn.AddComponent <TilePicker>(); tilePicker = objToSpawn.GetComponent <TilePicker>(); tilePicker.SetTiles(tiles); }
IEnumerator AddLevelFeatures_Routine() { int specialTilesCount = Random.Range(minSpecialTiles, maxSpecialTiles + 1); Vector2Int coords = Vector2Int.zero; Vector2Int[] neighbors; Tile tile; bool resetCoords = true; for (int index = 0; index < specialTilesCount; index++) { if (resetCoords) { coords = new Vector2Int(Random.Range(0, levelSize.x), Random.Range(0, levelSize.y)); } tiles[coords.x, coords.y].SetTile(presets.tiles[0].GetSprite(Vector2Int.zero), specialTileType); neighbors = TileUtility.SurroundingCoords(coords, levelSize); Vector2Int dir; for (int i = 0; i < neighbors.Length; i++) { tile = tiles[neighbors[i].x, neighbors[i].y]; if (Random.Range(0, 1f) < specialTileSpread && tile.type != specialTileType) { dir = neighbors[i] - coords; dir = new Vector2Int(dir.x, dir.y * -1); tile.SetTile(presets.tiles[0].GetSprite(dir), specialTileType); } } resetCoords = Random.Range(0, 1f) < specialTileLoop; if (!resetCoords) { index--; coords = neighbors[Random.Range(0, neighbors.Length)]; } yield return(new WaitForEndOfFrame()); } }
void PushObjectsOnPath(Vector3Int origin, Vector3Int movementInt, Vector3Int destination) { Vector3Int examinePos = destination; TileBase destinationTile = tilemap.GetTile(examinePos); if (destinationTile != null && TileUtility.IsHole(destinationTile)) { examinePos -= movementInt; TileBase lastPushedTile = tilemap.GetTile(examinePos); if (lastPushedTile != null && TileUtility.IsBlood(lastPushedTile)) { tilemap.SetTile(examinePos, null); tilemap.SetTile(destination, holeWithBlood); tileSwapper.removeSwap(destination); tileSwapper.addTileSwap(holeTile, Time.time + tileAnimationTime, destination); payEvent.Invoke(); DecrementCounter(destination); } } tileSwapper.removeSwap(examinePos); Vector3Int from = examinePos - movementInt; while (from != origin) { tilemap.SetTile(examinePos, tilemap.GetTile(from)); tileSwapper.moveSwap(from, examinePos); examinePos -= movementInt; from -= movementInt; } tilemap.SetTile(origin + movementInt, null); }
public static Tile[][] Parse(string[] rows) { int maxRowLength = rows.Max().Length; int rowsAmount = rows.Length; string[] normalizedRows = new string[rowsAmount]; for (int i = 0; i < rowsAmount; i++) { normalizedRows [i] = rows [i].PadRight(maxRowLength, TileKey.Block); } Tile[][] result = new Tile[rowsAmount] []; for (int x = 0; x < rowsAmount; x++) { result [x] = new Tile[maxRowLength]; for (int y = 0; y < maxRowLength; y++) { result [x] [y] = new Tile(x, y, TileUtility.GetType(normalizedRows[x][y])); } } return(result); }
public void Initialize(Pacman pacman, TileUtility tileUtility) { this.pacman = pacman; this.tileUtility = tileUtility; }
/// <summary> /// Checks the tile property for shops, and open them /// </summary> /// <param name="tileProperty"></param> /// <param name="e"></param> private void CheckForShopToOpen(IPropertyCollection tileProperty, StardewModdingAPI.Events.ButtonPressedEventArgs e) { //check if there is a Shop property on clicked tile tileProperty.TryGetValue("Shop", out PropertyValue shopProperty); if (VerboseLogging) { monitor.Log($"Shop Property value is: {shopProperty}"); } if (shopProperty != null) //There was a `Shop` property so attempt to open shop { //check if the property is for a vanilla shop, and gets the shopmenu for that shop if it exists IClickableMenu menu = TileUtility.CheckVanillaShop(shopProperty, out bool warpingShop); if (menu != null) { if (warpingShop) { SourceLocation = Game1.currentLocation; _playerPos = Game1.player.position.Get(); } //stop the click action from going through after the menu has been opened helper.Input.Suppress(e.Button); Game1.activeClickableMenu = menu; } else //no vanilla shop found { //Extract the tile property value string shopName = shopProperty.ToString(); if (ShopManager.ItemShops.ContainsKey(shopName)) { //stop the click action from going through after the menu has been opened helper.Input.Suppress(e.Button); ShopManager.ItemShops[shopName].DisplayShop(); } else { Monitor.Log($"A Shop tile was clicked, but a shop by the name \"{shopName}\" " + $"was not found.", LogLevel.Debug); } } } else //no shop property found { tileProperty.TryGetValue("AnimalShop", out shopProperty); //see if there's an AnimalShop property if (shopProperty != null) //no animal shop found { string shopName = shopProperty.ToString(); if (ShopManager.AnimalShops.ContainsKey(shopName)) { //stop the click action from going through after the menu has been opened helper.Input.Suppress(e.Button); ShopManager.AnimalShops[shopName].DisplayShop(); } else { Monitor.Log($"An Animal Shop tile was clicked, but a shop by the name \"{shopName}\" " + $"was not found.", LogLevel.Debug); } } } //end shopProperty null check }
public void CreateDefaultTile_IsATile() { m_Tile = TileUtility.CreateDefaultTile(); Assert.AreEqual(typeof(Tile), m_Tile.GetType()); }
public void Initialize(Pacman pacman, TileUtility tileUtility, Akabei akabei) { this.akabei = akabei; base.Initialize(pacman, tileUtility); }
private void FindTilesInRange() { this.TileResults = map.GetTilesInRangeThreadsafe(combatant.Tile.TileData, combatant.Stats.Movement); this.TileResults = TileUtility.FilterOutOccupiedTiles(this.TileResults); this.isDone = true; }