Example #1
0
    public void RandomizeType()
    {
        powerupType = Random.Range(0, PowerupEffects.EffectTypes.Length);

        /* need powerup sprites.... for now use enemy sprites*/
        GetComponent <SpriteRenderer>().sprite = GameManager.Instance.PowerupSprites[powerupType];
        effect = PowerupEffects.EffectTypes[powerupType];
    }
Example #2
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;
            }
        }
    }
Example #3
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;
        }
    }
Example #4
0
    // Perform null checks and set values if effect's is not null
    // Set up post-effect restore values (if applicable) and start restore timer
    public void GotPowerup(PowerupEffect effect)
    {
        // initial value to the restore effect. Should get overwritten by another one if an effect is happening
        // otherwise just here as a fallback
        PowerupEffect restoreValuesEffect = new PowerupEffect {
            bulletScaling = BulletScaling
        };

        string effectType = "";

        if (effect.health != null)
        {
            health = (float)effect.health;
        }

        // if (effect.shield != null) shield = (float)effect.shield;        // TOOD: implement shield

        if (effect.bulletScaling != null)
        {
            restoreValuesEffect = new PowerupEffect {
                bulletScaling = BulletScaling
            };

            effectType    = "BulletScaling";
            BulletScaling = (float)effect.bulletScaling;
        }

        if (effect.shipScaling != null)
        {
            restoreValuesEffect = new PowerupEffect {
                shipScaling = ShipScaling
            };

            effectType  = "ShipScaling";
            ShipScaling = (float)effect.shipScaling;
        }

        if (effect.shootPattern != null)
        {
            restoreValuesEffect = new PowerupEffect {
                shootPattern = ShootPattern
            };

            effectType   = "ShootPattern";
            ShootPattern = effect.shootPattern;
        }

        if (effect.duration != null)
        {
            Timer effectTimer = TimerManager.Instance.CreateTimerOneshot((float)effect.duration);

            effectTimer.onFinish += () => {
                GotPowerup(restoreValuesEffect);      // apply the values from the restoreValuesEffect to return to a 'normal' state

                powerupEffectRestoreValues.Remove(effectType);
                powerupEffectDurations[effectType].Stop();
                powerupEffectDurations.Remove(effectType);
            };

            effectTimer.Start();

            // add or update the timer for this effect type
            if (powerupEffectDurations.ContainsKey(effectType))
            {
                powerupEffectDurations[effectType].Stop();
                powerupEffectDurations[effectType] = effectTimer;
            }
            else
            {
                powerupEffectDurations.Add(effectType, effectTimer);
            }

            // add or update the restore value effect struct for this effect type
            if (powerupEffectRestoreValues.ContainsKey(effectType))
            {
                powerupEffectRestoreValues[effectType] = restoreValuesEffect;
            }
            else
            {
                powerupEffectRestoreValues.Add(effectType, restoreValuesEffect);
            }
        }
    }
Example #5
0
 void Awake()
 {
     this.pwEffect = GetComponent <PowerupEffect>();
 }