Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        timeSpentSpinning += Time.deltaTime;
        float percentThrough = timeSpentSpinning / tweenTime;

        percentThrough = Mathf.Sqrt(percentThrough);
        if (percentThrough >= 1)
        {
            GameObject.Destroy(cubeIOwn.gameObject);
            percentThrough = 1;
        }
        Vector3    newPosition = Vector3.Lerp(startPosition, endPosition, percentThrough);
        Quaternion newRotation = Quaternion.Slerp(startRotation, endRotation, percentThrough);

        this.transform.position     = newPosition;
        cubeIOwn.transform.rotation = newRotation;
        this.transform.rotation     = Quaternion.Euler(0, percentThrough * 360, 0);
        if (percentThrough >= 1)
        {
            Vector2 screenSpace = toDrainEnergyFrom.cameraToShake.GetComponent <Camera>().WorldToScreenPoint(cubeIOwn.transform.position);
            Vector3 worldSpace  = mainCamera.ScreenToWorldPoint(new Vector3(screenSpace.x, screenSpace.y, 15));

            for (int x = 0; x < energyToDrain; x++)
            {
                PowerupEffect p = GameObject.Instantiate(powerupEffect);
                p.Initialize(worldSpace, toDrainEnergyFrom.pawn.transform.position, 0, type);
                p.duration = .5f;
                p.height   = .1f;
            }

            cubeIOwn.transform.parent = this.transform.parent;
            GameObject.Destroy(this.gameObject);
        }

        if (timeSpentSpinning > infusionParticleSpawnTime && !hasSpawnedParticles)
        {
            toDrainEnergyFrom.StartNewParticleBarrage();
            for (int x = 0; x < energyToDrain; x++)
            {
                Vector3       from = toDrainEnergyFrom.GetTargetOfParticle(PowerupType.ENERGY, -1);
                Vector3       to   = endPosition + new Vector3(-offset, 0, 0);
                PowerupEffect p    = GameObject.Instantiate(powerupEffect);
                p.Initialize(from, to, 0, PowerupType.ENERGY);
                hasSpawnedParticles = true;
            }
        }
    }
Esempio n. 2
0
    public void DropPiece()
    {
        //Place the cubes from the piece to the board.
        for (int x = 0; x < 3; x++)
        {
            for (int y = 0; y < 3; y++)
            {
                if (currentPiece.HasBlockAt(x, y))
                {
                    GameCube cube = currentPiece.GetCubeAt(x, y);
                    grid[currentPiecePosition.x + x - 1, currentPiecePosition.y + y - 1] = cube;
                    cube.transform.parent        = this.transform;
                    cube.transform.localPosition = new Vector3(currentPiecePosition.x - numCells.x / 2f + x - 1 + .5f, 0, currentPiecePosition.y - numCells.y / 2f + y - 1 + .5f);
                }
            }
        }

        //Check for squares
        List <GameCube> cubesToExplode = new List <GameCube>();

        int numberOfSquaresMade = 0;

        for (int x = 0; x < numCells.x - 2; x++)
        {
            for (int y = 0; y < numCells.y - 2; y++)
            {
                if (IsCornerOfSquare(x, y))
                {
                    AddCubesFromSquareToList(x, y, cubesToExplode);
                    numberOfSquaresMade++;
                }
            }
        }

        int numberOfParticles = numberOfSquaresMade * 3;

        List <float> delays = new List <float>();

        for (int x = 0; x < numberOfParticles; x++)
        {
            float delay = UnityEngine.Random.Range(0, Mathf.Sqrt(numberOfSquaresMade / 2));
            delays.Add(delay);
        }

        delays.Sort();

        player.StartNewParticleBarrage();

        foreach (float delay in delays)
        {
            if (player.HasRoomForMoreEnergy())
            {
                PowerupEffect pe         = GameObject.Instantiate <PowerupEffect>(powerUpEffect);
                GameCube      sourceCube = cubesToExplode[UnityEngine.Random.Range(0, cubesToExplode.Count)];
                pe.Initialize(sourceCube.transform.position, player.GetTargetOfParticle(PowerupType.ENERGY, 3), delay, PowerupType.ENERGY);
                InvisibleDelayedChargeGiver chargeGiver = GameObject.Instantiate <InvisibleDelayedChargeGiver>(chargeGiverPrefab);
                chargeGiver.target = player;
                chargeGiver.delay  = delay + 1;
                chargeGiver.type   = PowerupType.ENERGY;
                chargeGiver.SetAmountForOneCube(PowerupType.ENERGY);
                chargeGiver.amount /= 3; //(3 particles per square made);
            }
        }

        if (numberOfSquaresMade != 0)
        {
            matchSound.Play();
            if (numberOfSquaresMade >= 2)
            {
                Vector3    centroid       = FindCentroid(cubesToExplode);
                GameObject comboParticles = comboParticleHolder.comboParticles[numberOfSquaresMade].gameObject;
                GameObject go             = GameObject.Instantiate(comboParticles);
                go.transform.position = centroid;
            }
        }
        else
        {
            dropSound.Play();
        }

        //This is where we handle explosions based on tile color.
        for (int x = 0; x < numCells.x; x++)
        {
            for (int y = 0; y < numCells.y; y++)
            {
                if (grid[x, y] != null && cubesToExplode.Contains(grid[x, y]))
                {
                    //A cube that has exploded is on a tile. What kind?
                    switch (cellTypes[x, y])
                    {
                    case CellType.ATTACK:
                        cubeConversionManager.QueueCube(grid[x, y], PowerupType.ATTACK);
                        cubesToExplode.Remove(grid[x, y]);
                        grid[x, y] = null;
                        break;

                    case CellType.SHIELD:
                        cubeConversionManager.QueueCube(grid[x, y], PowerupType.SHIELDS);
                        cubesToExplode.Remove(grid[x, y]);
                        grid[x, y] = null;
                        break;
                    }
                }
            }
        }

        foreach (GameCube cube in cubesToExplode)
        {
            RemoveCubeFromGrid(cube);
            cube.Sink(UnityEngine.Random.Range(0, Mathf.Sqrt(numberOfSquaresMade)));
        }

        Destroy(currentPiece.gameObject);

        currentPiece = nextPiece;
        currentPiece.transform.parent = this.transform;
        currentPiecePosition          = new Vector2Int(1, 1);
        UpdateCurrentPieceTransform();

        nextPiece = MakeAPiece();
        nextPiece.transform.parent        = nextPieceHolder;
        nextPiece.transform.localPosition = Vector3.zero;

        prevPieceRotation = currentPieceRotation = 0;

        //For tutorials; hack in a callback;
        if (MissionManager.triggerCallbacksOnBlockDrop)
        {
            MissionManager.instance.grossCallbackHack.enabled = true;
        }
    }