public static void DrawRange(IBuilding building) { var rect = building.BuildingRect; var lands = GameScene.Instance.Ground.GetBlocks(building.MapRect); foreach (var block in lands) { if (rect.IsInclude(block.MapPosition)) { Gizmos.color = Color.red; } else { Gizmos.color = Color.green; } var range = GroundBlock.MapPositionToRect(block.MapPosition); Gizmos.DrawLine(new Vector3(range.x, 0, range.y), new Vector3(range.xMax, 0, range.yMax)); } Gizmos.color = Color.blue; var centerRange = GroundBlock.MapPositionToRect(building.CenterPosition); Gizmos.DrawLine(new Vector3(centerRange.xMin, 0, centerRange.yMax), new Vector3(centerRange.xMax, 0, centerRange.yMin)); Gizmos.color = Color.yellow; var worldCenterPos = building.WorldCenterPosition; Gizmos.DrawLine(worldCenterPos + Vector3.left, worldCenterPos + Vector3.right); Gizmos.DrawLine(worldCenterPos + Vector3.forward, worldCenterPos + Vector3.back); }
public void Handle(ICollidable player, ICollidable groundBlock, CollisionDirection.DirectionTag direction) { if (typeof(IMario).IsInstanceOfType(player) && typeof(GroundBlock).IsInstanceOfType(groundBlock)) { this.player = (IMario)player; this.groundBlock = (GroundBlock)groundBlock; switch (direction) { case CollisionDirection.DirectionTag.Top: this.player.SetYPosition(this.groundBlock.GetTopSide() - player.GetHeight()); this.player.Ground(); break; case CollisionDirection.DirectionTag.Bottom: this.player.SetYPosition(this.groundBlock.GetBottomSide() + 1); break; case CollisionDirection.DirectionTag.Left: this.player.SetXPosition(this.groundBlock.GetLeftSide() - player.GetWidth()); break; case CollisionDirection.DirectionTag.Right: this.player.SetXPosition(this.groundBlock.GetRightSide() + 1); break; default: Console.WriteLine("Unexpected Direction Received in Collision.PlayerWithBrokenBrickBlock"); break; } } }
public void Handle(ICollidable player, ICollidable groundBlock, CollisionDirection.DirectionTag direction) { if (typeof(IMario).IsInstanceOfType(player) && typeof(GroundBlock).IsInstanceOfType(groundBlock)) { this.player = (IMario)player; this.groundBlock = (GroundBlock)groundBlock; switch (direction) { case CollisionDirection.DirectionTag.Top: this.player.SetYPosition(this.groundBlock.GetTopSide() - player.GetHeight()); this.player.Ground(); break; case CollisionDirection.DirectionTag.Bottom: this.player.SetYPosition(this.groundBlock.GetBottomSide() + 1); break; case CollisionDirection.DirectionTag.Left: this.player.SetXPosition(this.groundBlock.GetLeftSide() - player.GetWidth()); break; case CollisionDirection.DirectionTag.Right: this.player.SetXPosition(this.groundBlock.GetRightSide() + 1); break; default: Console.WriteLine(Config.GetCollisionResolutionException() + GetType().ToString()); break; } } }
public virtual GroundBlock[,] FillPieces(GameObject prefab, bool initialise = false) { GroundBlock[] children = prefab.GetComponentsInChildren <GroundBlock>(); Tuple <float, float>[] positions = children.Select(x => new Tuple <float, float>(x.transform.position.x, x.transform.position.z)).ToArray(); float xmin = positions.Min(x => x.Item1); float xmax = positions.Max(x => x.Item1); float zmin = positions.Min(x => x.Item2); float zmax = positions.Max(x => x.Item2); int width = Mathf.Abs((int)(xmax - xmin) / 10) + 1; int height = Mathf.Abs((int)(zmax - zmin) / 10) + 1; GroundBlock[,] pieces = new GroundBlock[width, height]; foreach (GroundBlock child in children) { int x = Mathf.Abs((int)(child.transform.position.x - xmin) / 10); int y = Mathf.Abs((int)(child.transform.position.z - zmin) / 10); pieces[x, y] = child; if (initialise) { SetClassSpecificFields(child, x, y); } } if (initialise) { Width = width; Height = height; } return(pieces); }
public override void SetClassSpecificFields(GroundBlock block, int x, int y) { if (IndexCenter == null && block.CenterPoint) { IndexCenter = new Tuple <int, int>(x, y); } }
/// <summary> /// 根据现在为止异步计算到目标的路径并更新目标位置栈 /// </summary> /// <returns></returns> private IEnumerator PathFindingAsyn(Vector2Int targetPos) { this.PathStack.Clear(); var currentPos = GroundBlock.WorldPositionToMapPos(this.transform.position); if (currentPos == targetPos) { yield break; } Stack <Vector2Int> posStack = null; while (posStack == null) { var task = new Task(() => AStar.DoAStar(currentPos, targetPos, out posStack)); task.Start(); // 等待直到异步计算结束 while (!task.IsCompleted) { yield return(null); } } if (posStack.Count <= 0) { yield break; } this.PathStack = posStack;// 更新目标位置栈 }
/// <summary> /// 设置地图位置 /// </summary> /// <param name="centerPos">建筑区域左下角的绝对位置</param> /// <param name="height">高度</param> public void SetMapPosition(Vector2Int centerPos, float height) { this.mapRect = new RectInt(centerPos - this.CenterRelativePosition, this.MapRect.size); var pos = GroundBlock.MapPositionToWorldPosition(this.BuildingRect.position, height); this.transform.position = pos; }
public float CalculateDistance(Vector3 position) { var pos = GroundBlock.WorldPositionToMapPos(position); var proximatePos = Ground.GetBuildingProximateMapPos(this, position - this.WorldCenterPosition); //var distance = (proximatePos - pos).magnitude * GroundBlock.UNIT + GroundBlock.UNIT; return(Vector2Int.Distance(pos, proximatePos)); }
private void OnDrawGizmos() { Gizmos.color = Color.yellow; foreach (var block in this.Field) { var range = GroundBlock.MapPositionToRect(block.Value.MapPosition); //Gizmos.DrawLine(new Vector3(range.xMin, 0, range.yMax), new Vector3(range.xMax, 0, range.yMin)); Gizmos.DrawLine(new Vector3(range.xMin, 0, range.yMin), new Vector3(range.xMin, 0, range.yMax)); Gizmos.DrawLine(new Vector3(range.xMin, 0, range.yMax), new Vector3(range.xMax, 0, range.yMax)); Gizmos.DrawLine(new Vector3(range.xMax, 0, range.yMax), new Vector3(range.xMax, 0, range.yMin)); Gizmos.DrawLine(new Vector3(range.xMax, 0, range.yMin), new Vector3(range.xMin, 0, range.yMin)); } }
public override void UpdateState() { if (this.Owner.Anim.GetCurrentAnimatorStateInfo(0).IsName("Hit")) { return; } // 向下一位置移动 var nextWorldPos = GroundBlock.MapPostioinCenterToWorldPosition(this.nextPos, this.Owner.transform.position.y); var direction = (nextWorldPos - this.Owner.transform.position).normalized; this.Owner.transform.Translate(direction * this.Owner.MoveSpeed * Time.deltaTime, Space.World); this.Owner.transform.rotation = Quaternion.Lerp(this.Owner.transform.rotation, Quaternion.LookRotation(direction), this.Owner.RotateSpeed * Time.deltaTime); }
public override void SetClassSpecificFields(GroundBlock block, int x, int y) { if (IndexAnchorStart == null || IndexAnchorEnd == null) { if (block.RoadAnchorStart) { IndexAnchorStart = new Tuple <int, int>(x, y); } if (block.RoadAnchorEnd) { IndexAnchorEnd = new Tuple <int, int>(x, y); } } }
/// <summary> /// 更新预览建筑 并返回是否可以建造 /// </summary> private bool UpdatePreviewBuidling() { if (this.previewBuilding == null) { return(false); } var hit = InputCtrl.MouseGroundPosition; if (hit.transform != null) { this.previewBuilding.SetMapPosition(GroundBlock.WorldPositionToMapPos(hit.point), this.previewBuilding.Transform.position.y); } return(GameScene.Instance.Ground.CheckCanBuild(this.previewBuilding));// 检查是否允许建造 }
public Block BuildBlock(string code) { Block b = new Block(); setIdFromCode(code); setSubIdFromCode(code); switch (id) { case 0: AirBlock airBlock = new AirBlock(subId); b.TexturePath = airBlock.TexturePath; b.IsCollidable = airBlock.IsCollidable; break; case 1: GroundBlock groundBlock = new GroundBlock(subId); b.TexturePath = groundBlock.TexturePath; b.IsCollidable = groundBlock.IsCollidable; break; case 2: GrassBlock grassBlock = new GrassBlock(subId); b.TexturePath = grassBlock.TexturePath; b.IsCollidable = grassBlock.IsCollidable; break; case 3: BridgeBlock bridgeBlock = new BridgeBlock(subId); b.TexturePath = bridgeBlock.TexturePath; b.IsCollidable = bridgeBlock.IsCollidable; break; case 4: DirtBlock dirtBlock = new DirtBlock(subId); b.TexturePath = dirtBlock.TexturePath; b.IsCollidable = dirtBlock.IsCollidable; break; default: AirBlock derivedBlock = new AirBlock(subId); b.TexturePath = derivedBlock.TexturePath; b.IsCollidable = derivedBlock.IsCollidable; break; } return(b); }
private void DetectMarioBlockCollision() { IBlock block = new GroundBlock(new Vector2(0, 0)); float marioLocationX = Level.Mario.MarioPhysics.Position.X; float marioLocationY = Level.Mario.MarioPhysics.Position.Y; int blocksWidth = block.BlockBox.Width; int blocksHeight = block.BlockBox.Height; int blockIndexX = (int)Math.Ceiling(marioLocationX / blocksWidth); int blockIndexY = (int)Math.Ceiling(marioLocationY / blocksHeight); for (int blockIndexOffsetX = Constant.Instance.BlockIndexOffset; blockIndexOffsetX < Constant.Instance.BlockIndexOffsetLimit; blockIndexOffsetX++) { for (int blockIndexOffsetY = Constant.Instance.BlockIndexOffset; blockIndexOffsetY < Constant.Instance.BlockIndexOffsetLimit; blockIndexOffsetY++) { CheckMarioBlockCollision(blockIndexX + blockIndexOffsetX, blockIndexY + blockIndexOffsetY); } } }
/// <summary> /// 获取地图块信息 /// </summary> /// <param name="pos"></param> /// <returns></returns> public GroundBlock GetBlock(Vector2Int pos) { GroundBlock result = null; if (this.Map.TryGetValue(pos, out result)) { return(result); } if (this.Map.ContainsKey(pos)) { return(this.Map[pos]); } result = new GroundBlock(pos); this.Map.Add(pos, result); return(result); }
/// <summary> /// 获取建筑中心向外指定方向的最近格子 /// </summary> /// <param name="building">建筑</param> /// <param name="direction">中心向外发射方向</param> /// <returns></returns> public static Vector2Int GetBuildingProximateMapPos(IBuilding building, Vector3 direction) { direction.y = 0; direction = direction.normalized; var center = building.WorldCenterPosition; var buildingRect = building.BuildingRect; var i = 0; while (true) { var pos = GroundBlock.WorldPositionToMapPos(center + direction * GroundBlock.UNIT * i++); if (!buildingRect.IsInclude(pos)) { return(pos); } } }
private void DetectEnemyBlockCollision() { foreach (IEnemy enemy in Level.EnemyList) { IBlock block = new GroundBlock(new Vector2(0, 0)); float enemyLocationX = enemy.EnemyPhysics.Position.X; float enemyLocationY = enemy.EnemyPhysics.Position.Y; int blocksWidth = block.BlockBox.Width; int blocksHeight = block.BlockBox.Height; int blockIndexX = (int)Math.Ceiling(enemyLocationX / blocksWidth); int blockIndexY = (int)Math.Ceiling(enemyLocationY / blocksHeight); for (int blockIndexOffsetX = Constant.Instance.BlockIndexOffset; blockIndexOffsetX < Constant.Instance.BlockIndexOffsetLimit; blockIndexOffsetX++) { for (int blockIndexOffsetY = Constant.Instance.BlockIndexOffset; blockIndexOffsetY < Constant.Instance.BlockIndexOffsetLimit; blockIndexOffsetY++) { CheckEnemyBlockCollision(blockIndexX + blockIndexOffsetX, blockIndexY + blockIndexOffsetY, enemy); } } } }
private void DetectFireballBlockCollision() { foreach (Fireball fireball in Level.FireballList) { IBlock block = new GroundBlock(new Vector2(0, 0)); float fireballLocationX = fireball.FireballPhysics.Position.X; float fireballLocationY = fireball.FireballPhysics.Position.Y; int blocksWidth = block.BlockBox.Width; int blocksHeight = block.BlockBox.Height; int blockIndexX = (int)Math.Ceiling(fireballLocationX / blocksWidth); int blockIndexY = (int)Math.Ceiling(fireballLocationY / blocksHeight); for (int blockIndexOffsetX = Constant.Instance.BlockIndexOffset; blockIndexOffsetX < Constant.Instance.BlockIndexOffsetLimit; blockIndexOffsetX++) { for (int blockIndexOffsetY = Constant.Instance.BlockIndexOffset; blockIndexOffsetY < Constant.Instance.BlockIndexOffsetLimit; blockIndexOffsetY++) { CheckFireballBlockCollision(blockIndexX + blockIndexOffsetX, blockIndexY + blockIndexOffsetY, fireball); } } } }
private void DetectItemBlockCollision() { foreach (IItem item in Level.ItemList) { IBlock block = new GroundBlock(new Vector2(0, 0)); float itemLocationX = item.ItemPhysics.Position.X; float itemLocationY = item.ItemPhysics.Position.Y; int blocksWidth = block.BlockBox.Width; int blocksHeight = block.BlockBox.Height; int blockIndexX = (int)Math.Ceiling(itemLocationX / blocksWidth); int blockIndexY = (int)Math.Ceiling(itemLocationY / blocksHeight); for (int blockIndexOffsetX = Constant.Instance.BlockIndexOffset; blockIndexOffsetX < Constant.Instance.BlockIndexOffsetLimit; blockIndexOffsetX++) { for (int blockIndexOffsetY = Constant.Instance.BlockIndexOffset; blockIndexOffsetY < Constant.Instance.BlockIndexOffsetLimit; blockIndexOffsetY++) { CheckItemBlockCollision(blockIndexX + blockIndexOffsetX, blockIndexY + blockIndexOffsetY, item); } } } }
void GetBlock() { var hits = Physics2D.RaycastAll(transform.position, Vector2.down); var block = standingBlock; foreach (var h in hits) { block = h.transform.GetComponent <GroundBlock>(); if (block != null) { break; } } if (block == null || block == standingBlock) { return; } blockPenalty = false; print("You stand on " + block.name); standingBlock = block; if (standingBlock.Faction.ID == this.faction.ID || standingBlock.Faction.ID == Faction.Default.ID) { return; } blockPenalty = true; if (!caughtDew) { return; } caughtDew = false; standingBlock.CaughtWater++; if (standingBlock.Faction.ID == Faction.Default.ID) { blockPenalty = false; } }
void OnCollisionStay2D(Collision2D coll) { if (coll.transform.tag == "Ground") { CheckBlockCollidable(coll); curJump = 0; canJump = true; GroundBlock comp = coll.gameObject.GetComponent <GroundBlock>(); bool flag = comp == null ? true : comp.allowDownShift; if (flag) { if (Input.GetKey(downButton)) { coll.collider.isTrigger = true; } } } }
private void OnDrawGizmosSelected() { if (this.registGroundBlock == null || this.registGroundBlock.Length <= 0) { return; } Gizmos.color = Color.red; foreach (var area in this.registGroundBlock) { for (int y = 0; y < area.w; y++) { for (int x = 0; x < area.z; x++) { var rect = GroundBlock.MapPositionToRect(new Vector2Int((int)area.x + x, (int)area.y + y)); Gizmos.DrawLine(new Vector3(rect.xMin, 0f, rect.yMin), new Vector3(rect.xMax, 0f, rect.yMax)); Gizmos.DrawLine(new Vector3(rect.xMin, 0f, rect.yMax), new Vector3(rect.xMax, 0f, rect.yMin)); } } } }
void OnControllerColliderHit(ControllerColliderHit hit) { if (hit.gameObject.tag == PrefabManager.instance.groundBlock.tag) { GroundBlock block = hit.gameObject.GetComponent <GroundBlock>(); if (!block.grassType) { GrassGrid grassGrid = Instantiate( PrefabManager.instance.grassPlatform, block.gameObject.transform.position + block.gameObject.transform.TransformVector(-0.5f, 0.5001f, -0.5f), block.transform.rotation ).GetComponent <GrassGrid>(); grassGrid.Init( block.transform.localScale.x, block.transform.localScale.z, block.transform.InverseTransformPoint(hit.point)); block.grassType = true; } } }
private void placeEnemies() { List <GroundBlock> possibleEnemyLocations = new List <GroundBlock>(); // Columns for (int i = 0; i < levelBlocks.GetLength(0); i++) { // Rows for (int j = Math.Max(0, Settings.RowsBeforeEnemies - currentDifficultySize); j < levelBlocks.GetLength(1); j++) { GroundBlock currentBlock = levelBlocks[i, j]; if (currentBlock.CanHoldEnemy) { possibleEnemyLocations.Add(currentBlock); } } } for (int i = 0; i < Settings.EnemiesPerLevelMatrix; i++) { if (possibleEnemyLocations.Any()) { GroundBlock enemyBlock = possibleEnemyLocations[Random.Range(0, possibleEnemyLocations.Count)]; possibleEnemyLocations.Remove(enemyBlock); Enemy enemyToPlace = findFittingEnemy(); GameObject enemy = Instantiate(enemyToPlace.Prefab); NavMeshAgent agent = enemy.GetComponent <NavMeshAgent>(); agent.enabled = false; EnemyBehaviour enemyBehaviour = enemy.GetComponent <EnemyBehaviour>(); enemyToPlace.SetVariablesForDifficultyLevel(enemyBehaviour, Settings.Difficulty); enemy.transform.position = new Vector3(enemyBlock.transform.position.x, enemy.transform.position.y, enemyBlock.transform.position.z); idleEnemies.Add(enemyBehaviour); agent.enabled = true; } else { break; } } }
private void Update() { var hits = Physics2D.RaycastAll(transform.position, Vector2.down, 2f); GroundBlock block = null; foreach (var h in hits) { block = h.transform.GetComponent <GroundBlock>(); if (block != null) { break; } } if (block == null || block.Faction.ID == Faction.Default.ID) { return; } block.Faction = Faction.Default; ReleaseSelf(); }
void Start() { Transform parent = transform.parent; if (parent == null) { Destroy(gameObject); return; } GroundBlock block = parent.GetComponent <GroundBlock>(); if (block != null && block.posInMinigrid == GameManager.Instance.entranceBlockPosition) { Destroy(gameObject); return; } thisTransform = transform; playerSquad = GameObject.FindWithTag("Player").GetComponent <Squad>(); collider = GetComponent <Collider2D>(); }
private static void LoadLevel(XmlReader reader) { Random random = new Random(); string objectType = ""; string objectName = ""; string location = ""; bool typeFlag = false; bool nameFlag = false; bool locationFlag = false; IList <IBlock> blockList = new List <IBlock>(); IList <IEnemy> enemyList = new List <IEnemy>(); IList <IItem> itemList = new List <IItem>(); while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name.ToString()) { case "ObjectType": objectType = reader.ReadString(); typeFlag = true; break; case "ObjectName": objectName = reader.ReadString(); nameFlag = true; break; case "Location": location = reader.ReadString(); locationFlag = true; break; } if (typeFlag && nameFlag && locationFlag) { switch (objectType) { case "Player": string[] coordinates = location.Split(' '); Mario.Instance.ConditionState = new SmallMarioState(Mario.Instance); Mario.Instance.Location = new Vector2(Int32.Parse(coordinates[0]), Int32.Parse(coordinates[1])); break; case "Block": switch (objectName) { case "HiddenBlock": string[] blockCoordinates = location.Split(' '); IBlock block = new HiddenBlock(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "HiddenBlockEmpty": blockCoordinates = location.Split(' '); block = new HiddenBlockEmpty(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "HiddenBlockCoin": blockCoordinates = location.Split(' '); block = new HiddenBlockCoin(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "HiddenBlockStar": blockCoordinates = location.Split(' '); block = new HiddenBlockStar(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "BrickBlock": blockCoordinates = location.Split(' '); block = new BrickBlock(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "BrickBlockEmpty": blockCoordinates = location.Split(' '); block = new BrickBlockEmpty(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "ItemBrick": blockCoordinates = location.Split(' '); block = new BrickBlockWithItem(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "ItemBrickCoin": blockCoordinates = location.Split(' '); block = new BrickBlockWithCoin(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "ItemBrickStar": blockCoordinates = location.Split(' '); block = new BrickBlockWithStar(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "QuestionBlock": blockCoordinates = location.Split(' '); block = new QuestionBlock(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "QuestionBlockEmpty": blockCoordinates = location.Split(' '); block = new QuestionBlockEmpty(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "QuestionBlockStar": blockCoordinates = location.Split(' '); block = new QuestionBlockStar(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "QuestionBlockCoin": blockCoordinates = location.Split(' '); block = new QuestionBlockCoin(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "UnbreakableBlock": blockCoordinates = location.Split(' '); block = new UnbreakableBlock(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "UsedBlock": blockCoordinates = location.Split(' '); block = new UsedBlock(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "GroundBlock": blockCoordinates = location.Split(' '); block = new GroundBlock(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "Pipe": blockCoordinates = location.Split(' '); block = new Pipe(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "PipeBottom": blockCoordinates = location.Split(' '); block = new PipeBottom(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "WarpPipe": blockCoordinates = location.Split(' '); WarpPipe pipe = new WarpPipe(); pipe.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); switch (pipe.Location.X) { case 1760: pipe.WarpDestination = new Vector2(8000, 384); break; case 8736: pipe.WarpDestination = new Vector2(2080, 352); break; } blockList.Add((IBlock)pipe); break; case "FlagPole": blockCoordinates = location.Split(' '); block = new FlagPole(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; } break; case "Enemy": switch (objectName) { case "Goomba": string[] enemyCoordinates = location.Split(' '); IEnemy enemy = new Goomba(); enemy.RowId = random.Next(0, 160); enemy.Location = new Vector2(Int32.Parse(enemyCoordinates[0]), Int32.Parse(enemyCoordinates[1])); enemyList.Add(enemy); break; case "Koopa": enemyCoordinates = location.Split(' '); enemy = new Koopa(); enemy.RowId = random.Next(0, 160); enemy.Location = new Vector2(Int32.Parse(enemyCoordinates[0]), Int32.Parse(enemyCoordinates[1])); enemyList.Add(enemy); break; } break; case "Item": switch (objectName) { case "Coin": string[] itemCoordinates = location.Split(' '); IItem item = new Coin(); item.Location = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1])); itemList.Add(item); break; case "FireFlower": itemCoordinates = location.Split(' '); item = new FireFlower(); item.Location = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1])); itemList.Add(item); break; case "OneUpMush": itemCoordinates = location.Split(' '); item = new OneUpMushroom(); item.Location = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1])); itemList.Add(item); break; case "SuperMush": itemCoordinates = location.Split(' '); item = new SuperMushroom(); item.Location = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1])); itemList.Add(item); break; case "Star": itemCoordinates = location.Split(' '); item = new Star(); item.Location = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1])); itemList.Add(item); break; } break; } typeFlag = false; nameFlag = false; locationFlag = false; } } } PlayerLevel.Instance.BlockArray = blockList; PlayerLevel.Instance.EnemyArray = enemyList; PlayerLevel.Instance.ItemArray = itemList; }
public void Undo() { /*RETURN TO BEFORE STATE * GameController * Player(Both) */ Player main_player = player; //먼저 움직인 캐릭터 Player other_player = player.other; //그 다음에 움직인 캐릭터(안 움직였을 수도 있음) map.SetBlockData((int)other_player.transform.position.x, (int)other_player.transform.position.z, other_player.temp); map.SetBlockData((int)main_player.transform.position.x, (int)main_player.transform.position.z, main_player.temp); main_player.transform.position = beforePosition_move; other_player.transform.position = beforePosition_other; Debug.Log(player_move_state.state); main_player.temp = player_move_state.temp; main_player.onCloud = player_move_state.onCloud; main_player.isLock = player_move_state.isLock; main_player.state = player_move_state.state; other_player.temp = player_other_state.temp; other_player.onCloud = player_other_state.onCloud; other_player.isLock = player_other_state.isLock; other_player.state = player_other_state.state; if (main_player.state == Player.State.Master) { other_player.transform.SetParent(main_player.transform); } else if (main_player.state == Player.State.Slave) { main_player.transform.SetParent(other_player.transform); } else { other_player.transform.SetParent(null); main_player.transform.SetParent(null); } int main_player_data = (int)main_player.transform.position.y == 1 ? BlockNumber.character : BlockNumber.upperCharacter; int other_player_data = (int)other_player.transform.position.y == 1 ? BlockNumber.character : BlockNumber.upperCharacter; map.SetBlockData((int)main_player.transform.position.x, (int)main_player.transform.position.z, main_player_data); map.SetBlockData((int)other_player.transform.position.x, (int)other_player.transform.position.z, other_player_data); //reset check array for (int i = 0; i < beforeSnow.Count; i++) { int height = (int)beforeSnow[i].x; int width = (int)beforeSnow[i].y; map.UpdateCheckArray(width, height, false); Block block = map.GetBlock(width, height); if (block.type == Block.Type.Ground) { GroundBlock groundBlock = block.GetComponent <GroundBlock>(); groundBlock.RevertBlock(); } } GameController.instance.RemainCheck(); GameController.instance.moveCount--; GameController.instance.UndoCommand(); if (map.parfait) { foreach (ParfaitBlock parfaitBlock in GameController.instance.mapLoader.parfaitBlock) { if (beforeParfaitOrder > parfaitBlock.sequence) //DeActivate { Debug.Log("clear"); parfaitBlock.ClearParfait(); } else if (beforeParfaitOrder == parfaitBlock.sequence) //Activate { Debug.Log("active"); parfaitBlock.Activate(); } else { Debug.Log("deactive"); parfaitBlock.DeActivate(); } } GameController.ParfaitOrder = beforeParfaitOrder; } //블럭 리셋 for (int i = 0; i < stepped_block.Count; i++) { if (stepped_block[i].type == Block.Type.Cracker) { CrackedBlock crackBlock = stepped_block[i].GetComponent <CrackedBlock>(); //TriggerExit 코드를 방지하기 위함 if (crackBlock.crack_ready) //아직 깨지지 않음 -> 캐릭터가 크래커 위에 있음 { crackBlock.crack_ready = false; //움직여도 깨지지 않게 하기 위함 } else //깨졌음 -> 캐릭터가 지나간 블럭 { crackBlock.RevertBlock(); } } } }
public override void SetClassSpecificFields(GroundBlock block, int x, int y) { }
public abstract void SetClassSpecificFields(GroundBlock block, int x, int y);