/// <summary> /// 根据地砖编号转换成坐标 /// </summary> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="doEvent">If set to <c>true</c> do event.</param> /// <param name="duringMove">If set to <c>true</c> during move.</param> public void SetPosition(int x, int y, bool doEvent = true, bool duringMove = false) { tk2dRuntime.TileMap.TileInfo groundTile = GetTileInfo(x, y, 0); //判断禁止通过的碰撞区域 if (groundTile == null || groundTile.stringVal == "obstacle") { return; } if (doEvent) { //记录当前坐标 Messenger.Broadcast <string, Vector2, System.Action <UserData> >(NotifyTypes.UpdateUserDataAreaPos, UserModel.CurrentUserData.CurrentAreaSceneName, new Vector2(x, y), null); Invoke("doEventDelay", duringMove ? 0.24f : 0); } _x = x; _y = y; Vector3 position = Map.GetTilePosition(_x, _y); float rx = Map.partitionSizeX * 0.005f; if (duringMove) { transform.DOMove(new Vector3(position.x + rx, position.y, position.z), 0.3f); } else { transform.position = new Vector3(position.x + rx, position.y, position.z); } // Map.ColorChannel.SetColor(_x, _y, new Color(1, 1, 1, 0)); // Map.Build(tk2dTileMap.BuildFlags.Default); }
public tk2dRuntime.TileMap.TileInfo[] GetOrCreateTileInfo(int numTiles) { #if UNITY_EDITOR || !UNITY_FLASH bool needInit = false; if (tileInfo == null) { tileInfo = new tk2dRuntime.TileMap.TileInfo[numTiles]; needInit = true; } else if (tileInfo.Length != numTiles) { System.Array.Resize(ref tileInfo, numTiles); needInit = true; } if (needInit) { for (int i = 0; i < tileInfo.Length; ++i) { if (tileInfo[i] == null) { tileInfo[i] = new tk2dRuntime.TileMap.TileInfo(); } } } #endif return(tileInfo); }
void doEventDelay() { tk2dRuntime.TileMap.TileInfo eventTile = GetTileInfo(_x, _y, 1); if (eventTile != null) { //处理区域图上的事件 if (eventTile.stringVal == "Event") { string id = Application.loadedLevelName + "_" + _x + "_" + _y; Messenger.Broadcast <string>(NotifyTypes.DealSceneEvent, id); } } else { //之前没有触发任何事件则在这里处理随机遇敌 List <RateData> ratesData = Statics.GetMeetEnemyRates(UserModel.CurrentUserData.CurrentAreaSceneName); RateData rateData; for (int i = 0; i < ratesData.Count; i++) { rateData = ratesData[i]; if (rateData.IsTrigger()) { Messenger.Broadcast <string>(NotifyTypes.CreateBattle, rateData.Id); //遇敌 break; } } } }
void doEventDelay() { if (!CanTriggerEvent()) { return; } tk2dRuntime.TileMap.TileInfo eventTile = GetTileInfo(_x, _y, 1); if (eventTile != null) { //处理区域图上的事件 if (eventTile.stringVal == "Event") { string id = Application.loadedLevelName + "_" + _x + "_" + _y; Messenger.Broadcast <string>(NotifyTypes.DealSceneEvent, id); } } else { //之前没有触发任何事件则在这里处理随机遇敌 List <RateData> ratesData = Statics.GetMeetEnemyRates(UserModel.CurrentUserData.CurrentAreaSceneName); RateData rateData; for (int i = 0; i < ratesData.Count; i++) { rateData = ratesData[i]; if (rateData.Rate > 0 && rateData.IsTrigger(250f)) { if (AreaMainPanelCtrl.MakeCostNocturnalClothing()) { Statics.CreatePopMsg(Vector3.zero, "被敌人发现后脱下夜行衣摆脱了对方", Color.yellow, 30); break; } Messenger.Broadcast <string>(NotifyTypes.CreateBattle, rateData.Id); //遇敌 eventTriggerDate = Time.fixedTime; break; } } } }
void Update() { if (isGoal) { if (!isGoalWalkStarted) { isGoalWalkStarted = true; player.animator.Play("Walk"); player.animator.ClipFps = 2f; player.sprite.scale = new Vector3(player.sprite.scale.x * -1f, player.sprite.scale.y, player.sprite.scale.z); } } // Attempt to get ground position if (player.isGrounded) { tempGroundPosition = lastGroundPositionY; lastGroundPositionY = player.transform.position.y; } if (!isFairyPause && player.isAlive && isGameReady) { // Falling death if (playerTransform.position.y < cameraTransform.position.y - camera.ScreenExtents.height / 2f) { player.Die(false, true); } if (player.isAlive) { UpdateScore(); healthTimer -= Time.deltaTime; if (healthTimer < 0) { healthTimer = healthTimerAmount; Damage(1); } // FAIRY INVINCIBILITY COUNTDOWN if (isFairy) { fairyTimer += Time.deltaTime; if (fairyTimer >= fairyTime) { Fairy.instance.transform.DOLocalMove(new Vector2(8f, 18f), 2.5f).SetEase(Ease.Linear).OnComplete(() => { isFairy = false; Destroy(Fairy.instance.gameObject); }); // Fairy.instance.FlyAway (); } } } if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } if (Input.GetKeyDown(KeyCode.R)) { UnityEngine.SceneManagement.SceneManager.LoadScene(0); } RaycastHit2D hit = Physics2D.Raycast(playerTransform.position, Vector2.down, 200f, LayerMask.GetMask("Ground TM")); if (hit) { tileInfo = tilemap.GetTileInfoForTileId(tilemap.GetTileIdAtPosition(hit.point, 1)); if (tileInfo != null) { if (tileInfo.intVal == 1) { isSlope = true; tilemap.GetTileAtPosition(hit.point, out tileX, out tileY); } else { isSlope = false; } } else { isSlope = false; } int tileId = tilemap.GetTileIdAtPosition(hit.point, 1); tileInfo = tilemap.GetTileInfoForTileId(tilemap.GetTileIdAtPosition(hit.point, 1)); } } }
public tk2dRuntime.TileMap.TileInfo[] GetOrCreateTileInfo(int numTiles) { #if UNITY_EDITOR || !UNITY_FLASH bool needInit = false; if (tileInfo == null) { tileInfo = new tk2dRuntime.TileMap.TileInfo[numTiles]; needInit = true; } else if (tileInfo.Length != numTiles) { System.Array.Resize(ref tileInfo, numTiles); needInit = true; } if (needInit) { for (int i = 0; i < tileInfo.Length; ++i) { if (tileInfo[i] == null) tileInfo[i] = new tk2dRuntime.TileMap.TileInfo(); } } #endif return tileInfo; }
//false:不可通过 //true:可通过 public bool checkTile(int x, int y) { if (!(x < 11 && y < 11 && x > -1 && y > -1)) { return(false); } tm = GameObject.Find("TileMap").GetComponent <tk2dTileMap>(); AM = GetComponent <ActionManager>(); int tileID = tm.GetTile(x, y, 1); if (tileID == -1) { return(true); } tk2dRuntime.TileMap.TileInfo tileinfo = tm.GetTileInfoForTileId(tileID); if (tileinfo != null) { if (tileinfo.stringVal == "Wall") { return(false); } //拥有Prefab Vector2 startPosition = new Vector2(x - 0.2f, y); Vector2 Direction = new Vector2(x, y); RaycastHit2D hit = Physics2D.Raycast(startPosition, Direction, 0.4f); //Debug.DrawLine(new Vector3(x - 0.2f, y, 0), new Vector3(x + 0.2f, y, 0), Color.red); if (hit.collider != null) { switch (hit.collider.tag) { case "Talk": AM.talk(hit.collider.gameObject.GetComponent <Talk>()); return(false); case "Key": if (AM.key(hit.collider.gameObject.GetComponent <Key>())) { tm.ClearTile(x, y, 1); } break; case "Door": if (AM.door(hit.collider.gameObject.GetComponent <Door>())) { tm.ClearTile(x, y, 1); } return(false); case "DoorWall": if (AM.doorwall(hit.collider.gameObject.GetComponent <DoorWall>())) { tm.ClearTile(x, y, 1); } return(false); case "Baoshi": if (AM.baoshi(hit.collider.gameObject.GetComponent <Baoshi>())) { tm.ClearTile(x, y, 1); } break; case "Pingzi": if (AM.pingzi(hit.collider.gameObject.GetComponent <Pingzi>())) { tm.ClearTile(x, y, 1); } break; case "Yaoshui": if (AM.yaoshui(hit.collider.gameObject.GetComponent <Yaoshui>())) { tm.ClearTile(x, y, 1); } break; case "Zhuangbei": if (AM.zhuangbei(hit.collider.gameObject.GetComponent <Zhuangbei>())) { tm.ClearTile(x, y, 1); } break; case "Enemy": if (AM.enemy(hit.collider.gameObject.GetComponent <Enemy>())) { tm.ClearTile(x, y, 1); } return(false); case "StairUp": AM.stair(hit.collider.gameObject.GetComponent <Stair>()); break; case "StairDown": AM.stair(hit.collider.gameObject.GetComponent <Stair>()); break; case "Tool": if (AM.mttool(hit.collider.gameObject.GetComponent <mtTool>())) { tm.ClearTile(x, y, 1); } break; } return(true); } else { return(true); } } else { return(false); } }