//게임 시작 준비. void UpdateGameIn() { //스테이지 구축. GameObject stage = GameObject.Find("Stage"); if (stage == null) { stage = Instantiate(m_stagePrefabs[m_gameCount]) as GameObject; stage.name = "Stage"; return; } //페이드인을 기다립니다. GameObject[] blocks = GameObject.FindGameObjectsWithTag("Block"); foreach (GameObject obj in blocks) { BlockScript b = obj.GetComponent <BlockScript>(); if (b.IsFadeIn()) { return; } } //게임 시작으로 전환. m_state = State.Game; m_gameTime = 0; //발사할 수 있게 합니다. GameObject[] bars = GameObject.FindGameObjectsWithTag("Bar"); foreach (GameObject obj in bars) { BarScript bar = obj.GetComponent <BarScript>(); bar.SetShotEnable(true); //발사기능 OFF. } }
//스테이지를 바꾸는 연출.. void UpdateGameChanging() { //초밥 페이드 아웃 시작. GameObject[] blocks = GameObject.FindGameObjectsWithTag("Block"); foreach (GameObject obj in blocks) { BlockScript b = obj.GetComponent <BlockScript>(); b.FadeOut(); } //탄환 소거. GameObject[] balls = GameObject.FindGameObjectsWithTag("Ball"); foreach (GameObject obj in balls) { Destroy(obj); } //발사할 수 없게 합니다. GameObject[] bars = GameObject.FindGameObjectsWithTag("Bar"); foreach (GameObject obj in bars) { BarScript bar = obj.GetComponent <BarScript>(); bar.SetShotEnable(false); //발사 기능 OFF. } //다음 상태로 전환. m_state = State.GameOut; }
//게임 종료 준비. void UpdateGameOut() { // 페이드 아웃 대기. GameObject[] blocks = GameObject.FindGameObjectsWithTag("Block"); foreach (GameObject obj in blocks) { BlockScript b = obj.GetComponent <BlockScript>(); if (b.IsFadeOut()) { return; } } //스테이지를 지웁니다. Destroy(GameObject.Find("Stage")); // 1게임 종료. ++m_gameCount; //Debug.Log("GameCount:" + m_gameCount); if (m_gameCount == GAMECOUNT_MAX) { m_state = State.GameEnd; // 정해진 게임 수에 도달했으므로 결과 화면으로 전환합니다. } else { m_state = State.GameIn; // 다음 게임으로 진행합니다. } }
//c indicates where the child's parent is in relation to it private void createChild(ShipChromosomeNode n, ChildNode c, ShipController s) { GameObject g = (GameObject)GameObject.Instantiate( Resources.Load(n.isEngine ? Config.ENGINE_PREFAB_LOCATION : Config.HEAVY_BLOCK_PREFAB_LOCATION), Vector3.zero, Quaternion.identity); if (n.isEngine) { EngineScript engine = g.GetComponent <EngineScript>(); engine.initialize(s, n.startEngageAngle, n.rangeEngageAngle); } g.transform.parent = transform; g.transform.localPosition = Vector3.zero; g.transform.localRotation = Quaternion.Euler(0, 0, n.relativeRotation); Vector3 colliderSize = g.GetComponent <MeshCollider>().bounds.size; switch (c) { case ChildNode.TOP: g.transform.localPosition = g.transform.localPosition + rotateByThisRotation(new Vector3(0, -colliderSize.y, 0)); break; case ChildNode.BOTTOM: g.transform.localPosition = g.transform.localPosition + rotateByThisRotation(new Vector3(0, colliderSize.y, 0)); break; case ChildNode.LEFT: g.transform.localPosition = g.transform.localPosition + rotateByThisRotation(new Vector3(colliderSize.x, 0, 0)); break; case ChildNode.RIGHT: g.transform.localPosition = g.transform.localPosition + rotateByThisRotation(new Vector3(-colliderSize.x, 0, 0)); break; } if (Physics.OverlapSphere(g.transform.position, (colliderSize.y < colliderSize.x ? colliderSize.y : colliderSize.x) / 2.1f).Length > 1) { GameObject.Destroy(g); return; } //FixedJoint fixedJoint = g.AddComponent<FixedJoint>(); //fixedJoint.enableCollision = false; //fixedJoint.connectedBody = rigidbody; BlockScript b = g.GetComponent <BlockScript>(); b.initialize(n, s); }
void Start() { Star = GameObject.FindWithTag("Star"); StarRigidbody = Star.GetComponent <Rigidbody>(); blockscript = GameObject.Find("Block_star").GetComponent <BlockScript>(); Star.SetActive(false); }
void Start() { eliminateToLeCanvas = GameObject.Find("EliminateToLeCanvas").GetComponent <Canvas>(); newYearPic = eliminateToLeCanvas.transform.Find("NewYearPic").GetComponent <Image>(); countDownBar = eliminateToLeCanvas.transform.Find("CountDownBar").GetComponent <Slider>(); mainCanvs = GameObject.Find("MainCanvas").GetComponent <Canvas>(); manager = GameObject.Find("CanvasManager").GetComponent <CanvasManager>(); Block block = Resources.Load <Block>("Prefabs/Block"); block = Instantiate(block); blockWidth = Convert.ToInt32(block.GetComponent <RectTransform>().rect.width); blockHeight = Convert.ToInt32(block.GetComponent <RectTransform>().rect.height); //在右侧减少一列 colBlockNum = width / blockWidth - 1; rowBlockNum = height / blockHeight; this.blockWidth = blockWidth / 2; this.blockHeight = blockHeight / 2; blockScript = block.GetComponent <BlockScript>(); DestroyImmediate(block.gameObject); }
public int CheckForHolesAtBlock(BlockScript checkBlock) { int holeDepth = checkBlock.y; if (checkBlock.y > 0 && checkBlock.state != BlockState.Moving && checkBlock.state != BlockState.Match && checkBlock.state != BlockState.New) { foreach (KeyValuePair <int, BlockScript> kvp in fieldBlocks) { if (kvp.Value != null && kvp.Value != this) { //Count how many blocks are below this to count the hole if (kvp.Value.y >= 0 && kvp.Value.x == checkBlock.x && kvp.Value.y < checkBlock.y) { holeDepth--; } } } return(holeDepth); } return(0); }
void LoadLevel() { SaveLoad.LoadMaps(); Game currentGame = SaveLoad.savedMaps[gridSize][level]; gridSize = currentGame.gridSize; //Get filled grid positions for (int n = 0; n < currentGame.filledListPosX.Count; n++) { GridScript.Instance.filledListPos.Add(new Vector2(currentGame.filledListPosX[n], currentGame.filledListPosY[n])); LogicManager.Instance.tilesLeft--; } GridScript.Instance.FillGrid(); //Get blocks and resolutions foreach (SerializableBlock sBlock in currentGame.sBlockList) { GameObject blockGO = Instantiate(Resources.Load(string.Format("Prefabs/Block {0}/{1}", sBlock.tilesNumber, sBlock.blockName))) as GameObject; blockGO.transform.SetParent(GameObject.Find("Blocks").transform); BlockScript bScript = blockGO.GetComponent <BlockScript>(); bScript.solutionIndex = sBlock.solvedIndex; bScript.solutionPos = new Vector2(sBlock.solvedPosX, sBlock.solvedPosY); for (int r = 0; r < Random.Range(0, 4); r++) { blockGO.GetComponent <BlockScript>().RotateBlock(); } } SpawnScript.Instance.DeleteSpawns(); Debug.LogWarning("Map Loaded!"); }
//Adjust avalible slots in Grid as tetrimino gameObjects move public void UpdateGrid(BlockScript blocks) { for (int y = 0; y < GridHeight; y++) { for (int x = 0; x < GridWidth; x++) { if (Grid [x, y] != null) { if (Grid[x, y].parent == blocks.transform) { Grid[x, y] = null; } } } } foreach (Transform mino in blocks.transform) { Vector2 pos = Round(mino.position); if (pos.y < GridHeight - 1) { Grid[(int)pos.x, (int)pos.y] = mino; } } }
public void BeginPathFind() { // Verify at least TWO END POINTS ARE SET! if (this.selectedPathPoints.Count != 2) { return; } JPSState.state = eJPSState.ST_FIND_PATH; // transition state to Primary Jump Point Building State // Tell each child object to re-evaulte their rendering info foreach (GameObject child in childObjects) { BlockScript block_component = child.GetComponent <BlockScript>(); block_component.setupDisplay(); } BlockScript[] points = this.selectedPathPoints.ToArray(); Point start = points[0].nodeReference.pos; Point stop = points[1].nodeReference.pos; List <Point> path = grid.getPath(start, stop); if (path != null && path.Count != 0) { _pathRenderer.drawPath(path); // Draw Path on Screen } }
void CollisionFound(RaycastHit hit) { if (hit.collider.transform.parent) { BlockScript blockScript = hit.collider.transform.parent.GetComponent <BlockScript>(); if (blockScript) { blockScript.WasHit(2); } } if (hit.collider.tag == "shield") { Destroy(gameObject); m_direction = Vector3.Reflect(m_direction, hit.normal); } else { if (hit.rigidbody) { TankScript tank = hit.rigidbody.GetComponent <TankScript>(); if (tank) { tank.Hit(gameObject); } } Bounce(hit.normal); } }
public BlockScript SetBelow() { //luodaan overlap joka kattoo onko alapuolella blokki Vector2 centerPoint = new Vector2(transform.position.x, transform.position.y - 0.54f); stuffBelow = Physics2D.OverlapPointAll(centerPoint); bool found = false; foreach (Collider2D col in stuffBelow) { if (col != gameObject.GetComponent <Collider2D>() && col != player.GetComponent <Collider2D>()) //TODO: siisti { blockBelow = col.gameObject.GetComponent <BlockScript>(); found = true; //print("ALLA ON " + blockBelow); //print(this + " is on top of " + blockBelow); } } if (!found) { blockBelow = null; } return(blockBelow); }
public void HoldBlocks(BlockScript toFall) { foreach (BlockScript block in toFall.group) { block.bs = BlockState.Hold; } }
public void SetBlockInGrid(BlockScript block) { posx = block.transform.position.x; posy = block.transform.position.y; blockGrid[Mathf.RoundToInt(posx), -Mathf.RoundToInt(posy)] = block; blockGrid[Mathf.RoundToInt(posx), -Mathf.RoundToInt(posy)].SetGridPos(Mathf.RoundToInt(posx), -Mathf.RoundToInt(posy), columns); }
//if the block above is durable -> chance of generating a candy block? //should the durable & candy blocks be generated? //if there is a durable block here, delete the generated block from here public void CreateBlock(int type, int row, int column) { //candy = type 1, block = type 2, durable block = type 3, level end block = type 4 string typeS; if (type == 1) { typeS = "Candy"; } else if (type == 2) { typeS = "Block"; } else if (type == 3) { typeS = "Fluori"; } else { typeS = "LvlEnd"; } GameObject go; //configure candies if (type == 1) { go = Instantiate(candyPrefab); blockScript = go.GetComponent <BlockScript>(); blockScript.bc = BlockColor.Candy; blockScript.bs = BlockState.Static; } else if (type == 3) { go = Instantiate(greyPrefab); } else { go = Instantiate(blockPrefab); } //for all types, change name and position go.name = (typeS + "_" + row + "_" + column).ToString(); Vector2 newPosition = new Vector2(firstBlock.x + column, firstBlock.y - row); go.transform.position = newPosition; blockScript = go.GetComponent <BlockScript>(); //separate level end blocks from blocks and candies (why?) //configure level end blocks if (type < 4) { go.transform.parent = blockFolder; } else { go.transform.parent = endBlocks; blockScript.bc = BlockColor.LevelEnd; blockScript.bs = BlockState.Static; blockScript.levelEnd = true; } }
public void entangle(BlockScript block) { Texture c = color == 1 ? red : color == 0 ? purple : blue; if (entangled != null && block == null) { BlockScript temp = entangled; entangled = null; if (temp.entangled != null) { temp.entangle(null); } c = color == 1 ? red : color == 0 ? purple : blue; } else if (block != null) { if (entangled && entangled.entangled != null) { entangled.entangle(null); } entangled = block; if (block.entangled != this) { block.entangle(this); } c = color == 1 ? red2 : color == 0 ? purple2 : blue2; } GetComponent <Renderer>().material.SetTexture("_EmissionMap", c); }
public void generatePhysicalShip(ShipChromosomeNode root) { GameObject g = (GameObject)GameObject.Instantiate(Resources.Load(Config.HEAVY_BLOCK_PREFAB_LOCATION), Vector3.zero, Quaternion.identity); Rigidbody r = g.AddComponent <Rigidbody>(); r.mass = Config.BLOCK_MASS * root.getListOfNodes().Count; r.drag = Config.BLOCK_DRAG; r.angularDrag = Config.BLOCK_ANGULAR_DRAG; //r.constraints = RigidbodyConstraints.FreezeAll; r.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezePositionZ; BlockScript b = g.GetComponent <BlockScript>(); ShipController s = g.AddComponent <ShipController>(); s.rootNode = root; s.setOrbs(orbsRoot); lastShip = s; b.initialize(root, s); b.combineSubMeshes(); g.transform.position = transform.position; g.SetActive(false); }
BlockScript getBlock(int colorIndex) { BlockScript b = null; while (freeInPool < blocks.Count) { if (!blocks[freeInPool].gameObject.activeSelf) { b = blocks[freeInPool]; break; } freeInPool++; } if (b == null) { b = Instantiate <GameObject>(blockPrefab).GetComponent <BlockScript>(); b.myIndex = blocks.Count; blocks.Add(b); } b.rendy.sharedMaterial = materials[colorIndex]; b.myColor = colorIndex; b.gameObject.SetActive(true); return(b); }
void CreatePoolBlock(GameObject blockPrefab) { GameObject newBlock = Instantiate(blockPrefab, Vector3.one * 100, Quaternion.identity); BlockScript newBlockScript = newBlock.GetComponent <BlockScript>(); pool.Add(newBlockScript); }
public bool CheckAlign() { bool aligned; float yRot = Block2.transform.localRotation.eulerAngles.y; if (yRot >= (360.0f - give) && yRot <= 360.0f || yRot >= 0.0f && yRot <= give) { // print ("Stopped spinning at " + Block2.transform.localRotation.eulerAngles.y); // StopCoroutine(SpinBlockRoutine); BlockScript cbs = CurBlock.GetComponent <BlockScript>(); cbs.isSpinning = false; BlockScript pbs = PrevBlock.GetComponent <BlockScript>(); cbs.ScaleAndMove(1.00f); pbs.ScaleAndMove(1.5f); StartCoroutine(SnapBlock(CurBlock)); PrevBlock = CurBlock; // NextBlock (); return(true); } else { return(false); } }
void CreateJoint() { RaycastHit hitInfo; GetComponentInChildren <Collider>().enabled = false; if (Physics.Raycast(transform.position, -transform.up, out hitInfo, 1.0f)) { if (hitInfo.collider.CompareTag("Block") || hitInfo.collider.CompareTag("Core")) { FixedJoint joint = gameObject.AddComponent <FixedJoint>(); joint.connectedBody = hitInfo.rigidbody; joint.connectedAnchor = hitInfo.transform.position; joint.anchor = transform.position; joint.breakForce = 900.0f; this.joint = joint; FixedJoint jointHit = hitInfo.collider.gameObject.AddComponent <FixedJoint>(); jointHit.connectedBody = rb; jointHit.anchor = hitInfo.transform.position; jointHit.connectedAnchor = transform.position; jointHit.breakForce = 900.0f; BlockScript script = hitInfo.collider.gameObject.GetComponent <BlockScript>(); if (script != null) { script.AddJointToList(jointHit); } } } GetComponentInChildren <Collider>().enabled = true; }
void Merge(BlockScript blockInDir) { //print("merging " + this + " to " + blockInDir.group); int direction = blockInDir == blockLeft ? 1 : -1; if (blockInDir.bs == BlockState.Static) { //if (blockInDir.bs == BlockState.Static || blockInDir.bs == BlockState.Hold) { Vector3 placeToSnap = blockInDir.transform.position + new Vector3(direction, 0, 0); placeToSnap = new Vector3(Mathf.Round(placeToSnap.x), Mathf.Round(placeToSnap.y), Mathf.Round(placeToSnap.z)); transform.position = placeToSnap; bs = BlockState.Static; } var tempTime = blockBelow.holdTimer; foreach (BlockScript block in group) //tästä oma funktio? { if (block.blockLeft) { tempTime = tempTime < block.blockBelow.holdTimer ? tempTime : block.blockLeft.holdTimer; } } foreach (BlockScript block in group) { block.holdTimer = tempTime; } bm.SetBlockInGrid(this); bs = blockInDir.bs; bsc.SpriteUpdate(); //bm.MergeGroups(this, blockInDir); }
private void OnCollisionEnter2D(Collision2D collision) { print("collided"); collided = true; if (collision.gameObject.tag.Equals("Player")) { print("GAME OVER"); SceneManager.LoadScene("Death"); //PlayerScript.Health -= 30; } else { BlockScript blockScript = collision.gameObject.GetComponent <BlockScript>(); print(collision.gameObject); print(blockScript); if (blockScript != null) { currtarget = 0; int nearest = blockScript.GetNearestEdge(targets[2], transform); targets[0] = collision.gameObject.transform.GetChild(nearest / 10); targets[1] = collision.gameObject.transform.GetChild(nearest % 10); if (targets[0] == targets[1]) { currtarget = 1; } print(targets[0].parent.gameObject.name); print(targets[0].gameObject.name); print(targets[1].gameObject.name); } prioritizeY = !prioritizeY; rigidbody.MovePosition(rigidbody.position - movementVector); } //EnemyPosScript.UpdatePosition(index, transform.position); }
//Tenta colocar blocos de 4 ou 5 squares em uma posição aleatoria no grid void PlaceRandomBlocks() { Vector2 destiny = new Vector2(Random.Range(0, gridSize), Random.Range(0, gridSize)); int squaresNumber = Random.Range(4, 6); GameObject randomBlock = GameManager.Instance.allBlocks[squaresNumber][Random.Range(0, GameManager.Instance.allBlocks[squaresNumber].Count)] as GameObject; GameObject blockGO = (GameObject)Instantiate(randomBlock, SpawnScript.Instance.spawnLocations[GameManager.Instance.activeBlocks.Count].transform.position, Quaternion.identity); for (int rot = 0; rot < Random.Range(0, 4); rot++) { blockGO.GetComponent <BlockScript>().RotateBlock(); } if (LogicManager.Instance.CheckPosition(blockGO, destiny)) { blockGO.transform.parent = GameObject.Find("Blocks").transform; LogicManager.Instance.PlaceBlock(blockGO, destiny); BlockScript bs = blockGO.GetComponent <BlockScript>(); bs.solutionPos = destiny; bs.solutionIndex = bs.rotIndex; blockGO.transform.position = SpawnScript.Instance.spawnLocations[bs.bNumber].transform.position - Vector3.forward; Debug.Log(blockGO.name + " posicionado em " + bs.solutionPos.x + "," + bs.solutionPos.y); string blockID = blockGO.name.Replace("(Clone)", "").Trim(); sBlockList.Add(new SerializableBlock(blockID, squaresNumber, bs.solutionIndex, (int)bs.solutionPos.x, (int)bs.solutionPos.y)); } else { GameManager.Instance.activeBlocks.Remove(blockGO); Destroy(blockGO); } }
void PaintGridPreview() { ClearGridColor(); Vector2 closestGridLoc = new Vector2(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.y)); Vector2 destiny = closestGridLoc - (relativePos - parentBlock.rotPos[parentBlock.rotIndex]); BlockScript bs = parentBlock.GetComponent <BlockScript>(); foreach (BlockTile bTile in parentBlock.tileList) { Color gridPreviewColor; Vector2 tilePos = destiny - (bs.rotPos[bs.rotIndex] - bTile.relativePos); if (tilePos.x >= 0 && tilePos.x < SpawnScript.Instance.gridSize && tilePos.y >= 0 && tilePos.y < SpawnScript.Instance.gridSize) { if (LogicManager.Instance.CheckPosition(parentBlock.gameObject, destiny)) { gridPreviewColor = new Color(0, 1, 0, 0.7f); } else { gridPreviewColor = new Color(1, 0, 0, 0.7f); } gridGO[Mathf.RoundToInt(tilePos.x), Mathf.RoundToInt(tilePos.y)].GetComponent <SpriteRenderer>().color = gridPreviewColor; } } GridScript.Instance.FillGrid(); }
private void GestureRecognizer_ManipulationUpdatedEvent(InteractionSourceKind source, Vector3 cumulativeDelta, Ray headRay) { Debug.Log("enter into updated"); GameObject oCurrentGameObject = EventSystem.current.currentSelectedGameObject; if (oCurrentGameObject != null) { oBlockScript = oCurrentGameObject.GetComponent <BlockScript>(); Debug.Log("got blockscript"); if (oBlockScript != null) { //oBlockScript.startMove(); //Debug.Log("start move called"); oBlockScript.move(); Debug.Log("move called"); } else { Debug.Log("block script null"); } } else { Debug.Log("current game object is null"); } }
public void OnDragStart(BlockScript block) { draggedLinkers = new List <GameObject>(); otherLinkers = new List <GameObject>(); foreach (Transform t in block.tilesParent.transform) { if (t.CompareTag("Linker")) { draggedLinkers.Add(t.gameObject); } } List <BlockScript> blocks = BlockManager.instance.LivingBlocks; foreach (BlockScript b in blocks) { if (b != null && b != block) { foreach (Transform t in b.tilesParent.transform) { if (t.CompareTag("Linker")) { otherLinkers.Add(t.gameObject); } } } } }
public Block(BlockScript bs) { pos = new IVector3(bs.transform.position); indest = bs.indest; no_weld = (from d in bs.no_weld select new IVector3(bs.transform.rotation * d)).ToList(); shape = new BlockShape(this); this.bs = bs; }
void MatchBlock(BlockScript block, float delay) { if (block != null) { //print(" " + block + " " + block.x + ", " + block.y); fxControllerScript.MatchBlock(block, gameControllerScript.matchDelay, delay); } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag.Equals("BlockTag")) { BlockScript blockScript = other.gameObject.GetComponent <BlockScript>(); blockScript.takeDamage(); } }
public void SetBlock(int x, int y, int z, BlockScript block) { if (InRange(x) && InRange(y) && InRange(z)) { blocks[x, y, z] = block; } else { world.SetBlock(pos.x + x, pos.y + y, pos.z + z, block); } }
// Use this for initialization void Start() { block = GetComponent<BlockScript>(); }
protected override void Start() { collider.isTrigger = true; _block = transform.parent.parent.GetComponent<BlockScript>(); }
public void SetBlock(int x, int y, int z, BlockScript block) { Chunk chunk = GetChunk(x, y, z); if (chunk != null) { chunk.SetBlock(x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, block); chunk.update = true; } }
public override bool IsSolid(BlockScript.Direction direction) { return false; }