Exemplo n.º 1
0
    void FixedUpdate()
    {
        if (pauseMove)
        {
            return;
        }

        //Feuer Eis:
        if (Input.GetKey(KeyCode.Space) && !prevTapp)
        {
            IceManager.CallFireIce();
        }
        prevTapp = Input.GetKey(KeyCode.Space);

        if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.RightArrow))
        {
            hit          = Physics2D.Raycast((Vector2)transform.position + Vector2.down, Vector2.left, 1.4f, 1 << 11);
            rb.position += Vector2.left * pAttribute.real_vel * .6f * (hit.collider == null ? 1 : (hit.distance * hit.distance - 1f));
        }
        if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.LeftArrow))
        {
            hit          = Physics2D.Raycast((Vector2)transform.position + Vector2.down, Vector2.right, 1.4f, 1 << 11);
            rb.position += Vector2.right * pAttribute.real_vel * .6f * (hit.collider == null ? 1 : (hit.distance * hit.distance - 1f));
        }
        if (Input.GetKey(KeyCode.W) && proc.groundDist < .6f)
        {
            rb.velocity = new Vector2(rb.velocity.x, pAttribute.jumpPower);
        }
    }
Exemplo n.º 2
0
    private void Start()
    {
        iceManager = this;

        iceGravity   = gravity * Time.fixedDeltaTime;
        coneIceCount = 0;
    }
Exemplo n.º 3
0
    private void Update()
    {
#if (UNITY_ANDROID)
        //Feuer Eis:
        if (Input.touchCount > 0 && !prevTapp && !blockShoot)
        {
            IceManager.CallFireIce();
        }
        //blockShoot = false;
        prevTapp = Input.touchCount > 0;
#endif

        //Springen:
        if (Input.gyro.userAcceleration.z > thresh_jump && procMove.groundDist < .6f && !pauseMove)
        {
            rb.velocity = new Vector2(rb.velocity.x, (Input.gyro.userAcceleration.z > thresh_jump_max ? 1 : Input.gyro.userAcceleration.z / thresh_jump_max) * attribute.jumpPower);
        }
        //anim.SetBool("moving", isMoving && !pauseMove);
    }
Exemplo n.º 4
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);
        }
    }