//Assign list value to blocks based on color tags void Start() { parentBlock = transform.parent.GetComponent <BlockMove>(); Color = GameObject.FindObjectOfType <RunwayManager>(); switch (this.transform.parent.tag) { case "GreenBlock": activeColor = 0; break; case "RedBlock": activeColor = 1; break; case "BlueBlock": activeColor = 2; break; case "BlackBlock": activeColor = 3; break; default: break; } }
//Попытаться создать прикрепление для единственнного рядом стоящего блока private void SetAT() { Attachment atBlock=new Attachment(); Vector2 atDir = new Vector2(); int count = 0; foreach (Vector3 dirVector in Vector.directions) { Vector2 nextPos = transform.position + dirVector; RaycastHit2D hit = Physics2D.Raycast(nextPos, new Vector3(0, 0, 10)); if (hit) { Attachment at = hit.transform.GetComponent<Attachment>(); BlockMove bm = hit.transform.GetComponent<BlockMove>(); if (at && bm.enabled) { Vector2 blockPos = hit.transform.position; Vector2 playerPos = transform.position; if (blockPos.x - playerPos.x == dirVector.x || blockPos.y - playerPos.y == dirVector.y) { atBlock = at; atDir = dirVector; count++; } } } } if (count == 1) EnableAT(atBlock, atDir); }
// Update is called once per frame void Update() { if (Time.time > nextTime) { //Time > 점점 빨라짐.... nextTime = Time.time + Mathf.Lerp(TIME_BETWEEN.x, TIME_BETWEEN.y, BBB.GetTimeInterpolate(TIME_MAX)); pos.Set(Random.Range(-screenInfo.x, screenInfo.y), screenInfo.y); quat = Quaternion.Euler(Vector3.forward * Random.Range(angleMinMax.x, angleMinMax.y)); Transform _trans = Instantiate(block, pos, quat) as Transform; _trans.localScale *= Random.Range(sizeMinMax.x, sizeMinMax.y); //Score call back Register. BlockMove _scp = _trans.GetComponent <BlockMove> (); if (_scp != null) { _scp.onDeath += delegate() { if (player != null) { score++; scoreText.text = score.ToString(); } }; } //_go.transform.position = new Vector2( // _go.transform.position.x, // _go.transform.position.y + _go.GetComponent<Renderer> ().bounds.extents.y*2 //); } }
public bool SetTarget(Vector3 dirVector) { if (!move && Vector.Multiplicity(transform.position + dirVector)) { Vector3 nextPos = transform.position + dirVector; RaycastHit2D[] hits = Physics2D.RaycastAll(nextPos, new Vector3(0, 0, 10)); floor = null; BlockMove bm = null; bool player = false; foreach (RaycastHit2D hit in hits) { if (floor == null) { floor = hit.transform.GetComponent <Floor>(); } if (hit.transform.GetComponent <BlockMove>() != null && hit.transform.GetComponent <BlockMove>().enabled) { bm = hit.transform.GetComponent <BlockMove>(); } if (hit.transform.GetComponent <PlayerMove>() != null) { player = true; } } if (floor != null && floor.Available(gameObject)) { if (at != null && condititon == Condititon.underPit && player) { StartMove(dirVector); condititon = Condititon.normal; return(true); } if (at != null && condititon == Condititon.underPit && !player) { return(false); } if (at != null && player && at.condititon == Attachment.Condititon.attached && moveFromPlayer) { moveFromPlayer = false; StartMove(dirVector); return(true); } if (bm != null && bm.enabled) { if (bm.SetTarget(dirVector)) { StartMove(dirVector); return(true); } } else { StartMove(dirVector); return(true); } } } return(false); }
public void Boom() { foreach (Collider block in neighbors) { BlockMove health = block.gameObject.GetComponent <BlockMove>(); health.counter++; } }
private void EnableAT(Attachment at, Vector3 dirVector) { attachedBlock = at; atDir = dirVector; attachedBlock.condititon = Attachment.Condititon.attached; bmAttachedBlock = attachedBlock.GetComponent<BlockMove>(); at.player = gameObject; }
private void OnTriggerEnter2D(Collider2D collision) { if (enteredBlock == null) { enteredBlock = collision.gameObject; BlockMoveEnteredBlock = enteredBlock.GetComponent <BlockMove>(); AttachmentEnteredBlock = enteredBlock.GetComponent <Attachment>(); } }
// Start is called before the first frame update void Start() { var ray = Physics2D.Raycast(transform.position, -transform.up, 100, LayerMask.GetMask("Object")); var attached = ray.transform.gameObject; transform.parent = attached.transform; _blockMove = transform.parent.GetComponent <BlockMove>(); _blockColor = GetComponent <BlockColor>(); }
private void OnTriggerExit2D(Collider2D collision) { if (enteredBlock == collision.gameObject) { enteredBlock = null; BlockMoveEnteredBlock = null; AttachmentEnteredBlock = null; filled = false; isFloor = false; lastCondition = Attachment.Condititon.zero; } }
private void CreateBlocks() { for (int i = 0; i < width; i++) { for (int j = 0; j < depth; j++) { GameObject BlockClone = (GameObject)Instantiate(block, (new Vector3(1 + (i * 2), 0, 1 + (j * 2)) + transform.position), Quaternion.identity); BlockMove CloneScript = BlockClone.GetComponent <BlockMove>(); CloneScript.speed = speed; CloneScript.maxHeight = transform.position.y + maxHeight; CloneScript.minHeight = transform.position.y + minHeight; BlockClone.transform.parent = transform; CloneScript.coorInGrid = i + "," + j; Blocks[i, j] = BlockClone; BlockScripts[i, j] = CloneScript; } } }
private void SetAT(Vector3 dirVector) { if (attachedBlock != null) DisableAT(); Vector2 nextPos = transform.position + dirVector; RaycastHit2D hit = Physics2D.Raycast(nextPos, new Vector3(0, 0, 10)); if (hit) { Attachment at = hit.transform.GetComponent<Attachment>(); BlockMove bm = hit.transform.GetComponent<BlockMove>(); if (at && bm.enabled) { Vector2 blockPos = hit.transform.position; Vector2 playerPos = transform.position; if (blockPos.x - playerPos.x == dirVector.x || blockPos.y - playerPos.y == dirVector.y) EnableAT(at, dirVector); } } }
private bool PitAvailability(GameObject go) { BlockMove bm = go.GetComponent <BlockMove>(); Attachment at = go.GetComponent <Attachment>(); //Для блоков, которые заполнят яму //Если объект является прикрепляемым и пол отключен if (at && isFloor == false) { return(!filled); //Яма доступна для заполнения, если она не заполнена } //Для объектов, которые встанут на заполненную яму //Если яма заполнена и объект является перемещаемым (игроком или блоком) if (filled == true && bm) { return(floor.isAvailable); } return(false); }
private void Start() { origin = GetComponent <SpriteRenderer>().sprite; bm = GetComponent <BlockMove>(); }
private void DisableAT() { attachedBlock.condititon = Attachment.Condititon.not_attached; bmAttachedBlock = null; attachedBlock = null; }
// Start is called before the first frame update void Start() { // 플레이어 찾아서 연결하기 GameManager.Instance.player.TurnEndEvent += TurnCount; _block = gameObject.GetComponent <BlockMove>(); }
/// <summary> /// Takes a texture representing the map and generates tiles from the pixels' color values. /// </summary> /// <param name="texMap"></param> public void GenerateMap(Texture2D texMap) { MapEntry map = (MapEntry)currentMap.value; Color32[] colorData = texMap.GetPixels32(); int pos = 0; List <MapTile> mappus = new List <MapTile>(); battleMap.breakables.Clear(); for (int j = 0; j < _sizeY; j++) { for (int i = 0; i < _sizeX; i++) { InteractPosition interPos = GetInteractable(map, i, j); Transform tile = (interPos != null && interPos.interactType == InteractType.BLOCK) ? Instantiate(blockTilePrefab) : Instantiate(tilePrefab); tile.position = new Vector3(i, j, 0); tile.SetParent(battleMap.tileParent); MapTile tempTile = tile.GetComponent <MapTile>(); tempTile.battlemap = battleMap; tempTile.posx = i; tempTile.posy = j; if (interPos == null) { tempTile.SetTerrain(GetTerrainFromPixel(colorData[pos])); } else if (interPos.interactType == InteractType.BLOCK) { tempTile.interactType = InteractType.BLOCK; tempTile.SetTerrain(tileBreakable); tempTile.alternativeTerrain = GetTerrainFromPixel(colorData[pos]); battleMap.breakables.Add(tempTile); BlockMove block = tempTile.GetComponent <BlockMove>(); block.currentTile = tempTile; block.stats.hp = interPos.health; block.currentHealth = interPos.health; } else if (interPos.interactType == InteractType.VILLAGE) { tempTile.interactType = InteractType.VILLAGE; tempTile.alternativeTerrain = GetTerrainFromPixel(colorData[pos]); tempTile.dialogue = interPos.dialogue; tempTile.gift = interPos.gift; if (interPos.ally.charData != null) { tempTile.ally = mapSpawner.SpawnVillageCharacter(interPos); Debug.Log("Spawned ally: " + tempTile.ally.name); } TerrainTile terrain = (interPos.gift == null && interPos.ally == null) ? tileHouse : tileHouseReward; tempTile.SetTerrain(terrain); } else if (interPos.interactType == InteractType.CAPTURE) { tempTile.SetTerrain(GetTerrainFromPixel(colorData[pos])); tempTile.interactType = InteractType.CAPTURE; } else if (interPos.interactType == InteractType.ESCAPE) { tempTile.SetTerrain(GetTerrainFromPixel(colorData[pos])); tempTile.interactType = InteractType.ESCAPE; } else if (interPos.interactType == InteractType.DATABASE) { tempTile.SetTerrain(tileChest); tempTile.alternativeTerrain = tileChest.substitueTile; tempTile.interactType = InteractType.DATABASE; tempTile.gift = interPos.gift; } else if (interPos.interactType == InteractType.DOOR) { tempTile.SetTerrain(tileDoor); tempTile.alternativeTerrain = tileDoor.substitueTile; tempTile.interactType = InteractType.DOOR; tempTile.gift = interPos.gift; } else { Debug.LogError("Unimplemented interact type " + interPos.interactType); } mappus.Add(tempTile); pos++; } } battleMap.tiles = mappus.ToArray(); Debug.Log("Data read and map created"); }
void Move(Vector2 dir) { // 이미 이동 중인 경우 if (_blockMove.IsMoving()) { _moveStack = dir; return; } // 유효한 방향인지 검사 if (!(Mathf.Abs(dir.magnitude - 1) < 0.001f && (Mathf.Abs(Mathf.Abs(dir.x) - 1) < 0.001f || Mathf.Abs(Mathf.Abs(dir.y) - 1) < 0.001f))) { return; } // 문이 있는지 검사 Vector3 position = transform.position; position += Vector3.ClampMagnitude((Vector3)dir, 0.45f); target = BlockCheck(position); if (target != null) { Door _door = target.GetComponent <Door>(); if (_door != null) { // 문이 닫혀 있으면 이동하지 않음 if (!_door.IsOpened()) { return; } // 문이 열려 있으면 블록이 막고 있더라도 이동 if (_door.IsOpened()) { _blockMove.Move(dir); return; } } } // 이동이 가능한지 검사 position = transform.position; while (true) { // 한 칸 이동 position += (Vector3)dir; // 이동할 위치의 오브젝트와 컴포넌트 찾기 target = BlockCheck(position); if (target == null) { break; // 공간이 비어있음 } BlockMove component = target.GetComponent <BlockMove>(); // 움직일 수 없음 if (!component.movable) { return; } } // 블록 밀면서 이동하기 position = transform.position; while (true) { // 한 칸 이동 position += (Vector3)dir; // 이동할 위치의 오브젝트와 컴포넌트 찾기 target = BlockCheck(position); if (target == null) { break; // 공간이 비어있음 } BlockMove component = target.GetComponent <BlockMove>(); // 블록 이동시키기 component.Move(dir); } // 자신 이동하기 _blockMove.Move(dir); }
// Start is called before the first frame update void Start() { _blockMove = GetComponent <BlockMove>(); _blockMove.MoveFinishedEvent += MoveStackPop; // 이동 종료 이벤트에 MoveStackPop 함수 연결 }
// Update is called once per frame void Update() { if (IsSlowDown) { timeSinceSlow += Time.deltaTime; float percent = timeSinceSlow / timeToSlow; if (percent >= 1f) { IsSlowDown = false; } CurrentSpeed = Mathf.MoveTowards(speedBeforeSlow, StartSpeed, percent); } else { CurrentSpeed += Acceleration * Time.deltaTime; } TimeTilSpawnNext -= Time.deltaTime; if (TimeTilSpawnNext < 0) { if (!Isflipped) { float horzExtent = Camera.main.orthographicSize * Screen.width / Screen.height; Vector2 spawnPos = new Vector2(horzExtent + 0.5f, 0); GameObject curGO = Instantiate(spawnList[spawnCounter], spawnPos, Quaternion.identity); foreach (Transform block in curGO.transform) { BlockMove curBM = block.GetComponent <BlockMove>(); curBM.speed = CurrentSpeed; } spawnCounter += 1; if (spawnCounter > spawnList.Length - 1) { spawnCounter -= 2; Isflipped = !Isflipped; } } else { float horzExtent = Camera.main.orthographicSize * Screen.width / Screen.height; Vector2 spawnPos = new Vector2(horzExtent + 0.5f, 0); GameObject curGO = Instantiate(spawnList[spawnCounter], spawnPos, Quaternion.identity); curGO.transform.Rotate(transform.forward, 180f); foreach (Transform block in curGO.transform) { BlockMove curBM = block.GetComponent <BlockMove>(); SpriteRenderer curSR = block.GetComponent <SpriteRenderer>(); curSR.flipY = !curSR.flipY; curBM.speed = CurrentSpeed; block.transform.Rotate(transform.forward, 180f); } spawnCounter -= 1; if (spawnCounter < 0) { spawnCounter += 2; Isflipped = !Isflipped; } } TimeTilSpawnNext = 1 / CurrentSpeed; } }
// Start is called before the first frame update void Start() { GameManager.Instance.player = this; _blockMove = GetComponent <BlockMove>(); _blockMove.MoveFinishedEvent += OnTurnEnd; // 이동 종료 이벤트에 TurnCount 함수 연결 }