Пример #1
0
    public void Process(Pickup pickup)
    {
        pickupProperty = pickup.GetPickupProperty();
        pickupValue    = pickup.GetPickupValue();
        analyticsManager.AddPickupsTaken();

        switch (pickupProperty)
        {
        case "Health":
            playerController.AddHealth((int)pickupValue);
            healthDisplay.SetHealth(playerController.GetHealth());
            analyticsManager.AddHealthPickups();
            break;

        case "Points":
            scoreKeeper.AddScore((int)pickupValue);
            analyticsManager.AddPointPickups();
            break;

        case "Damage":
            playerController.SetProjectileDamage(pickupValue);
            analyticsManager.AddDamagePickups();
            break;

        case "ShotSpeed":
            playerController.IncreaseFiringRate(pickupValue);
            analyticsManager.AddSpeedPickups();
            break;

        default:
            Debug.Log("Incorrect Pickup Property!");
            break;
        }
        pickup.Pick();
    }
        private void ApplyDamage(
            GridPositionComponent targetPosition,
            IntegerComponent damage,
            IntegerComponent targetHealth)
        {
            ObjectPools.Instance.GetPooledObject <TextPopup>().Enable(
                (-damage.Value).ToString(),
                targetPosition.Position + Vector2.up,
                1.0f);
            targetHealth.Value -= damage.Value;

            AudioPlayer.Instance.PlayAudio(AudioPlayer.Type.Damage);

            if (ActorCache.Instance.Player.Entity == targetHealth.Owner)
            {
                _healthDisplay.SetHealth(targetHealth.Value);
            }

            var fireImmune = targetHealth.Owner.GetComponent <FireImmuneComponent>();

            if (fireImmune != null)
            {
                targetHealth.Owner.RemoveComponent(fireImmune);
            }

            var neutral = targetHealth.Owner.GetComponent <NeutralComponent>();

            if (neutral != null)
            {
                targetHealth.Owner.RemoveComponent(neutral);
            }

            if (targetHealth.Value <= 0)
            {
                var render = targetHealth.Owner.GetComponent <RenderComponent>();
                if (render != null)
                {
                    render.Sprite = Sprites.Instance.GetDeathSprite();
                    render.Renderer.sortingOrder = SortOrder.DeadActor;
                }

                var turnComponent = targetHealth.Owner.GetComponent <BooleanComponent>(ComponentType.Turn);
                if (turnComponent != null)
                {
                    targetHealth.Owner.RemoveComponent(turnComponent);
                }

                // IF Player, Game Over
                if (targetHealth.Owner == ActorCache.Instance.Player.Entity)
                {
                    GameController.Instance.GameOver();
                }
            }
        }
Пример #3
0
    private void TakeDamage(DamageDealer damageDealer, Collider2D collision)
    {
        health -= damageDealer.GetDamage();

        if (health <= 0)
        {
            health = 0;

            Die();
        }
        else
        {
            PrefabPoolingSystem.Spawn(collision.GetComponent <Projectile>().GetImpactVFX(), transform.localPosition, Quaternion.identity);

            AudioSource.PlayClipAtPoint(collision.GetComponent <Projectile>().GetImpactSound(), mainCameraPos,
                                        collision.GetComponent <Projectile>().GetImpactSoundVolume());


            healthDisplay.SetHealth(health.ToString());
        }
    }
Пример #4
0
    private void Start()
    {
        SetUpBoundaries();

        healthDisplay = FindObjectOfType <HealthDisplay>();
        healthDisplay.SetHealth(health.ToString());



        GameSession.instance.SetPlayer(this);

        fireCoroutineLvl0 = StartCoroutine(FireContinuouslyLvl0());
        fireCoroutineLvl2 = StartCoroutine(FireContinuouslyLvl2());
    }
        public void AddHealth()
        {
            var player       = ActorCache.Instance.Player;
            var playerHealth = player.Entity.GetComponent <IntegerComponent>(ComponentType.Health);

            if (playerHealth.Value >= MaxHealth)
            {
                return;
            }

            playerHealth.Value += 1;

            _healthDisplay.SetHealth(playerHealth.Value);

            AudioPlayer.Instance.PlayAudio(AudioPlayer.Type.ItemApply);
            ObjectPools.Instance.GetPooledObject <TextPopup>().Enable("HEALTH+", GetDisplayPos(), 3.0f);
        }
Пример #6
0
    void Update()
    {
        Vector2 dir = GetDirection();

        Move(dir, speed);

        health_display.SetHealth(health);
        energy_display.SetEnergy(energy);
        score_display.SetScore(score);

        if (health <= 0)
        {
            GameOver();
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            TryFire();
        }
    }
Пример #7
0
    private void ProcessHit(DamageDealer damageDealer, Enemy enemy)
    {
        health -= damageDealer.GetDamage();
        healthDisplay.SetHealth(health);
        if (enemy)
        {
            enemy.Die();
        }
        else
        {
            damageDealer.Hit();
        }

        if (health <= 0)
        {
            Die();
        }
        else
        {
            AudioSource.PlayClipAtPoint(hitSound, Camera.main.transform.position, hitSoundVolume);
        }
    }
Пример #8
0
 public void TakeDamage(int amount)
 {
     HealthPoints -= amount;
     Display.SetHealth(HealthPoints);
 }
Пример #9
0
 public void SetDisplay(HealthDisplay newDisplay)
 {
     Display = newDisplay;
     Display.SetHealth(HealthPoints);
 }
 private void Start()
 {
     state = PlayerHealthState.Alive;
     healthDisplay.SetHealth(healthPoints);
 }
Пример #11
0
    void Update()
    {
        // End game
        for (int i = 0; i < enemySpawner.transform.childCount; i++)
        {
            Enemy currentEnemy = enemySpawner.transform.GetChild(i).gameObject.GetComponent <Enemy>();
            if (currentEnemy.transform.position.x < minX)
            {
                health--;
                Destroy(currentEnemy.gameObject);
            }
        }

        // Remove towers
        for (int i = 0; i < tiles.rows; i++)
        {
            for (int j = 0; j < tiles.cols; j++)
            {
                Tile  currentTile  = tiles.GetTiles()[i, j];
                Tower currentTower = currentTile.GetTower();
                if (currentTower != null)
                {
                    for (int k = 0; k < enemySpawner.transform.childCount; k++)
                    {
                        Enemy      currentEnemy  = enemySpawner.transform.GetChild(k).gameObject.GetComponent <Enemy>();
                        Collider2D enemyCollider = currentEnemy.GetComponent <Collider2D>();
                        Collider2D towerCollider = currentTower.GetComponent <Collider2D>();

                        // If tower collides with enemy, destroy tower and enemy
                        if (towerCollider.bounds.Intersects(enemyCollider.bounds))
                        {
                            Destroy(currentTower.gameObject);
                            Destroy(currentEnemy.gameObject);
                        }

                        // Loop through bullets
                        for (int l = 0; l < currentTower.transform.childCount; l++)
                        {
                            Bullet     currentBullet  = currentTower.transform.GetChild(l).gameObject.GetComponent <Bullet>();
                            Collider2D bulletCollider = currentBullet.GetComponent <Collider2D>();

                            // If bullet collides with enemy, destroy bullet and enemy
                            if (bulletCollider.bounds.Intersects(enemyCollider.bounds))
                            {
                                Destroy(currentBullet.gameObject);
                                Destroy(currentEnemy.gameObject);
                                money++;
                            }
                        }
                    }
                }
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            if ((selectedMode == Mode.PLACE_TOWER && selectedTower.cost <= money) || selectedMode == Mode.REMOVE_TOWER)
            {
                // Place towers
                for (int i = 0; i < tiles.rows; i++)
                {
                    for (int j = 0; j < tiles.cols; j++)
                    {
                        Tile  currentTile  = tiles.GetTiles()[i, j];
                        Tower currentTower = currentTile.GetTower();
                        if (currentTile.isMouseOver())
                        {
                            if (selectedMode == Mode.PLACE_TOWER && currentTower == null)
                            {
                                Debug.Log("Placing Tower");
                                currentTower = Instantiate(
                                    selectedTower,
                                    new Vector3(
                                        currentTile.transform.position.x,
                                        currentTile.transform.position.y,
                                        -1
                                        ),
                                    Quaternion.identity
                                    ).GetComponent <Tower>();
                                currentTower.transform.SetParent(currentTile.transform);
                                currentTile.SetTower(currentTower);
                                money -= selectedTower.cost;

                                return;
                            }
                            else if (currentTower == null)
                            {
                                return;
                            }
                            else if (selectedMode == Mode.REMOVE_TOWER && currentTile.isMouseOver())
                            {
                                Destroy(currentTower.gameObject);
                                money += (int)((float)currentTower.cost * 0.8f);
                                return;
                            }
                        }
                    }
                }
            }
        }
        moneyDisplay.SetMoney(money);
        healthBar.SetHealth(health);
    }