예제 #1
0
    public override void _Ready()
    {
        timerMeteorSpawner  = GetNode <Timer>("TimerMeteorSpawner");
        timerPowerUpSpawner = GetNode <Timer>("TimerPowerUpSpawner");
        timerEnemySpawner   = GetNode <Timer>("TimerEnemySpawner");
        timerWave           = GetNode <Timer>("TimerWave");
        timerWaveCooldown   = GetNode <Timer>("TimerWaveCooldown");
        player            = GetNode <Player>("Player");
        lifeContainer     = GetNode <LifeContainer>("Canvas/Stats/PanelContainer/HBoxContainer/ColorRect/LifeContainer");
        labelWave         = GetNode <Label>("Canvas/Stats/PanelContainer/HBoxContainer/ColorRect2/WaveScoreContainer/Wave");
        labelScore        = GetNode <Label>("Canvas/Stats/PanelContainer/HBoxContainer/ColorRect2/WaveScoreContainer/Score");
        labelWaveShow     = GetNode <Label>("Canvas/LabelWave");
        labelGameOver     = GetNode <Label>("Canvas/LabelGameOver");
        labelCurrentScore = GetNode <Label>("Canvas/LabelGameOver/LabelCurrentScore");
        labelHighScore    = GetNode <Label>("Canvas/LabelGameOver/LabelHighScore");
        bgm = GetNode <AudioStreamPlayer>("BGM");

        timerMeteorSpawner.Connect("timeout", this, nameof(OnTimerMeteorTimeout));
        timerPowerUpSpawner.Connect("timeout", this, nameof(OnTimerPowerUpTimeout));
        timerEnemySpawner.Connect("timeout", this, nameof(OnTimerEnemyTimeout));
        timerWave.Connect("timeout", this, nameof(OnTimerWaveTimeout));
        timerWaveCooldown.Connect("timeout", this, nameof(OnTimerWaveCooldownTimeout));
        player.Connect("Exploded", this, nameof(OnExploded));

        SetProcessInput(false);
        SetupWave();
        InitializePlayerLife();
        ShowWaveText();

        Engine.TimeScale = 1;
        bgm.Play();
    }
예제 #2
0
        public void UsableObjectRelease_Successful()
        {
            //Arrange
            int playerLife           = 80;
            int containerLifeContent = 30;
            int playerMaxLife        = 100;

            var player        = new PlayerBody(new ShapeCircle(10, new Point(1, 1)), new Vector(0, 0), null, null, playerLife, playerMaxLife, "Bob", 0, 1);
            var lifeContainer = new LifeContainer(null, containerLifeContent);

            player.UsableBodyInScope = lifeContainer;
            player.Shape.Position    = new Point(player.Shape.Position.X + 10, player.Shape.Position.Y);

            //Act
            player.UpdateState();

            //Assert
            Assert.AreEqual(player.UsableBodyInScope, null);
        }
예제 #3
0
        public void UseLifeContainer_Successful()
        {
            //Arrange
            int playerLife           = 80;
            int containerLifeContent = 30;
            int playerMaxLife        = 100;

            var mechnicEngine = Substitute.For <IMechanicEngine>();
            var player        = new PlayerBody(new ShapeCircle(10, new Point(1, 1)), new Vector(0, 0), mechnicEngine, null, playerLife, playerMaxLife, "Bob", 0, 1);
            var lifeContainer = new LifeContainer(null, containerLifeContent);

            player.UsableBodyInScope = lifeContainer;

            //Act
            player.Use();

            //Assert
            Assert.AreEqual(player.Life, player.LifeMax);
        }
 private void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.isTrigger == false)
     {
         if (owner.tag != collider.tag)
         {
             Debug.Log(transform.name + " collided with " + collider.name);
             LifeContainer lifecontainer = collider.GetComponent <LifeContainer>();
             if (lifecontainer == null)
             {
                 // collided with a object withot a life container
             }
             else
             {
                 // collided with a object with a life conteiner
                 lifecontainer.TakeDamage(damage);
             }
             Destroy(gameObject);
         }
     }
 }
예제 #5
0
파일: Hud.cs 프로젝트: incutonez/ZeldaU
        private void RefreshLifeUI()
        {
            float?health = Player.Health;
            // 0-based value
            float?maxHealth = (Player.MaxHealth / 2) - 1;

            for (int i = 0; i < LifeContainer.childCount; i++)
            {
                RectTransform heart = LifeContainer.GetChild(i).GetComponent <RectTransform>();
                if (i > maxHealth)
                {
                    heart.gameObject.SetActive(false);
                }
                else
                {
                    heart.gameObject.SetActive(true);
                    Image image      = heart.GetComponent <Image>();
                    int   heartCount = (i + 1) * 2;
                    // This means we should either show a half heart or empty heart
                    if (heartCount > health)
                    {
                        if (heartCount - health >= 2)
                        {
                            image.sprite = HeartEmptySprite;
                        }
                        else if (heartCount - health >= 1)
                        {
                            image.sprite = HeartHalfSprite;
                        }
                    }
                    // Otherwise, we're still at a full heart
                    else
                    {
                        image.sprite = HeartSprite;
                    }
                }
            }
        }