/// <summary>Data for the standard snake consumable - Increases tail size and score.
    /// </summary>
    public override void OnConsumed(SnakeHead snakehead, Cell targetCell = null)
    {
        SnakeScoreHandler.UpdatedScore?.Invoke(scoreIncrease);
        snakehead.SnakeTail.TailNodesToAdd += tailNodesToAddWhenConsumed;

        OneShotAudioManager.PlayOneShot2D(AudioClipWhenConsumed);
        OneShotPFXManager.PlayPFX(targetCell.Vector2Position, PFXType.StdConsumableExplosion);
    }
Esempio n. 2
0
    /// <summary>Initializes the game. Should only be called once
    /// </summary>
    public void InitializeGame()
    {
        if (!FindObjectOfType <SnakeScoreHandler>())
        {
            Debug.LogWarning("No scorehandler was found in scene before play. No score will be shown");
        }

        #region MusicPlayer
        GameObject backgroundMusicPlayer = GameObject.Find("MusicPlayer");
        if (!backgroundMusicPlayer && BackgroundMusicSong)
        {
            backgroundMusicPlayer = new GameObject("MusicPlayer");
        }
        if (BackgroundMusicSong)
        {
            backgroundMusicPlayer.AddComponent <AudioSource>().clip = BackgroundMusicSong;
            backgroundMusicPlayer.GetComponent <AudioSource>().loop = true;
            backgroundMusicPlayer.GetComponent <AudioSource>().Play();
            backgroundMusicPlayer.GetComponent <AudioSource>().volume = 0.1f;
            DontDestroyOnLoad(backgroundMusicPlayer);
        }
        #endregion MusicPlayer

        //Initializes the static classes
        OneShotAudioManager.SetupObjectPool(5);
        OneShotPFXManager.SetUpObjectPool();

        //Create Grid
        var cellGrid = levelGridData.GenerateGrid();
        CellGridUtility.Grid = cellGrid;

        //Create Player
        var Snake = snakeData.GenerateSnake();
        Snake.GetComponent <CellOccupant>().CurrentCell = cellGrid
                                                          [levelGridData.SnakeStartPositionX, levelGridData.SnakeStartPositionY];

        //Create Spawners
        for (int i = 0; i < TimedSpawns.Length; i++)
        {
            TimedSpawns[i].CreateTimedSpawner(cellGrid);
        }

        //Place Camera and set settings
        var GridSizeX = levelGridData.GridSizeX;
        var GridSizeY = levelGridData.GridSizeY;
        Camera.main.transform.position = new Vector3((GridSizeX - 1) / 2, (GridSizeY * 1.1f - 1) / 2, -10);
        Camera.main.orthographicSize   = GridSizeY / 1.75f;

        GameLoopUtility.OnGameStart?.Invoke();
    }
Esempio n. 3
0
    private void OnPortalEnter(Portal senderPortal, Collider collider)
    {
        Vector3 offset = senderPortal.transform.position - collider.transform.position;

        switch (collider.tag)
        {
        case "Projectile":
            var projectile = collider.GetComponent <Projectile>();
            projectile.CanPickup = false;

            var rgb = projectile.rgb;
            rgb.MovePosition(postTeleportPosition.position);

            Vector3 originalVelocity = projectile.actualVelocity;
            //Vector3 newVelocity = Vector3.Reflect(originalVelocity, transform.up);
            //newVelocity.y = 0f; // keep vector in x,z and ignore y
            Vector3 newVelocity = originalVelocity;

            // rotate new velocity according to both portals' rotations
            float      rotationDiff       = senderPortal.transform.rotation.eulerAngles.y - transform.rotation.eulerAngles.y;
            Quaternion correctiveRotation = Quaternion.Euler(0f, rotationDiff, 0f);
            newVelocity = correctiveRotation * newVelocity;

            // set actual velocity
            projectile.actualVelocity = newVelocity;

            // apply force
            rgb.velocity = Vector3.zero;
            rgb.AddForce(newVelocity.normalized * portalSettings.PostTeleportForce, ForceMode.Impulse);
            rgb.angularVelocity = Vector3.zero;

            OneShotAudioManager.PlayOneShotAudio(portalSettings.teleportationSounds, transform.position, 1f);

            Debug.DrawRay(opposingPortal.transform.position, originalVelocity, Color.red, 5f);
            Debug.DrawRay(transform.position, newVelocity, Color.green, 5f);
            break;

        case "Player":
            Debug.Log("Player Teleported");
            break;
        }
    }
Esempio n. 4
0
    /// <summary>Spawns a consumable from the objectpool at a random position in the grid
    private void SpawnConsumable(ConsumableSpawnData spawnData)
    {
        (bool foundCell, Cell targetEmptyCell) = CellGridUtility.FindRandomEmptyCell(40);
        if (!foundCell)
        {
            return;
        }

        var objectToSpawn = ObjectPool.Rent(true);

        //Assigns data. Can't be done when initializing for some reason.
        objectToSpawn.GetComponent <Consumable>().ConsumableData = spawnData.ConsumableData;
        objectToSpawn.GetComponent <CellOccupant>().CurrentCell  = targetEmptyCell;

        var spawnAudioClip = spawnData.ConsumableData.AudioClipWhenSpawned;

        if (spawnAudioClip)
        {
            OneShotAudioManager.PlayOneShot2D(spawnAudioClip);
        }
    }
    private void OnBeat()
    {
        if (!GameManager.Instance.gameInProgress)
        {
            return;
        }

        // cache
        Renderer renderer;

        // disable old dir
        for (int i = 0; i < oldIterationRenderers.Length; i++)
        {
            renderer = oldIterationRenderers[i];
            if (renderer == null)
            {
                break;
            }
            renderer.material = greyedColor;
        }

        // enable current dir
        int startIndex = amtPerDir * (currentIteration = currentIteration > 2 ? 0 : currentIteration + 1);

        for (int i = 0; i < amtPerDir; i++)
        {
            renderer = renderers[startIndex + i];
            if (renderer == null)
            {
                return;
            }
            renderer.material        = globalColor;
            oldIterationRenderers[i] = renderer;
        }

        // shoot projectile
        {
            var projectile = manager.SpawnObject(projectilePrefab).GetComponent <Projectile>();

            projectile.transform.position = launchPositions[currentIteration].position;
            projectile.rgb.WakeUp();
            projectile.rgb.useGravity      = true;
            projectile.ownCollider.enabled = true;

            // launch projectile in aim direction
            var forceVec = launchPositions[currentIteration].position - transform.position;
            forceVec.y = 0f;

            Vector3 shotVec = forceVec.normalized * settings.ShotStrength;
            projectile.rgb.AddForce(shotVec, ForceMode.Impulse);
            projectile.actualVelocity = shotVec;             // for portal/wall bounces

            projectile.InitialShooter = null;
            projectile.wallHitVol     = .4f;
            OneShotAudioManager.PlayOneShotAudio(settings.ProjectileShotSounds, launchPositions[currentIteration].position, .4f);
        }
        if (Time.timeScale < .01f)
        {
            StartCoroutine(OnBeatDelayed());
        }
        else
        {
            music.RegisterCallOnNextBeat(OnBeat, beatDelay, false);
        }
    }