private IEnumerator DeathAnimation()
        {
            if (m_deathFX)
            {
                m_deathFX.Play(transform, Vector3.zero, m_pool);
            }
            m_camShakeEvent.Raise();
            if (m_asset.IsPlayer())
            {
                m_togglePanWideOffsetEvent.Raise(true);
            }

            yield return(new WaitForSeconds(3f));
        }
Beispiel #2
0
    protected virtual void SwitchEntered()
    {
        this.ToggleState();

        if (AudioManager.instance != null)
        {
            AudioManager.instance.PlaySound("OnOff");
        }



        foreach (IObject iobject in LinkedObjects)
        {
            iobject.ToggleState();
            if (iobject.persistent)
            {
                if (!ActivatedPersistentObjects.Contains(iobject))
                {
                    ActivatedPersistentObjects.Add(iobject);
                }
            }
        }

        // Triggers player to recalculate their jump distance in case new blocks obstruct their path
        if (eventCooldownTimer.Finished && !eventCooldownTimer.Running)
        {
            JumpInterruptEvent.Raise();
            eventCooldownTimer.Run();
        }
    }
Beispiel #3
0
 private void ReadPauseInput()
 {
     if (Input.touchCount == 3)
     {
         GamePauseEvent.Raise();
     }
 }
Beispiel #4
0
 /// <summary>
 /// Sent when another object enters a trigger collider attached to this
 /// object (2D physics only).
 /// </summary>
 /// <param name="other">The other Collider2D involved in this collision.</param>
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Player")
     {
         PlayerDeathEvent.Raise();
     }
 }
Beispiel #5
0
 private void ReadPauseInput()
 {
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         GamePauseEvent.Raise();
     }
 }
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.O))
     {
         m_startCountdownEvent.Raise();
     }
 }
Beispiel #7
0
        public void OnAnyKeyDown()
        {
            if (m_currentState == DCCurrentState.levelIntro && !m_blockInteractions)
            {
                m_currentState = DCCurrentState.countdown;
                m_closeLevelIntroEvent.Raise();
                m_unitPlacer.PlaceUnits();
                m_startCountdownEvent.Raise();
            }

            if (!m_blockInteractions && (m_currentState == DCCurrentState.gameWon || m_currentState == DCCurrentState.gameLost))
            {
                //transitions and UI etc
                StartCoroutine(LoadFirstLevel());
                //reset scoring etc.
            }

            //only for debugging
            if (m_currentState == DCCurrentState.gameplay)
            {
                if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    Debug.Log("1 pressed: go to win state");
                    OnGameWon();
                }
                if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    Debug.Log("2 pressed: go to lose state");
                    OnGameLost();
                }
                if (Input.GetKeyDown(KeyCode.Alpha3))
                {
                    Debug.Log("3 pressed: lost a life");    //this will be notified via a void event
                    OnLifeLost();
                }
                if (Input.GetKeyDown(KeyCode.Alpha4))
                {
                    Debug.Log("4 pressed: level complete");    //this will be notified via a void event
                    OnLevelComplete();
                }
            }
        }
Beispiel #8
0
 public void OnPauseChange(bool newIsPaused)
 {
     if (newIsPaused)
     {
         transitionToBlack.Raise();
     }
     else
     {
         transitionToView.Raise();
     }
 }
Beispiel #9
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.tag == "Player")
     {
         if (AudioManager.instance != null)
         {
             AudioManager.instance.StopSound("ElecOn");
         }
         LevelFinished.Raise();
     }
 }
        private void Start()
        {
            var offsetX = .5f;
            var offsety = .5f;

            Grid.Node[,] nodes = new Grid.Node[width, height];

            StringBuilder sb = new StringBuilder();

            for (int x = 0; x < width; ++x)
            {
                for (int y = 0; y < height; ++y)
                {
                    var worldPosition = new Vector3(x + bottomLeft.x + offsetX, y + bottomLeft.y + offsety);
                    var cellPos       = impassable.WorldToCell(worldPosition);
                    var tile          = impassable.GetTile(cellPos);

                    if (tile)
                    {
                        nodes[x, y] = new Grid.Node(x, y, -1, worldPosition);

                        sb.Append(", -1");

                        continue;
                    }


                    cellPos = impassable.WorldToCell(worldPosition);

                    tile = passable.GetTile(cellPos);

                    if (tile)
                    {
                        nodes[x, y] = new Grid.Node(x, y, 1, worldPosition);
                        sb.Append(",  1");
                        continue;
                    }

                    nodes[x, y] = new Grid.Node(x, y, -2, worldPosition);
                    sb.Append(", -2");
                }

                sb.Append("\n");
            }

            //   Debug.Log("grid:\n" + sb.ToString());

            _grid = new SquareGrid(nodes, bottomLeft);

            output.Value = _grid;
            onGridGenerated.Raise();
        }
Beispiel #11
0
        private IEnumerator LoadFirstLevel()
        {
            //pause and transition
            m_currentState      = DCCurrentState.loadingLevel;
            m_blockInteractions = true;
            m_pausePlayEvent.Raise(true);
            m_requestPauseGameEvent.Raise(true);
            m_enterTransitionEvent.Raise();
            yield return(new WaitForSeconds(m_transitionDuration.Value));

            //load level
            m_levels.SetupFirstLevel(m_terrainGen);
            m_unitPlacer.SetLevelAsset(m_levels.CurrentLevel());
            yield return(new WaitForSeconds(1f));

            m_exitTransitionEvent.Raise();
            yield return(new WaitForSeconds(m_transitionDuration.Value));

            //show intro
            m_requestIntroUIEvent.Raise(m_levels.CurrentLevel());
            m_currentState      = DCCurrentState.levelIntro;
            m_blockInteractions = false;
        }
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.P))
     {
         if (!isPaused)
         {
             startTransitionEvent.Raise();
         }
         else
         {
             endTransitionEvent.Raise();
         }
         isPaused = !isPaused;
     }
 }
Beispiel #13
0
        private IEnumerator DoCountdown()
        {
            m_TMProText.text = "3";
            m_TMProText.gameObject.SetActive(true);

            yield return(new WaitForSecondsRealtime(m_interval));

            m_TMProText.text = "2";

            yield return(new WaitForSecondsRealtime(m_interval));

            m_TMProText.text = "1";

            yield return(new WaitForSecondsRealtime(m_interval));

            m_TMProText.text = "GO";

            yield return(new WaitForSecondsRealtime(m_interval));

            m_TMProText.gameObject.SetActive(false);

            m_countdownCompleteEvent.Raise();
        }
        private IEnumerator BuildRoom()
        {
            LevelDefinition level          = new LevelDefinition();
            var             adjustedHeight = height + 4;
            var             adjustedWidth  = width + 4;

            char[,] roomChars = new char[adjustedWidth, adjustedHeight];
            char playerEntrance = 'b';

            bool levelParsed = false;

            while (!levelParsed)
            {
                try
                {
                    level = PickRoom(out playerEntrance, out var flipX, out var flipY);
                    var roomString = level.Level;
                    // var roomString = room.Template;

                    roomChars = StringToCharTable(width, height, roomString);

                    roomChars = ExpandChunks(roomChars);

                    roomChars = AddBorder(roomChars);

                    if (flipX)
                    {
                        roomChars = FlipX(roomChars, adjustedWidth, adjustedHeight);
                    }

                    if (flipY)
                    {
                        roomChars = FlipY(roomChars, adjustedWidth, adjustedHeight);
                    }


                    levelParsed = true;
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    // without this we have no game, pick a a new room and try again
                }
            }

            var grid = new Grid.Node[adjustedWidth, adjustedHeight];

            int        tileIdx       = 0;
            Vector3Int pos           = Vector3Int.zero;
            Vector2    worldPos      = Vector2.zero;
            bool       playerSpawned = false;

            var enemySpawnPoints       = new List <Vector3Int>();
            var terrainSpawnPoints     = new List <Vector3Int>();
            var lootSpawnPoints        = new List <Vector3Int>();
            var specialLootSpawnPoints = new List <Vector3Int>();

            for (int y = 0; y < adjustedHeight; ++y)
            {
                pos.y      = y;
                worldPos.y = y + .5f;

                for (int x = 0; x < adjustedWidth; ++x)
                {
                    pos.x      = x;
                    worldPos.x = x + .5f;


                    switch (roomChars[x, y])
                    {
                    case 'c':
                    {
                        chasm.SetTile(pos, tiles.ChasmTiles.RandomElement());
                        var go = Instantiate(tiles.Chasm, worldPos, Quaternion.identity);
                        go.transform.parent = chasmParent;
                        grid[x, y]          = new Grid.Node(x, y, -2, worldPos);
                        break;
                    }

                    case 'u':
                    {
                        var go = Instantiate(tiles.UnbreakableWall, worldPos, Quaternion.identity);
                        go.transform.parent = unbreakableParent;
                        grid[x, y]          = new Grid.Node(x, y, -2, worldPos);
                        break;
                    }

                    case 'w':
                    {
                        walls.SetTile(pos, tiles.Wall);
                        floor.SetTile(pos, tiles.FloorTiles.RandomElement());
                        grid[x, y] = new Grid.Node(x, y, 1, worldPos);
                        break;
                    }

                    case 'b':     // entry/exit
                    {
                        playerSpawned = SpawnEntrance(
                            'b',
                            playerEntrance,
                            playerSpawned,
                            worldPos,
                            Vector2.down,
                            tiles.BottomExit
                            );

                        floor.SetTile(pos, tiles.FloorTiles.RandomElement());
                        grid[x, y] = new Grid.Node(x, y, 1, worldPos);
                        break;
                    }

                    case 'l':     // entry/exit
                    {
                        playerSpawned = SpawnEntrance(
                            'l',
                            playerEntrance,
                            playerSpawned,
                            worldPos,
                            Vector2.left,
                            tiles.LeftExit
                            );

                        floor.SetTile(pos, tiles.FloorTiles.RandomElement());
                        grid[x, y] = new Grid.Node(x, y, 1, worldPos);
                        break;
                    }

                    case 't':     // entry/exit
                    {
                        playerSpawned = SpawnEntrance(
                            't',
                            playerEntrance,
                            playerSpawned,
                            worldPos,
                            Vector2.up,
                            tiles.TopExit
                            );

                        floor.SetTile(pos, tiles.FloorTiles.RandomElement());
                        grid[x, y] = new Grid.Node(x, y, 1, worldPos);
                        break;
                    }

                    case 'r':     // entry/exit
                    {
                        playerSpawned = SpawnEntrance(
                            'r',
                            playerEntrance,
                            playerSpawned,
                            worldPos,
                            Vector2.right,
                            tiles.RightExit
                            );

                        floor.SetTile(pos, tiles.FloorTiles.RandomElement());
                        grid[x, y] = new Grid.Node(x, y, 1, worldPos);
                        break;
                    }

                    case 'n':     // entry/exit
                    {
                        floor.SetTile(pos, tiles.FloorTiles.RandomElement());
                        grid[x, y] = new Grid.Node(x, y, 1, worldPos);
                        break;
                    }

                    case 'h':     // high value item
                    {
                        specialLootSpawnPoints.Add(pos);
                        floor.SetTile(pos, tiles.FloorTiles.RandomElement());
                        grid[x, y] = new Grid.Node(x, y, 1, worldPos);
                        break;
                    }

                    default:     // must be floor so can spawns ememies and loot here
                    {
                        enemySpawnPoints.Add(pos);
                        terrainSpawnPoints.Add(pos);
                        lootSpawnPoints.Add(pos);

                        floor.SetTile(pos, tiles.FloorTiles.RandomElement());
                        grid[x, y] = new Grid.Node(x, y, 1, worldPos);
                        break;
                    }
                    }

                    if (timelapse > 0)
                    {
                        yield return(new WaitForSeconds(timelapse));
                    }
                }
            }

            var enemiesAmount = UnityEngine.Random.Range(level.MinEnemies, level.MaxEnemies + 1);
            var terrainAmount = UnityEngine.Random.Range(level.MinTerrain, level.MaxTerrain + 1);
            var itemsAmount   = UnityEngine.Random.Range(level.MinItems, level.MaxItems + 1);

            while (enemySpawnPoints.Count > 0 && enemiesAmount > 0)
            {
                var point = enemySpawnPoints.RandomElement();
                worldPos = new Vector2(point.x + .5f, point.y + .5f);

                var spawned = false;
                foreach (var enemy in tiles.Enemies)
                {
                    if (UnityEngine.Random.Range(1, enemy.Second) == 1)
                    {
                        var go = Instantiate(enemy.First, worldPos, Quaternion.identity);
                        go.transform.parent = enemiesParent;
                        spawned             = true;
                        break;
                    }
                }

                if (spawned)
                {
                    --enemiesAmount;
                    enemySpawnPoints.Remove(point);
                }
            }


            while (terrainSpawnPoints.Count > 0 && terrainAmount > 0)
            {
                var point = terrainSpawnPoints.RandomElement();
                worldPos = new Vector2(point.x + .5f, point.y + .5f);

                var spawned = false;
                foreach (var terrain in tiles.Terrain)
                {
                    if (UnityEngine.Random.Range(1, terrain.Second) == 1)
                    {
                        var go = Instantiate(terrain.First, worldPos, Quaternion.identity);
                        go.transform.parent = terrainParent;
                        spawned             = true;
                        break;
                    }
                }

                if (spawned)
                {
                    --terrainAmount;
                    terrainSpawnPoints.Remove(point);
                }
            }

            while (lootSpawnPoints.Count > 0 && itemsAmount > 0)
            {
                var point = lootSpawnPoints.RandomElement();
                worldPos = new Vector2(point.x + .5f, point.y + .5f);

                var spawned = false;
                foreach (var item in tiles.Items)
                {
                    if (UnityEngine.Random.Range(1, item.Second) == 1)
                    {
                        var go = Instantiate(tiles.Pickup, worldPos, Quaternion.identity);
                        // go.transform.parent = enemiesParent;
                        go.GetComponent <PickUpBehaviour>().SetItem(item.First);

                        spawned = true;
                        break;
                    }
                }

                if (spawned)
                {
                    --itemsAmount;
                    lootSpawnPoints.Remove(point);
                }
            }



            output.Value = new SquareGrid(grid, Vector2.zero);
            yield return(null);

            onGridBuilt.Raise();
            yield break;
        }
Beispiel #15
0
 public void ResumeGame()
 {
     GameResumeEvent.Raise();
 }
Beispiel #16
0
 public void ToggleTouchScreenMode()
 {
     isTouchScreenMode = !isTouchScreenMode;
     TouchScreenToggleEvent.Raise();
 }
Beispiel #17
0
 public void NotifyAllBaddiesDead()
 {
     m_allBaddiesDeadEvent.Raise();
 }