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();
                }
            }
        }
        protected override void OnTrigger()
        {
            Animator animator = ParentGameObject.GetComponent <Animator>();

            if (animator == null)
            {
                End();
                return;
            }

            switch (_kind)
            {
            case Kind.TRIGGER: animator.SetTrigger(_parameter);
                break;

            case Kind.BOOL: animator.SetBool(_parameter, _boolValue);
                break;

            case Kind.INTEGER: animator.SetInteger(_parameter, _intValue);
                break;

            case Kind.FLOAT: animator.SetFloat(_parameter, _floatValue);
                break;
            }

            End();
        }
Beispiel #3
0
 /// <summary>
 /// Public override method which initiates at the first frame.
 /// </summary>
 public override void Start()
 {
     keyObserver = ParentGameObject.GetComponent <KeyObserver>();
     position    = ParentGameObject.GetComponent <Position>();
     x           = position.Pos.X;
     option      = 0;
 }
Beispiel #4
0
        /// <summary>
        /// Method that runs once on start.
        /// </summary>
        public override void Start()
        {
            MapComponent map = ParentGameObject.GetComponent <MapComponent>();

            maxX = map.Map.GetLength(0);
            maxY = map.Map.GetLength(1);
        }
Beispiel #5
0
        public override void Initialize()
        {
            IHealthComponent healthComponent = ParentGameObject.GetComponent <IHealthComponent>();

            healthComponent.OnHealthDepleted += OnDeath;
            base.Initialize();
        }
        public override void Initialize()
        {
            var movementComponent = ParentGameObject.GetComponent <IMovementComponent>();

            movementComponent.MoveInDirection(new Vector2(0, 1));

            base.Initialize();
        }
Beispiel #7
0
 public override void Start()
 {
     sprite = ParentGameObject.GetComponent <ConsoleSprite>();
     if (sprite == null)
     {
         throw new InvalidOperationException(
                   $"The {nameof(SpriteCollider)} component " +
                   "requires a {nameof(ConsoleSprite)} component");
     }
 }
Beispiel #8
0
        /// <summary>
        /// Method to run at the beginning of a scene
        /// </summary>
        public override void Start()
        {
            _transform = ParentGameObject.GetComponent <Transform>();

            if (_transform == null)
            {
                throw new InvalidOperationException(
                          $"The {nameof(ObjectCollider)} component " +
                          $"requires a {nameof(Transform)} component");
            }
        }
Beispiel #9
0
        public override void Initialize()
        {
            //Subscribe to our ICollisionComponent.
            CollisionComponent              = ParentGameObject.GetComponent <ICollisionComponent>();
            CollisionComponent.OnCollision += Collided;

            //Get a reference to our damage component.
            DamageComponent = ParentGameObject.GetComponent <IDamageComponent>();

            base.Initialize();
        }
        public override void Initialize()
        {
            healthComponent = ParentGameObject.GetComponent <IHealthComponent>();

            if (healthComponent != null)
            {
                healthComponent.OnHealthDepleted += OnHealthDepleted;
            }

            base.Initialize();
        }
Beispiel #11
0
        /// <summary>
        /// Turns the player sprite.
        /// </summary>
        /// <param name="right">True if player is facing right.</param>
        private void TurnSprite(bool right)
        {
            // Sprite for player facing right.
            char[,] playerSpriteRight =
            {
                { '─', '▄', '█', '└' },
                { '▄', '▀', '▄', '▄' },
                { '█', '█', '▐', '▄' },
                { '█', '▀', '▐', '▄' },
                { '█', '▐', '▄', '▄' },
                { '█', '└', '█', '▄' },
                { '▄', '─', '▄', '┘' },
                { '▄', '┐', '┘', ' ' },
            };

            // Sprite for player facing left.
            char[,] playerSpriteLeft =
            {
                { '▄', '┌', '└', ' ' },
                { '▄', '─', '▄', '└' },
                { '█', '┘', '█', '▄' },
                { '█', '▌', '▄', '▄' },
                { '█', '▀', '▌', '▄' },
                { '█', '█', '▌', '▄' },
                { '▄', '▀', '▄', '▄' },
                { '─', '▄', '█', '┘' },
            };

            if (!right)
            {
                ParentGameObject
                .GetComponent <ConsoleSprite>()
                .SwitchSprite(
                    playerSpriteLeft,
                    ConsoleColor.Red,
                    ConsoleColor.Gray);
            }
            else
            {
                ParentGameObject
                .GetComponent <ConsoleSprite>()
                .SwitchSprite(
                    playerSpriteRight,
                    ConsoleColor.Red,
                    ConsoleColor.Gray);
            }
        }
Beispiel #12
0
        private void CheckMaterial()
        {
            Renderer thisRenderer = ParentGameObject.GetComponent <Renderer>();

            if (thisRenderer == null)
            {
                m_useThis = false;
            }
            else
            {
#if UNITY_EDITOR
                m_useThis = ((UnityEditor.EditorApplication.isPlaying && m_material == thisRenderer.material) ||
                             (!UnityEditor.EditorApplication.isPlaying && m_material == thisRenderer.sharedMaterial));
#else
                m_useThis = (m_material == thisRenderer.material);
#endif
            }
        }
Beispiel #13
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 score goes down by 10
                if (framesForTime == 50)
                {
                    Scoring -= 10;

                    framesForTime = 0;

                    /* Actualizes the render of the game object with the
                     * actualized score */
                    ParentGameObject.GetComponent <RenderableStringComponent>()
                    .SwitchString(() => "Score: " + Scoring.ToString());
                }
            }
        }
        /// <summary>
        /// Действия по началу игрового уровня (с пробросом в компонент главного меню)
        /// </summary>
        private void StartGameLevel()
        {
            ParentGameObject.LinkedAppModel.GetSoundManager().StopMusic();

            MainMenuControlComponent mainMenuControlComponent =
                ParentGameObject.GetComponent <MainMenuControlComponent>(typeof(MainMenuControlComponent));

            //disable all button listeners
            if (MenuHandlingControls != null)
            {
                foreach (var keyListenerComponent in MenuHandlingControls)
                {
                    keyListenerComponent.DisableAndSendToPool();
                }
            }

            SelectUiElement(null);


            ViewEndedTransitionToTheGameStage += () => mainMenuControlComponent.StartGameHandle(CurrentSelectedLevel);

            TransitionToTheGameStageStarted?.Invoke();
        }
Beispiel #15
0
        protected void ChangeMaterial()
        {
            if (m_useThis)
            {
                Renderer thisRenderer = ParentGameObject.GetComponent <Renderer>();

                if (thisRenderer == null)
                {
                    return;
                }
#if UNITY_EDITOR
                if (UnityEditor.EditorApplication.isPlaying)
                {
                    m_material = thisRenderer.material;
                }
                else
                {
                    m_material = thisRenderer.sharedMaterial;
                }
#else
                m_material = thisRenderer.material;
#endif
            }
        }
Beispiel #16
0
        protected override void OnHealthDepleted(IHealthComponent sender, IGameObject damageInitator)
        {
            var renderComponent = ParentGameObject.GetComponent <IRenderComponent>();

            var particleAction = Parent.ActionFactory.GetAction <OneShotEmitParticleAction>();

            particleAction.ParticleName = ParticleEffectName;

            //Find the correct spot on the IRenderComponent if it's available.
            if (renderComponent != null)
            {
                float x = (ParentGameObject.Position.X + (renderComponent.Width / 2f));
                float y = (ParentGameObject.Position.Y + (renderComponent.Height / 2f));
                particleAction.TargetLocation = new Vector2(x, y);

                Parent.FireAction(particleAction, null);
            }
            else //No render component, just set the target to be this game object.
            {
                Parent.FireAction(particleAction, sender.Parent);
            }

            base.OnHealthDepleted(sender, damageInitator);
        }
 // Start is called immediately before the game loop starts
 public override void Start()
 {
     // Get a reference to the key reader component
     keyReader = ParentGameObject.GetComponent <KeyReaderComponent>();
 }
Beispiel #18
0
        public override void Initialize()
        {
            MovementComponent = ParentGameObject.GetComponent <IMovementComponent>();

            base.Initialize();
        }
Beispiel #19
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;
                }
            }
        }
Beispiel #20
0
 /// <summary>
 /// Public override method which initiates at the first frame.
 /// </summary>
 public override void Start()
 {
     position = ParentGameObject.GetComponent <Position>();
     x        = position.Pos.X;
 }
Beispiel #21
0
 public override void Start()
 {
     keyObserver = ParentGameObject.GetComponent <KeyObserver>();
 }
        public override void Initialize()
        {
            scoreText = ParentGameObject.GetComponent <IRenderComponent>().GetRenderable("score") as ITextRenderable;

            base.Initialize();
        }