Beispiel #1
0
        /// <summary>
        /// Public override method which is launched at each frame.
        /// </summary>
        public override void Update()
        {
            // Sees if the player as not died or finish the level
            if (!player.Gameover)
            {
                framesForTime++;

                // At each 50 frames, the time goes down by 1
                if (framesForTime == 50)
                {
                    Timing--;

                    framesForTime = 0;

                    /* Actualizes the render of the game object with the
                     * actualized score */
                    ParentGameObject.GetComponent <RenderableStringComponent>().
                    SwitchString(() => "Time: " + Timing.ToString());
                }

                // Returns to the menu if the time's up.
                if (Timing == 0)
                {
                    ParentScene.Terminate();
                    Menu menu = new Menu();
                    menu.Run();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Player update levels and victory/defeat conditions
        /// </summary>
        public override void Update()
        {
            base.Update();

            // Player directions
            _playerLeft = new Vector2((int)selfTrans.Pos.X - 1,
                                      (int)selfTrans.Pos.Y);

            _playerRight = new Vector2((int)selfTrans.Pos.X + 1,
                                       (int)selfTrans.Pos.Y);

            _playerDown = new Vector2((int)selfTrans.Pos.X,
                                      (int)selfTrans.Pos.Y + 1);

            _playerUp = new Vector2((int)selfTrans.Pos.X,
                                    (int)selfTrans.Pos.Y - 1);

            _playerPos = new Vector2((int)selfTrans.Pos.X,
                                     (int)selfTrans.Pos.Y);

            // Level up
            LevelUp(Role);

            // Check if dead
            if (Life <= 0)
            {
                // End game, You died
                ParentScene.Terminate();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Dungeon update with base, checks if enemies exist,
        /// if not, terminate game
        /// </summary>
        public override void Update()
        {
            base.Update();

            if (CheckAliveDead())
            {
                // End game, victory screen
                ParentScene.Terminate();
            }
        }
Beispiel #4
0
 public override void Update()
 {
     foreach (ConsoleKey key in keyObserver.GetCurrentKeys())
     {
         if (key == ConsoleKey.Escape)
         {
             Console.WriteLine("Bye :(");
             ParentScene.Terminate();
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Public override method which is launched at each frame.
        /// </summary>
        public override void Update()
        {
            // Gets the position in Y of the indicator
            y = position.Pos.Y;

            /* Sees what key is pressed and depending of the keys pressed
             * the indicator can go up and down or initiate another scene*/
            foreach (ConsoleKey key in keyObserver.GetCurrentKeys())
            {
                if (key == ConsoleKey.UpArrow && option != 0)
                {
                    y -= 2;
                    option--;
                }
                else if (key == ConsoleKey.DownArrow && option != 3)
                {
                    y += 2;
                    option++;
                }
                else if (key == ConsoleKey.Enter)
                {
                    if (option == 0)
                    {
                        ParentScene.Terminate();
                        Level1 level1 = new Level1();
                        level1.Run();
                    }

                    if (option == 1)
                    {
                        ParentScene.Terminate();
                        Level2 level2 = new Level2();
                        level2.Run();
                    }
                    else if (option == 2)
                    {
                        ParentScene.Terminate();
                        Help helpMenu = new Help();
                        helpMenu.Run();
                    }
                    else
                    {
                        ParentScene.Terminate();
                    }
                }
            }

            // The position of the gameobject actualizes with the new values
            position.Pos = new Vector3(x, y, position.Pos.Z);
        }
Beispiel #6
0
 /// <summary>
 /// Public override method which is launched at each frame.
 /// </summary>
 public override void Update()
 {
     /* Sees what key is pressed and depending of the keys pressed
      * the indicator initiate the menu scene */
     foreach (ConsoleKey key in keyObserver.GetCurrentKeys())
     {
         if (key == ConsoleKey.Enter)
         {
             ParentScene.Terminate();
             Menu menu = new Menu();
             menu.Run();
         }
     }
 }
Beispiel #7
0
        /// <summary>
        /// Public override method which is launched at each frame.
        /// </summary>
        public override void Update()
        {
            bool ground;

            x = position.Pos.X;
            y = position.Pos.Y;
            bool colide = false;

            // Sets Gameover to true when the player reaches the end of the
            // level.
            if (ParentScene.xdim - 9 == position.Pos.X && !Gameover)
            {
                Gameover = true;
            }

            if (Gameover)
            {
                // Sets the correct keys to observe
                ParentGameObject.GetComponent <KeyObserver>().keysToObserve =
                    new ConsoleKey[] { ConsoleKey.Enter, ConsoleKey.Escape };
                ParentScene.inputHandler.quitKeys = new ConsoleKey[] {
                    ConsoleKey.Enter,
                    ConsoleKey.Escape,
                };
                ParentScene.inputHandler.RegisterObserver(
                    ParentGameObject
                    .GetComponent <KeyObserver>()
                    .keysToObserve, ParentGameObject
                    .GetComponent <KeyObserver>());

                // Runs if player falls of the map.
                if (ParentScene.ydim - 4 == position.Pos.Y)
                {
                    // Outputs the dead text
                    dead.GetComponent <RenderableStringComponent>()
                    .SwitchString(() => "Press Enter to restart");

                    // Waits for player input to go to the next level or
                    // back to the main menu.
                    foreach (ConsoleKey key in keyObserver.GetCurrentKeys())
                    {
                        if (key == ConsoleKey.Enter)
                        {
                            if (level == 1)
                            {
                                ParentScene.Terminate();
                                Level1 level1 = new Level1();
                                level1.Run();
                                break;
                            }
                            else
                            {
                                ParentScene.Terminate();
                                Level2 level2 = new Level2();
                                level2.Run();
                                break;
                            }
                        }

                        if (key == ConsoleKey.Escape)
                        {
                            ParentScene.Terminate();
                            Menu menu = new Menu();
                            menu.Run();
                            break;
                        }
                    }
                }

                // Runs if player reaches the end of the level.
                else if (ParentScene.xdim - 9 == position.Pos.X)
                {
                    // Outputs the ending level text
                    dead.GetComponent <RenderableStringComponent>()
                    .SwitchString(() =>
                                  $"Press Enter to go to the next level, your score is : {actualScore.Scoring}");

                    // Waits for player input to go to the next level or back
                    // to the main menu.
                    foreach (ConsoleKey key in keyObserver.GetCurrentKeys())
                    {
                        if (key == ConsoleKey.Enter)
                        {
                            if (level == 1)
                            {
                                ParentScene.Terminate();
                                Level2 level2 = new Level2();
                                level2.Run();
                                break;
                            }
                            else
                            {
                                ParentScene.Terminate();
                                Menu menu = new Menu();
                                menu.Run();
                                break;
                            }
                        }

                        if (key == ConsoleKey.Escape)
                        {
                            ParentScene.Terminate();
                            Menu menu = new Menu();
                            menu.Run();
                            break;
                        }
                    }
                }
            }
            else
            {
                // Checks if the player is on the ground
                ground = CheckGround();

                // If he is not jumping and not in the ground, the player
                // will then starts to fall
                if (!inAir && !ground)
                {
                    while (!ground)
                    {
                        Falling();

                        // Removes the keyObserver from the player.
                        ParentScene.inputHandler
                        .RemoveObserver(ParentGameObject
                                        .GetComponent <KeyObserver>());

                        doesNotHaveKeyObserver = true;
                        ground = true;
                    }
                }

                // If he is in the ground, then he can walk and jump as normal
                else if (!inAir)
                {
                    if (doesNotHaveKeyObserver)
                    {
                        // Adds the keyObserver to the player.
                        ParentScene.inputHandler
                        .AddObserver(ParentGameObject
                                     .GetComponent <KeyObserver>());
                        doesNotHaveKeyObserver = false;
                    }

                    // Controls the movement of the player.
                    foreach (ConsoleKey key in keyObserver.GetCurrentKeys())
                    {
                        switch (key)
                        {
                        case ConsoleKey.RightArrow:
                            lastkey = ConsoleKey.RightArrow;
                            foreach (Vector2 v in occupied)
                            {
                                if (position.Pos.X + 7 == v.X &&
                                    position.Pos.Y == v.Y)
                                {
                                    colide = true;
                                }
                            }

                            if (!colide)
                            {
                                x++;
                            }

                            // Map limits.
                            x            = Math.Clamp(x, 0, ParentScene.xdim - 9);
                            y            = Math.Clamp(y, 0, ParentScene.ydim - 3);
                            position.Pos = new Vector3(
                                x,
                                y,
                                position.Pos.Z);
                            TurnSprite(true);
                            break;

                        case ConsoleKey.UpArrow:
                            lastkey      = ConsoleKey.UpArrow;
                            position.Pos = new Vector3(
                                x,
                                y,
                                position.Pos.Z);
                            break;

                        case ConsoleKey.LeftArrow:
                            lastkey = ConsoleKey.LeftArrow;
                            foreach (Vector2 v in occupied)
                            {
                                if (position.Pos.X - 1 == v.X &&
                                    position.Pos.Y == v.Y)
                                {
                                    colide = true;
                                }
                            }

                            if (!colide)
                            {
                                x--;
                            }

                            // Map limits.
                            x            = Math.Clamp(x, 0, ParentScene.xdim - 9);
                            y            = Math.Clamp(y, 0, ParentScene.ydim - 3);
                            position.Pos = new Vector3(
                                x,
                                y,
                                position.Pos.Z);
                            TurnSprite(false);
                            break;

                        case ConsoleKey.Spacebar:
                            inAir        = true;
                            position.Pos = new Vector3(
                                x,
                                y,
                                position.Pos.Z);
                            break;

                        case ConsoleKey.Escape:
                            ParentScene.Terminate();
                            Menu menu = new Menu();
                            menu.Run();
                            break;
                        }
                    }

                    // Map limits.
                    x = Math.Clamp(x, 0, ParentScene.xdim - 9);
                    y = Math.Clamp(y, 0, ParentScene.ydim - 3);
                }

                // Player Jump.
                else if (inAir)
                {
                    actualScore.Scoring -= 5;
                    ParentScene.inputHandler.RemoveObserver(
                        ParentGameObject.GetComponent <KeyObserver>());
                    if (jumpFrames <= 2)
                    {
                        y -= 2;
                        if (lastkey == ConsoleKey.RightArrow)
                        {
                            x += 3;
                        }
                        else if (lastkey == ConsoleKey.LeftArrow)
                        {
                            x -= 3;
                        }
                        jumpFrames++;
                    }
                    else if (jumpFrames == 3)
                    {
                        y -= 2;
                        if (lastkey == ConsoleKey.RightArrow)
                        {
                            x += 3;
                        }
                        else if (lastkey == ConsoleKey.LeftArrow)
                        {
                            x -= 3;
                        }
                        jumpFrames = 0;
                        inAir      = false;
                    }

                    // Map limits.
                    x            = Math.Clamp(x, 0, ParentScene.xdim - 9);
                    y            = Math.Clamp(y, 0, ParentScene.ydim - 3);
                    position.Pos = new Vector3(x, y, position.Pos.Z);
                    Thread.Sleep(80);
                }

                if (coins != null)
                {
                    coinScore = CheckCoin();
                }
                if (coinScore)
                {
                    actualScore.Scoring += 1000;
                    coinScore            = false;
                }
            }
        }