static void moveAnyObject(Vector3 oldPos, Vector3 newPos) { if (SpawnTiles.tileExists(oldPos) && !SpawnTiles.tileExists(newPos)) { GameObject toMove = SpawnTiles.blocks [oldPos]; SpawnTiles.blocks.Remove(oldPos); SpawnTiles.blocks.Add(newPos, toMove); toMove.transform.position = newPos; } }
private static bool movementBlocked(Vector3 currentTile, Vector3 offset, Vector3 currentRampDirection) { if (currentRampDirection == offset) { currentTile += Vector3.up * 2; } GameObject block = SpawnTiles.tileExists(currentTile + offset) ? SpawnTiles.blocks [SpawnTiles.roundVector(currentTile + offset)] : null; RampBehaviour ramp = block == null ? null : block.GetComponent <RampBehaviour> (); return ((!PLAYER_CAN_FALL && !SpawnTiles.tileExists(currentTile + offset + new Vector3(0, -2, 0))) || ( block != null && block.GetComponent <VoidManager> () == null && block.GetComponent <WaterManager> () == null && (ramp == null || (ramp.upSlopeDirection != offset && currentRampDirection != ramp.upSlopeDirection)) )); }
public void SetPassable(bool status) { passable = status; if (!passable && SpawnTiles.tileIsFree(transform.position)) { SpawnTiles.blocks [SpawnTiles.roundVector(transform.position)] = gameObject; r.enabled = true; } if (!passable && SpawnTiles.tileExists(transform.position) && !SpawnTiles.tileHasPlayer(SpawnTiles.roundVector(transform.position)) && SpawnTiles.blocks[SpawnTiles.roundVector(transform.position)].GetComponent <WaterManager>() != null) { Destroy(SpawnTiles.blocks [SpawnTiles.roundVector(transform.position)]); SpawnTiles.blocks [SpawnTiles.roundVector(transform.position)] = gameObject; r.enabled = true; } if (passable && SpawnTiles.tileExists(transform.position) && SpawnTiles.blocks [SpawnTiles.roundVector(transform.position)] == gameObject) { SpawnTiles.blocks.Remove(SpawnTiles.roundVector(transform.position)); r.enabled = false; } }
void Update() { if (Time.time >= nextTime) { simulatePhysics(); nextTime += tick; } //Move player if in water foreach (Player p in players) { Vector3 currentTile = new Vector3( Mathf.Round(p.transform.position.x / 2), Mathf.Round(p.transform.position.y / 2), Mathf.Round(p.transform.position.z / 2)) * 2; if (SpawnTiles.tileExists(SpawnTiles.roundVector(currentTile)) && SpawnTiles.blocks [SpawnTiles.roundVector(currentTile)].GetComponent <WaterManager> () != null) { Vector3 newPosition = p.transform.position + Move.WaterMove(SpawnTiles.blocks [SpawnTiles.roundVector(currentTile)].GetComponent <WaterManager> ()); p.transform.position = newPosition; } } }
void simulatePhysics() { //Find all Voidblocks - physics sometimes applies to things inside a void List <VoidManager> voidblocks = new List <VoidManager>(); foreach (GameObject v in GameObject.FindGameObjectsWithTag("Void")) { if (v != null) { voidblocks.Add(v.GetComponent <VoidManager> ()); } } //Pushblock physics List <Pushblock> pushables = new List <Pushblock>(); foreach (GameObject x in GameObject.FindGameObjectsWithTag("Pushblock")) { if (x != null) { pushables.Add(x.GetComponent <Pushblock> ()); } } foreach (Pushblock p in pushables) { Vector3 below = new Vector3(p.transform.position.x, p.transform.position.y - 2, p.transform.position.z); if (!SpawnTiles.tileExists(below)) { SpawnTiles.blocks.Remove(SpawnTiles.roundVector(p.transform.position)); p.transform.position = below; SpawnTiles.blocks.Add(below, p.gameObject); } if (p.transform.position.y < killPlane) { SpawnTiles.blocks.Remove(SpawnTiles.roundVector(p.transform.position)); Destroy(p.gameObject); } } //Black Hole Physics List <GameObject> blackholes = new List <GameObject>(); foreach (GameObject b in GameObject.FindGameObjectsWithTag("Blackhole")) { if (b != null) { blackholes.Add(b); } } foreach (GameObject b in blackholes) { Vector3 up = b.transform.position + Vector3.up * 2; Vector3 down = b.transform.position + Vector3.down * 2; Vector3 left = b.transform.position + Vector3.left * 2; Vector3 right = b.transform.position + Vector3.right * 2; Vector3 forward = b.transform.position + Vector3.forward * 2; Vector3 back = b.transform.position + Vector3.back * 2; Vector3[] reachable = new Vector3[] { up, down, left, right, forward, back }; foreach (Vector3 v in reachable) { if (SpawnTiles.tileExists(v)) { Destroy(SpawnTiles.blocks[v].gameObject); SpawnTiles.blocks.Remove(v); } } } //Water physics List <WaterManager> waterblocks = new List <WaterManager>(); foreach (GameObject w in GameObject.FindGameObjectsWithTag("Water")) { if (w != null) { waterblocks.Add(w.GetComponent <WaterManager> ()); } } //add water blocks in voids foreach (VoidManager v in voidblocks) { foreach (GameObject g in v.getAllObjects()) { if (g.GetComponent <WaterManager> () != null) { waterblocks.Add(g.GetComponent <WaterManager>()); } } } foreach (WaterManager wtr in waterblocks) { Vector3 below = new Vector3(wtr.transform.position.x, wtr.transform.position.y - 2, wtr.transform.position.z); Vector3 next = getNextWater(wtr); //flow down if (!SpawnTiles.tileExists(below) && below.y > killPlane) { generateWater(wtr, below, false); } //flow to next tile if free and not void, and there is not water below else if (!SpawnTiles.tileExists(next) && SpawnTiles.tileExists(below) && SpawnTiles.blocks [SpawnTiles.roundVector(below)].GetComponent <WaterManager> () == null) { generateWater(wtr, next, false); } //flow into void block next else if (SpawnTiles.tileExists(next) && SpawnTiles.blocks [next].GetComponent <VoidManager> () != null) { SpawnTiles.blocks [next].GetComponent <VoidManager> ().addObject(generateWater(wtr, next, true)); } //flow into void block below else if (SpawnTiles.tileExists(below) && SpawnTiles.blocks [below].GetComponent <VoidManager> () != null) { SpawnTiles.blocks [below].GetComponent <VoidManager> ().addObject(generateWater(wtr, below, true)); } //push pushblock if (SpawnTiles.tileExists(next) && SpawnTiles.blocks [SpawnTiles.roundVector(next)].GetComponent <Pushblock> () != null) { Pushblock p = SpawnTiles.blocks [SpawnTiles.roundVector(next)].GetComponent <Pushblock> (); Vector3 nextNext = getNextWaterPush(wtr.getDirection(), p); if (!SpawnTiles.tileExists(nextNext)) { SpawnTiles.blocks.Remove(SpawnTiles.roundVector(p.transform.position)); p.transform.position = nextNext; SpawnTiles.blocks.Add(p.transform.position, p.gameObject); } } //stop water if parent is destoryed if (!wtr.isSource() && wtr.getParent() == null) { SpawnTiles.blocks.Remove(SpawnTiles.roundVector(wtr.transform.position)); Destroy(wtr.gameObject); } } }
public static void ObjectMove(string axisV, string axisH, Player p) { Vector2 translation = new Vector2(Input.GetAxis(axisV), Input.GetAxis(axisH)); translation = translation.normalized * GetMagnitude(translation) * Time.deltaTime * speed; Vector3 positionOffset = UP * translation.x + RIGHT * translation.y; Vector3 waterOffset = new Vector3(0, 0, 0); Vector3 currentTile = new Vector3( Mathf.Round(p.transform.position.x / 2), Mathf.Round(p.transform.position.y / 2), Mathf.Round(p.transform.position.z / 2)) * 2; RampBehaviour ramp = SpawnTiles.tileExists(currentTile) ? SpawnTiles.blocks [currentTile].GetComponent <RampBehaviour>() : null; Vector3 tileBelow = currentTile + Vector3.down * 2; bool onIce = false; if (ramp == null && SpawnTiles.tileExists(tileBelow)) { ramp = SpawnTiles.blocks [tileBelow].GetComponent <RampBehaviour> (); if (ramp != null) { currentTile = tileBelow; } else { onIce = SpawnTiles.blocks [tileBelow].GetComponent <IceManager> () != null && (p.prevOffset.x != 0 || p.prevOffset.z != 0); } } p.pos = currentTile; if (positionOffset.magnitude > 0) { p.transform.rotation = Quaternion.LookRotation(positionOffset); } if (onIce && p.prevOffset != Vector3.zero) { positionOffset = p.prevOffset.normalized * speed * Time.deltaTime; } Vector3 positionWithinTile = p.transform.position + positionOffset - currentTile; if (!SpawnTiles.tileExists(tileBelow) || (ramp == null && positionWithinTile.y > 0) || SpawnTiles.blocks[tileBelow].GetComponent <VoidManager>() != null || SpawnTiles.blocks[tileBelow].GetComponent <WaterManager>() != null) { positionOffset = Vector3.down * Time.deltaTime * 6; } Vector3 lookVector = p.transform.TransformDirection(Vector3.forward); int normalizedX = lookVector.x > 0 ? 2 : -2; int normalizedZ = lookVector.z > 0 ? 2 : -2; float distX = Mathf.Abs(normalizedX - positionWithinTile.x * 2) / Mathf.Abs(lookVector.x); float distZ = Mathf.Abs(normalizedZ - positionWithinTile.z * 2) / Mathf.Abs(lookVector.z); Vector3 newPos = currentTile + (distX < distZ ? new Vector3(normalizedX, 0, 0) : new Vector3(0, 0, normalizedZ)); p.selector.position = newPos; bool cubeSelector = SpawnTiles.tileExists(p.selector.position); p.selector.GetComponent <Renderer> ().enabled = cubeSelector; p.selectorChild.GetComponent <Renderer> ().enabled = !cubeSelector; bool exceedingBoundaryX = (positionOffset.x > 0 && positionWithinTile.x > RADIUS) || (positionOffset.x < 0 && positionWithinTile.x < -RADIUS); bool exceedingBoundaryZ = (positionOffset.z > 0 && positionWithinTile.z > RADIUS) || (positionOffset.z < 0 && positionWithinTile.z < -RADIUS); bool onEdge = false; Vector3 rampDirection = ramp == null ? Vector3.zero : ramp.upSlopeDirection; if (movementBlocked(currentTile, new Vector3(normalizedX, 0, 0), rampDirection)) { if (exceedingBoundaryX) { positionOffset.x = 0; onEdge = true; } } if (movementBlocked(currentTile, new Vector3(0, 0, normalizedZ), rampDirection)) { if (exceedingBoundaryZ) { positionOffset.z = 0; onEdge = true; } } if (movementBlocked(currentTile, new Vector3(normalizedX, 0, normalizedZ), rampDirection)) { if (exceedingBoundaryX && exceedingBoundaryZ && !onEdge) { positionOffset.x = 0; positionOffset.z = 0; onEdge = true; } } p.prevOffset = onEdge ? Vector3.zero : positionOffset; //acount for water if (SpawnTiles.tileExists(currentTile) && SpawnTiles.blocks [SpawnTiles.roundVector(currentTile)].GetComponent <WaterManager> () != null) { WaterManager w = SpawnTiles.blocks [SpawnTiles.roundVector(currentTile)].GetComponent <WaterManager> (); waterOffset = waterDirections [w.getDirection()] * Time.deltaTime * speed * 1.1f; } float rampOffset = ramp == null ? 0 : mul((positionWithinTile + ramp.upSlopeDirection * 0.5f), ramp.upSlopeDirection).magnitude * 0.5f; Vector3 newPosition = p.transform.position + positionOffset + waterOffset; if (ramp == null) { } else { newPosition.y = currentTile.y + rampOffset; } p.transform.position = newPosition; if (p.transform.position.y < -10) { p.Respawn(); } }
void Update() { if (WorldManager.inMenu) { return; } for (int i = 0; i < players.Length; i++) { //uncomment line below to make use of player inventory currentSpell [i] = players [i].getCurrentSpell(); if (Input.GetButton("Spell" + i.ToString())) { if (spellProgress [i] >= 1) { spellProgress [i] = -1; players [i].lastSpellFinished = true; Vector3 playerPos = getTile(players [i].transform.position); int otherPlayer = -1; Vector3 spellPos = selectors [i].transform.position; Vector3 belowSpellPos = new Vector3(spellPos.x, spellPos.y - 2, spellPos.z); Vector3 aboveSpellPos = new Vector3(spellPos.x, spellPos.y + 2, spellPos.z); for (int j = 0; j < players.Length; j++) { if (j == i) { continue; } Vector3 otherSpellPos = selectors [j].transform.position; if (otherSpellPos == spellPos && spellProgress[j] > 0) { otherPlayer = j; spellProgress [j] = -1; break; } } if (currentSpell [i].Equals(spell.PUSH)) { Instantiate(pushEffect, playerPos, Quaternion.LookRotation(spellPos - playerPos)).transform.Translate(0, 0, -1); if (otherPlayer != -1) { Vector3 otherPlayerPos = getTile(players [otherPlayer].transform.position); Instantiate(pushEffect, otherPlayerPos, Quaternion.LookRotation(spellPos - otherPlayerPos)).transform.Translate(0, 0, -1); } } //PUSH and DOUBlE PUSH if (currentSpell [i].Equals(spell.PUSH) && SpawnTiles.tileExists(spellPos)) { Spellable spellableBlock = SpawnTiles.blocks [SpawnTiles.roundVector(spellPos)].GetComponent <Spellable> (); //should also handle void blocks VoidManager v = SpawnTiles.blocks [SpawnTiles.roundVector(spellPos)].GetComponent <VoidManager> (); if (v != null) { foreach (GameObject g in v.getAllObjects()) { if (g.GetComponent <Spellable> () != null) { spellableBlock = g.GetComponent <Spellable> (); break; } } } //back to your regullarly scheduled push... if (spellableBlock != null) { if (otherPlayer == -1) { spellableBlock.ApplySpell(currentSpell [i], playerPos, Vector3.zero); } else { spellableBlock.ApplySpell(getSpellCombo(currentSpell [i], currentSpell [otherPlayer]), playerPos, getTile(players [otherPlayer].transform.position)); //check other player's spell limit players [otherPlayer].removeFirstActiveConditional(spellCosts[spell.DOUBLE_PUSH]); } //in case it was inside a void MeshRenderer rend = spellableBlock.gameObject.GetComponent <MeshRenderer> (); if (rend == null) { rend = spellableBlock.GetComponent <Pushblock> ().graphics; } rend.enabled = true; } //if player spell limit gets exceeded, remove first active players [i].removeFirstActiveConditional(spellCosts[spell.PUSH]); } //PULL else if (currentSpell [i].Equals(spell.PUSH) && otherPlayer != -1 && getSpellCombo(currentSpell[i], currentSpell[otherPlayer]).Equals(spell.PULL) && SpawnTiles.tileIsFree(spellPos)) { Vector3 toMoveRight = spellPos + Vector3.right * 2; Vector3 toMoveForward = spellPos + Vector3.forward * 2; Vector3 toMoveLeft = spellPos + Vector3.left * 2; Vector3 toMoveBack = spellPos + Vector3.back * 2; if (SpawnTiles.tileExists(toMoveRight) && SpawnTiles.blocks[toMoveRight].GetComponent <Pushblock>() != null) { moveAnyObject(toMoveRight, spellPos); Debug.Log("right"); } else if (SpawnTiles.tileExists(toMoveForward) && SpawnTiles.blocks[toMoveForward].GetComponent <Pushblock>() != null) { moveAnyObject(toMoveForward, spellPos); Debug.Log("forward"); } else if (SpawnTiles.tileExists(toMoveLeft) && SpawnTiles.blocks[toMoveLeft].GetComponent <Pushblock>() != null) { moveAnyObject(toMoveLeft, spellPos); Debug.Log("left"); } else if (SpawnTiles.tileExists(toMoveBack) && SpawnTiles.blocks[toMoveBack].GetComponent <Pushblock>() != null) { moveAnyObject(toMoveBack, spellPos); Debug.Log("back"); } //if player spell limit gets exceeded, remove first active players [i].removeFirstActiveConditional(spellCosts[spell.PULL]); players [otherPlayer].removeFirstActiveConditional(spellCosts[spell.PULL]); } //CREATE BLOCK/PUSHBLOCK else if (currentSpell [i].Equals(spell.CREATE_BLOCK) && (!SpawnTiles.tileExists(spellPos)) || (SpawnTiles.tileExists(spellPos) && SpawnTiles.blocks [spellPos].GetComponent <WaterManager> () != null)) { //destory current water block if (SpawnTiles.tileExists(spellPos)) { WaterManager currentWater = SpawnTiles.blocks [SpawnTiles.roundVector(spellPos)].GetComponent <WaterManager> (); Destroy(currentWater.gameObject); SpawnTiles.blocks.Remove(SpawnTiles.roundVector(spellPos)); } //now create block if (otherPlayer == -1) { GameObject tileClone = Instantiate(tile, spellPos, Quaternion.Euler(0, 0, 0)); SpawnTiles.blocks.Add(spellPos, tileClone); players [i].addActive(spellPos, spell.CREATE_BLOCK); Level.SetVertexColors(tileClone); } else if (getSpellCombo(currentSpell [i], currentSpell [otherPlayer]).Equals(spell.CREATE_PUSHBLOCK)) { GameObject pushblockClone = Instantiate(Pushblock, spellPos, Quaternion.Euler(0, 0, 0)); SpawnTiles.blocks.Add(spellPos, pushblockClone); //check other player's spell limit players [otherPlayer].addActive(spellPos, spell.CREATE_PUSHBLOCK); players [i].addActive(spellPos, spell.CREATE_PUSHBLOCK); } } //CREAT DESTROY/RAMP else if (currentSpell [i].Equals(spell.DESTROY)) { //destroy pushblocks and ramps if (otherPlayer == -1 && SpawnTiles.tileExists(spellPos) && (SpawnTiles.blocks[spellPos].GetComponent <Pushblock>() != null || SpawnTiles.blocks[spellPos].GetComponent <RampBehaviour>() != null)) { Destroy(SpawnTiles.blocks [spellPos].gameObject); SpawnTiles.blocks.Remove(spellPos); //check spell limit players [i].removeFirstActiveConditional(spellCosts [spell.DESTROY]); } //create ramp else if (!SpawnTiles.tileExists(spellPos) && SpawnTiles.tileExists(belowSpellPos) && getSpellCombo(currentSpell [i], currentSpell [otherPlayer]).Equals(spell.CREATE_RAMP)) { Vector3 dir = spellPos - players [i].pos; Debug.Log("Ramp building"); GameObject rampClone = Instantiate(ramp, spellPos, Quaternion.LookRotation(dir)); rampClone.GetComponent <RampBehaviour> ().upSlopeDirection = spellPos - players [i].pos; SpawnTiles.blocks.Add(spellPos, rampClone); Level.SetVertexColors(rampClone); //add active spells players [i].addActive(spellPos, spell.CREATE_RAMP); players [otherPlayer].addActive(spellPos, spell.CREATE_RAMP); } //create void else if (getSpellCombo(currentSpell [i], currentSpell [otherPlayer]).Equals(spell.CREATE_VOID)) { if (SpawnTiles.tileExists(spellPos)) { Destroy(SpawnTiles.blocks [spellPos].gameObject); SpawnTiles.blocks.Remove(spellPos); } GameObject bh = Instantiate(Voidblock, spellPos, Quaternion.Euler(0, 0, 0)); SpawnTiles.blocks.Add(spellPos, bh); //add active spells players [i].addActive(spellPos, spell.CREATE_VOID); players [otherPlayer].addActive(spellPos, spell.CREATE_VOID); } } //ADD ICE else if (currentSpell [i].Equals(spell.CREATE_ICE)) { //add ice if (otherPlayer == -1 && SpawnTiles.tileExists(belowSpellPos) && SpawnTiles.blocks [belowSpellPos].GetComponent <VoidManager> () == null && SpawnTiles.blocks [belowSpellPos].GetComponent <WaterManager> () == null) { SpawnTiles.blocks [belowSpellPos].AddComponent <IceManager> (); SpawnTiles.blocks [belowSpellPos].GetComponent <IceManager> ().updateMaterial(); //spell limit players [i].removeFirstActiveConditional(spellCosts [spell.CREATE_ICE]); } //ice above - note that it places ice on the top face of spellPos tile else if (SpawnTiles.tileExists(spellPos) && getSpellCombo(currentSpell [i], currentSpell [otherPlayer]).Equals(spell.ICE_ABOVE)) { GameObject above = SpawnTiles.blocks [spellPos]; if (above.GetComponent <IceManager> () == null && above.GetComponent <VoidManager> () == null && above.GetComponent <WaterManager> () == null) { above.AddComponent <IceManager> (); above.GetComponent <IceManager> ().updateMaterial(); //spell limit players [i].removeFirstActiveConditional(spellCosts [spell.ICE_ABOVE]); players [otherPlayer].removeFirstActiveConditional(spellCosts [spell.ICE_ABOVE]); } } //remove ice else if (SpawnTiles.tileExists(belowSpellPos) && getSpellCombo(currentSpell [i], currentSpell [otherPlayer]).Equals(spell.REMOVE_ICE)) { IceManager active = SpawnTiles.blocks [belowSpellPos].GetComponent <IceManager> (); if (active != null) { active.applyPastMaterial(); Destroy(active); } //spell limit players [i].removeFirstActiveConditional(spellCosts [spell.REMOVE_ICE]); players [otherPlayer].removeFirstActiveConditional(spellCosts [spell.REMOVE_ICE]); } } //Raise else if (currentSpell [i].Equals(spell.RAISE)) { //raise block if (otherPlayer == -1 && SpawnTiles.tileExists(spellPos) && !SpawnTiles.tileExists(aboveSpellPos)) { moveAnyObject(spellPos, aboveSpellPos); //spell limit players [i].removeFirstActiveConditional(spellCosts [spell.RAISE]); } //double raise else if (getSpellCombo(currentSpell [i], currentSpell [otherPlayer]).Equals(spell.DOUBLE_RAISE) && SpawnTiles.tileExists(spellPos) && !SpawnTiles.tileExists(aboveSpellPos + Vector3.up * 2)) { moveAnyObject(spellPos, aboveSpellPos + Vector3.up * 2); //spell limit players [i].removeFirstActiveConditional(spellCosts [spell.DOUBLE_RAISE]); players [otherPlayer].removeFirstActiveConditional(spellCosts [spell.DOUBLE_RAISE]); } //raise push else if (getSpellCombo(currentSpell [i], currentSpell [otherPlayer]).Equals(spell.RAISE_PUSH) && SpawnTiles.tileExists(spellPos)) { Vector3 upAndOver = new Vector3((spellPos.x - playerPos.x) + spellPos.x, spellPos.y + 2, (spellPos.z - playerPos.z) + spellPos.z); moveAnyObject(spellPos, upAndOver); //spell limit players [i].removeFirstActiveConditional(spellCosts [spell.RAISE_PUSH]); players [otherPlayer].removeFirstActiveConditional(spellCosts [spell.RAISE_PUSH]); } //lower else if (getSpellCombo(currentSpell [i], currentSpell [otherPlayer]).Equals(spell.LOWER) && SpawnTiles.tileExists(spellPos)) { moveAnyObject(spellPos, belowSpellPos); } //spell limit players [i].removeFirstActiveConditional(spellCosts [spell.LOWER]); players [otherPlayer].removeFirstActiveConditional(spellCosts [spell.LOWER]); } } else if (spellProgress [i] >= 0) { if (spellProgress[i] == 0) { players [i].spellSound.pitch = 1; players [i].spellSound.Stop(); players [i].spellSound.Play(); players [i].lastSpellFinished = false; } spellProgress [i] += spellSpeed * Time.deltaTime; } } else { spellProgress [i] = 0; if (!players[i].lastSpellFinished && players [i].spellSound.pitch > 0) { players [i].spellSound.pitch -= Time.deltaTime * 2; } } const float max = 0.7f; const float min = 0.03f; float c = Mathf.Clamp(max - (spellProgress[i] * (max - min)), min, max); selectorMaterials [i].SetFloat("_Cutoff", c); } }
public override void ApplySpell(SpellManager.spell spellType, Vector3 casterPosition, Vector3 casterPosition2) { switch (spellType) { case SpellManager.spell.PUSH: Vector3 newPosition = SpawnTiles.roundVector(transform.position * 2 - casterPosition); if (SpawnTiles.tileIsFree(newPosition) || (SpawnTiles.tileExists(newPosition) && SpawnTiles.blocks[newPosition].GetComponent <WaterManager>() != null) || (SpawnTiles.tileExists(newPosition) && SpawnTiles.blocks[newPosition].GetComponent <VoidManager>() != null)) { SpawnTiles.blocks.Remove(SpawnTiles.roundVector(transform.position)); if (SpawnTiles.tileExists(newPosition)) { if (SpawnTiles.blocks [newPosition].GetComponent <WaterManager> () != null) { Destroy(SpawnTiles.blocks [newPosition]); SpawnTiles.blocks.Remove(newPosition); SpawnTiles.blocks.Add(newPosition, gameObject); } else { //must be a void block VoidManager v = SpawnTiles.blocks [newPosition].GetComponent <VoidManager> (); v.addObject(gameObject); this.gameObject.GetComponent <MeshRenderer> ().enabled = false; } } else { SpawnTiles.blocks.Add(newPosition, gameObject); } transform.position = newPosition; } break; case SpellManager.spell.DOUBLE_PUSH: if (SpawnTiles.roundVector(casterPosition - transform.position) == SpawnTiles.roundVector(transform.position - casterPosition2)) { SpawnTiles.blocks.Remove(SpawnTiles.roundVector(transform.position)); Destroy(gameObject); } else { Vector3 midPosition = SpawnTiles.roundVector(transform.position * 2 - casterPosition); newPosition = SpawnTiles.roundVector(transform.position * 3 - casterPosition * 2); if (SpawnTiles.tileIsFree(midPosition)) { SpawnTiles.blocks.Remove(SpawnTiles.roundVector(transform.position)); if (SpawnTiles.tileIsFree(newPosition) || (SpawnTiles.tileExists(newPosition) && SpawnTiles.blocks[newPosition].GetComponent <WaterManager>() != null) || (SpawnTiles.tileExists(newPosition) && SpawnTiles.blocks[newPosition].GetComponent <VoidManager>() != null)) { //pushing into water block if (SpawnTiles.tileExists(newPosition)) { if (SpawnTiles.blocks [newPosition].GetComponent <WaterManager> () != null) { Destroy(SpawnTiles.blocks [newPosition]); SpawnTiles.blocks.Remove(newPosition); SpawnTiles.blocks.Add(newPosition, gameObject); } else { //must be a void block VoidManager v = SpawnTiles.blocks [newPosition].GetComponent <VoidManager> (); v.addObject(gameObject); this.gameObject.GetComponent <MeshRenderer> ().enabled = false; } } else { SpawnTiles.blocks.Add(newPosition, gameObject); } transform.position = newPosition; } else { SpawnTiles.blocks.Add(midPosition, gameObject); transform.position = midPosition; } } } break; } }