Ejemplo n.º 1
0
    private void ReviewLevelState(EnemyShipBody ship)
    {
        Score += ship.points;

        if (EnemyManager.amountEnemies == 0)
        {
            GameObject player = GameObject.FindWithTag("Player");
            if (player == null)
            {
                Debug.Log("Player not found");
                return;
            }
            else if (!player.activeInHierarchy)
            {
                return;
            }

            //NEXT LEVEL
            LevelComplete?.Invoke();
        }
        else if (EnemyManager.amountEnemies < 0)
        {
            Debug.LogError("AmountEnemies can't be less than 0");
        }
    }
Ejemplo n.º 2
0
    private void ElementHitHandler(PoleElementController poleElement)
    {
        if (poleElement.isBoss)
        {
            if (poleElement.BossPower == 0)
            {
                onLevelComplete.Invoke(this);
            }
        }
        else
        {
            PoleElements.Remove(poleElement);

            if (PoleElements.Count > 0)
            {
                PoleElements[0].meshCollider.enabled = true;
            }
            else if (PoleElements.Count == 0)
            {
                Obstacle.Rotator.StopRotating();
                Obstacle.RiseTheObstacle(-1);
            }

            lowerTarget -= 0.5f;
            LoweringThePole();
        }

        Count         = PoleElements.Count + LastBlock.BossPower;
        txtCount.text = Count.ToString("00");
    }
Ejemplo n.º 3
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         LevelComplete.Invoke();
     }
 }
Ejemplo n.º 4
0
        public void OnSpaceOrEnterPressed()
        {
            var wordToMatch = _wordsToMatch[_currentWordIndex];

            if (wordToMatch == EnteredText)
            {
                WordsToType[_currentWordIndex].Active    = false;
                WordsToType[_currentWordIndex].Completed = true;

                var curWordTupple = WordsToType[_currentWordIndex].Text;
                curWordTupple.Compare = "";
                WordsToType[_currentWordIndex].Text = curWordTupple;

                CurrentWordIndex++;

                if (_currentWordIndex < WordsToType.Count)
                {
                    WordsToType[_currentWordIndex].Active = true;
                    WordToMatch = WordsToType[_currentWordIndex].Text.Display;
                }
                else
                {
                    _endTime = DateTime.Now;
                    UpdateCompletedMessage();
                    LevelComplete?.Invoke(this, new EventArgs());
                }
                EnteredText = "";
            }
            else
            {
                EnteredText = "";
                OnTextChanged();
            }
        }
        void OnTriggerEnter(Collider other)
        {
            if (0 != (layers.value & 1 << other.gameObject.layer))
            {
                ExecuteOnEnter(other);

                if (gameObject.name == "DoorSwitch1")
                {
                    timerSwitch1 = Time.time - EventHandler.eventhandler.GetStartTime();
                    SwitchTimerEvent?.Invoke(1, timerSwitch1);
                }

                if (gameObject.name == "Switch")
                {
                    timerSwitch2 = Time.time - EventHandler.eventhandler.GetStartTime();
                    SwitchTimerEvent?.Invoke(2, timerSwitch2);
                }

                if (gameObject.name == "Switch (1)")
                {
                    timerSwitch3 = Time.time - EventHandler.eventhandler.GetStartTime();
                    SwitchTimerEvent?.Invoke(3, timerSwitch2);
                }

                if (gameObject.name == "InfoZone_InsideBox")//Key
                {
                    timerKey = Time.time - EventHandler.eventhandler.GetStartTime();
                    KeyTimerEvent?.Invoke(timerKey);
                }

                // Porta 1 = "PressurePad"
                // Switch 1 = "DoorSwitch1"
                // Switch 2 = "Switch"
                // Switch 3 = "Switch (1)"

                if (gameObject.name == "InfoZone_End")//End Level
                {
                    finalTimer = Time.time - EventHandler.eventhandler.GetStartTime();
                    LevelCompleteEvent?.Invoke(finalTimer);
                }
            }
        }
Ejemplo n.º 6
0
    /// <summary>
    /// Change the current level state
    /// </summary>
    /// <param name="state"></param>
    protected virtual void ChangeLevelState(LevelState newState)
    {
        if (CurrentLevelState == newState)
        {
            return;
        }

        LevelState oldState = CurrentLevelState;

        CurrentLevelState = newState;
        LevelStateChanged?.Invoke(oldState, newState);

        switch (newState)
        {
        case LevelState.Complete:
            LevelStats.time = LevelTime - TimeLeft;
            LevelComplete?.Invoke();
            break;

        case LevelState.Failed:
            LevelFailed?.Invoke();
            break;
        }
    }
Ejemplo n.º 7
0
    public void CheckFilledTiles()
    {
        WPTile previousWpTile = _map[gridSize - 1, 0];
        WPTile currentWpTile  = _map[gridSize - 1, 1];

        for (var y = 1; y < gridSize + 1; y++)
        {
            for (var x = 0; x < gridSize; x++)
            {
                var tile = _map[x, y];
                if (tile != null)
                {
                    tile.SetTexture(false);
                }
            }
        }

        while (currentWpTile != null && currentWpTile.IsFilled(previousWpTile))
        {
            currentWpTile.SetTexture(true);
            Vector2 newCoordinates = currentWpTile.GetNewCoordinates(previousWpTile);

            int newX = (int)newCoordinates.x;
            int newY = (int)newCoordinates.y;

            previousWpTile = currentWpTile;

            currentWpTile = newX < gridSize && newX >= 0 ? _map[newX, newY] : null;

            if (currentWpTile == _endWpTile)
            {
                LevelComplete.Invoke();
                currentWpTile = null;
            }
        }
    }
Ejemplo n.º 8
0
Archivo: Game.cs Proyecto: gormel/has
 public void CompleteLevel()
 {
     LevelComplete?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 9
0
        public void Update(GameTime gameTime, Texture2D wallImage, ContentManager content,
                           int windowWidth, int windowHeight, ref User user, bool updateSnake)
        {
            #region Regular Updating

            this.windowWidth  = windowWidth;
            this.windowHeight = windowHeight;

            if (!LevelReady)
            {
                loadingScreen.Update(gameTime);
            }

            for (int i = 0; i < Walls.Count; i++)
            {
                if (Walls[i].Exploding)
                {
                    Walls[i].Update(gameTime, rand);
                }
                if (Walls[i].Exploded)
                {
                    Walls.RemoveAt(i);
                }
            }

            if (showingAddCoin)
            {
                addCoinTimer.Update(gameTime);
                addCoinLocation.Y -= 0.5f;
                if (addCoinTimer.QueryWaitTime(gameTime))
                {
                    showingAddCoin = false;
                }
            }

            if (snake.Rectangle.Intersects(finRect) && GameMode != GameMode.Star)
            {
                Rectangle snakeRect = snake.Rectangle;
                snakeRect.X = StartPos.X;
                snakeRect.Y = StartPos.Y;
                snake.ChangeRectangle(snakeRect);
                LevelComplete?.Invoke();
            }

            if (GameMode == GameMode.Star)
            {
                for (int i = 0; i < stars.Count; i++)
                {
                    if (snake.Rectangle.Intersects(stars[i]))
                    {
                        Sound.PlaySound(Sounds.Star);
                        stars.RemoveAt(i);
                        if (stars.Count == 0)
                        {
                            Rectangle snakeRect = snake.Rectangle;
                            snakeRect.X = StartPos.X;
                            snakeRect.Y = StartPos.Y;
                            snake.ChangeRectangle(snakeRect);
                            LevelComplete?.Invoke();
                        }
                    }
                }
            }

            if (LevelReady && updateSnake)
            {
                snake.Update(gameTime, PowerUps, Walls, rand, windowWidth, windowHeight, ref user, enemies);
            }

            if (LevelReady)
            {
                for (int i = 0; i < enemies.Count; i++)
                {
                    enemies[i].Update(this);
                }
            }

            foreach (PowerUp p in PowerUps)
            {
                p.Update(windowWidth, windowHeight, Walls, gameTime);
                if (!p.IsPickedUp)
                {
                    if (snake.Rectangle.Intersects(p.Rectangle) && p.Type == PowerupType.Restart)
                    {
                        snake.X = StartPos.X;
                        snake.Y = StartPos.Y;
                        user.AddToStat(Stat.PowerupsCollected, 1);
                        user.AddToStat(Stat.TimesTeleported, 1);
                        Sound.PlaySound(Sounds.Teleport);
                        p.Collect(windowWidth, windowHeight);
                    }
                }
            }

            foreach (Coin c in coins)
            {
                if (!c.IsPickedUp)
                {
                    c.Update(Walls, windowWidth, windowHeight);
                    if (snake.Rectangle.Intersects(c.DrawRectangle))
                    {
                        // Coin has been picked up; increase coin value
                        addCoinLocation = new Vector2(c.DrawRectangle.X,
                                                      c.DrawRectangle.Y + (int)font.MeasureString("+" + c.CoinValue).Y);
                        addCoinText = "+" + c.CoinValue;
                        user.AddCoins(1);
                        Sound.PlaySound(Sounds.Coin);
                        user.AddToStat(Stat.CoinsCollected, 1);
                        showingAddCoin = true;

                        c.IsPickedUp = true;
                    }
                }
            }

            this.wallImage = wallImage;

            #endregion

            #region Maze Generation

            // Uses random maze algorithms to ensure that the maze is random
            switch (Step)
            {
            case 1:
                // Part 1: Create a grid to start with
                #region Create Grid

                // Start by drawing all the walls up and down.
                for (int i = 0; i < windowWidth; i++)
                {
                    for (int j = 1; j < windowHeight; j++)
                    {
                        int x = j * ROW_SIZE;
                        int y = (i * ROW_SIZE) + InventoryInterface.BG_HEIGHT;

                        if (x > windowWidth || y > windowHeight)
                        {
                            continue;
                        }

                        Walls.Add(new Wall(x, y, wallImage, SMALL_WALL_SIDE, CELL_SIZE, true, j, i, Direction2.UpDown,
                                           explosionStripAsset, content));
                    }
                }
                // Then draw the walls across
                for (int i = 1; i < windowWidth; i++)
                {
                    for (int j = 0; j < windowHeight; j++)
                    {
                        int x = j * ROW_SIZE;
                        int y = (i * ROW_SIZE) + InventoryInterface.BG_HEIGHT;

                        if (x > windowWidth || y > windowHeight || y < InventoryInterface.BG_HEIGHT)
                        {
                            continue;
                        }

                        Walls.Add(new Wall(x, y, wallImage, CELL_SIZE, SMALL_WALL_SIDE, true, j, i, Direction2.LeftRight, explosionStripAsset, content));
                    }
                }

                // Initialize our unvisited cells list
                for (int i = 0; i < ROWS; i++)
                {
                    for (int j = 0; j < COLUMNS; j++)
                    {
                        unvisitedCells.Add(new Cell(i, j));
                    }
                }
                // Initialize cell neighbors
                foreach (Cell c in unvisitedCells)
                {
                    foreach (Cell n in unvisitedCells)
                    {
                        if (c.IsNeighbor(n))
                        {
                            // The "n" cell is a neighbor of "c"
                            c.Neighbors.Add(n);
                        }
                    }
                }
                // Currently, all the cells are unvisited, so we must set our cells list to all of the unvisited ones (this is efficient as it prevents
                // additional calculations when initializing unvisitedCells
                Cells = unvisitedCells.Clone();

                // Set the turtle's initial cell
                turtle.Row    = 0;
                turtle.Column = 0;
                for (int i = 0; i < unvisitedCells.Count; i++)
                {
                    if (unvisitedCells[i].Row == turtle.Row && unvisitedCells[i].Column == turtle.Column)
                    {
                        turtle.Cell = unvisitedCells[i];
                        visitedCells.Add(unvisitedCells[i]);
                        unvisitedCells.RemoveAt(i);
                        break;
                    }
                }

                // Increase step
                Step++;

                #endregion
                break;

            case 2:
                // Part 2: Generate the actual maze
                #region Generate Maze

                GenerateHuntAndKill(content, coinSprite);

                loadingScreen.AddPercentage(1);

                #endregion
                break;
            }
            #endregion
        }
Ejemplo n.º 10
0
        private void UpdateGame()
        {
            //Pre game timer
            if (mPreGameTime > 0)
            {
                mPreGameTime--;

                if (mPreGameTime == 0)
                {
                    mPlaying = true;
                    ClearASCII();
                    WriteASCIICentred("PAUSED", mASCIISize.Width / 2, mASCIISize.Height / 2);
                }
                else
                {
                    ClearASCII();

                    string[] lns = mLevel.Name.Split('|');

                    for (int i = 0; i < lns.Length; i++)
                    {
                        WriteASCIICentred(lns[i], mASCIISize.Width / 2, (mASCIISize.Height * (i + 1)) / (lns.Length + 1));
                    }
                }
            }

            if (mPlaying && !mPaused)
            {
                //Update all the snakes
                UpdateSnakes();

                //Check block at bottom
                //if (GetTileAt(BottomDoorLocation) == TileType.Null) {
                //    if (!IsThereSnakeAt(BottomDoorLocation)) {
                //        SetTileAt(BottomDoorLocation, TileType.Wall);
                //    }
                //}

                if (mMode == Mode.Normal)
                {
                    //mLevelTime--;
                    if (mLevelTime == 0)
                    {
                        AddRandomFood(mInitialFood - GetRemainingFoodCount());
                        mLevelTime = InitialLevelTime;
                    }
                }
            }

            if (LevelUpdate != null)
            {
                LevelUpdate.Invoke(this, EventArgs.Empty);
            }

            //Repaint
            Invalidate();

            //Callback functions
            switch (mCallbackState)
            {
            case CallbackState.WinGame:
                mPlaying = false;

                if (LevelComplete != null)
                {
                    LevelComplete.Invoke(this, EventArgs.Empty);
                }
                break;

            case CallbackState.LoseGame:
                mPlaying = false;
                if (LevelFail != null)
                {
                    LevelFail.Invoke(this, EventArgs.Empty);
                }
                break;
            }

            //Reset callback
            mCallbackState = CallbackState.Null;

            //Update the update counter
            mUpdateCnt = (mUpdateCnt + 1) % UpdatesPerSecond;
        }