Пример #1
0
    public void StartGame()
    {
        // Fetch Scripts
        GameObject gameScripts = GameObject.Find("GameScripts");

        spawnTiles       = gameScripts.GetComponent <SpawnTiles>();
        actionManager    = gameScripts.GetComponent <ActionManager>();
        turnManager      = gameScripts.GetComponent <TurnManager>();
        uiManager        = gameScripts.GetComponent <UIManager>();
        inputHandler     = gameScripts.GetComponent <InputHandler>();
        cameraController = gameScripts.GetComponent <CameraController>();

        // Create Map to play on
        spawnTiles.CreateMap(Seed, RoundMap, Mountains);

        // Initialize scripts in a certain order
        actionManager.Initialize();
        uiManager.Initialize();
        inputHandler.Initialize();
        turnManager.Initialize();

        foreach (Player player in Players)
        {
            turnManager.AddPlayer(player);
        }

        uiManager.UpdateCurrentPlayer(turnManager.GetCurrentPlayer());
        uiManager.UpdateResources(
            turnManager.GetCurrentPlayer().GetStone(),
            turnManager.GetCurrentPlayer().GetWood(),
            turnManager.GetCurrentPlayer().GetWheat(),
            turnManager.GetCurrentPlayer().GetCoins());
    }
Пример #2
0
        private bool TryAddNonStandardTiles(MapTile tile, Point location)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases (cases are covered elsewhere)
            switch (tile)
            {
            case MapTile.Key:
                Items.Add(new Key(location, this));
                break;

            case MapTile.Compass:
                Items.Add(new Compass(location));
                break;

            case MapTile.Map:
                Items.Add(new Map(location));
                break;

            case MapTile.Bow:
                Items.Add(new BowItem(location, Secondary.Bow, 10));
                break;

            case MapTile.Triforce:
                Items.Add(new Triforce(location));
                break;

            case MapTile.PushableBlock:
                var pushableBlock = new MovableBlock(location);
                Collidables.Add(pushableBlock);
                Drawables.Add(pushableBlock);
                TransitionResetables.Add(pushableBlock);
                break;

            case MapTile.SpawnEnemy:
                SpawnTiles.Add(location);
                break;

            case MapTile.Sand:
                Drawables.Add(new Overlay(location, BlockType.Sand));
                break;

            case MapTile.Heart:
                Items.Add(new HeartContainer(location, this));
                break;

            case MapTile.Boomerang:
                Items.Add(new BoomerangItem(location, this, 20));
                break;

            case MapTile.BasementBricks:
            case MapTile.BlackOverlay:
            case MapTile.None:
            case MapTile.Room2_1Block:
                break;

            default:
                return(false);
            }

            return(true);
        }
Пример #3
0
 void Start()
 {
     if (debug)
     {
         blocks = new Dictionary <Vector3, GameObject> ();
         spawnTilesPlease();
         instance = this;
     }
 }
Пример #4
0
    public void AssignLists()
    {
        c_SpawnTiles = FindObjectOfType <SpawnTiles>();

        if (c_SpawnTiles != null)
        {
            bounds = c_SpawnTiles.currentBounds;
            StartCoroutine(CreatePattern(pulseTime));
        }
    }
Пример #5
0
 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;
     }
 }
    void Refresh()
    {
        bool pushed = !SpawnTiles.tileIsFree(transform.position);

        foreach (DoorBehaviour d in doors)
        {
            d.SetPassable(pushed);
        }

        buttonObject.position = pushed ? buttonPos + Vector3.down * 0.2f : buttonPos;
    }
Пример #7
0
    // Use this for initialization
    void Start()
    {
        sphere     = GameObject.Find("Sphere");
        spawntiles = sphere.GetComponent <SpawnTiles>();


        MusicSource.clip = MusicClip;
        if (spawntiles.muted == false)
        {
            MusicSource.Play();
        }
        else
        {
            MusicSource.Stop();
        }
    }
Пример #8
0
    IEnumerator GenerateAmbientOcclusion()
    {
        int count = 0;

        foreach (GameObject g in AOTargets)
        {
            Mesh    m      = g.GetComponent <MeshFilter> ().mesh;
            Color[] colors = m.colors;
            if (colors.Length == 0)
            {
                colors = new Color[m.vertices.Length];
                for (int i = 0; i < m.vertices.Length; i++)
                {
                    colors [i] = Color.white;
                }
            }
            for (int i = 0; i < m.vertices.Length; i++)
            {
                Vector3 localPos = g.transform.TransformPoint(m.vertices [i]) - g.transform.position;
                Vector3 normal   = g.transform.TransformDirection(m.normals [i]).normalized;
                if (Mathf.Abs(normal.x) + Mathf.Abs(normal.y) + Mathf.Abs(normal.z) > 1.1f)
                {
                    continue;
                }
                foreach (Vector3 v in new Vector3[] { Vector3.up, Vector3.forward, Vector3.right, Vector3.zero })
                {
                    float   angle      = Vector3.Angle(v, normal);
                    Vector3 projection = normal;
                    if (angle > 5 && angle < 175)
                    {
                        projection = localPos - v * Vector3.Dot(localPos, v);
                    }
                    if (isAOTarget(SpawnTiles.roundVector(g.transform.position + projection * 2)))
                    {
                        colors [i] *= new Color(0.6f, 0.6f, 0.6f);
                    }
                }
            }
            // assign the array of colors to the Mesh.
            m.colors = colors;
            if ((count++) % 100 == 0)
            {
                yield return(null);
            }
        }
    }
Пример #9
0
    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))
             ));
    }
 void Update()
 {
     foreach (Player p in PlayerManager.staticPlayers)
     {
         if (SpawnTiles.round2Vector(p.transform.position) != SpawnTiles.round2Vector(transform.position + Vector3.up))
         {
             active = true;
             return;
         }
     }
     if (active)
     {
         foreach (Player p in PlayerManager.staticPlayers)
         {
             p.transform.position = other.transform.position + Vector3.up + p.offset() * 0.5f;
         }
         other.active = false;
     }
 }
 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;
     }
 }
Пример #12
0
    protected override void OnStartRunning()
    {
        m_EntityCommandBuffer = m_Barrier.CreateCommandBuffer();

        EntityArchetype tileArch = EntityManager.CreateArchetype(typeof(GridData), typeof(Translation), typeof(LocalToWorld));

        tile = m_EntityCommandBuffer.CreateEntity(tileArch);

        var spawnJob = new SpawnTiles
        {
            commandBuffer = m_EntityCommandBuffer,
            tile          = tile
        };
        JobHandle spawnJobHandle = spawnJob.Schedule(this);

        m_Barrier.AddJobHandleForProducer(spawnJobHandle);

        spawnJobHandle.Complete();

        m_EntityCommandBuffer.DestroyEntity(tile);
    }
Пример #13
0
    public Tile[,,] ReadMap(Transform parentContainer)
    {
        Size = Vector3Int.one * -1;
        Bounds mapBounds = new Bounds();

        foreach (Transform t in parentContainer)
        {
            Tile tile = t.GetComponent <Tile>();
            if (tile != null)
            {
                mapBounds.Encapsulate(tile.position);
            }
        }
        Size = mapBounds.size.Round() + Vector3Int.one;
        Vector3Int offset = mapBounds.min.Round();

        Tile[,,] tiles = new Tile[Size.x, Size.y, Size.z];
        foreach (Transform t in parentContainer)
        {
            Tile tile = t.GetComponent <Tile>();
            if (tile != null)
            {
                Vector3Int pos = tile.position - offset;
                tiles[pos.x, pos.y, pos.z] = tile;
                switch (tile.Type)
                {
                case Tile.TileType.SpawnPoint:
                    SpawnTiles.Add((SpawnTile)tile);
                    break;

                case Tile.TileType.Item:
                    ItemTiles.Add((ItemTile)tile);
                    break;
                }
            }
        }
        return(tiles);
    }
    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;
            }
        }
    }
Пример #15
0
    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;
        }
    }
    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);
            }
        }
    }
Пример #17
0
    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);
        }
    }
Пример #18
0
 private void Awake()
 {
     instance = this;
 }
Пример #19
0
    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();
        }
    }