Пример #1
0
        private void OnTriggerEnter(Collider2D other)
        {
            if (other.Owner is Explosion)
            {
                this.Active = false;

                int xPos  = (int)Transform.Position.X;
                int yPos  = (int)Transform.Position.Y;
                int index = Map.GetIndex(xPos, yPos);

                if (LevelManager.CurrentMap.MapNodes[index] == null)
                {
                    LevelManager.CurrentMap.MapNodes[index] = new Node(1, new Vector2(xPos, yPos));
                }

                LevelManager.CurrentMap.GenerateNeighborNode();

                //this is the random to generate our powerups..
                int randomPw = RandomManager.Instance.Random.Next(0, Enum.GetNames(typeof(PowerUpType)).Length);

                //once the random is thrown we can generate it
                //at the moment we only have 2 active powerups so
                //we make some test using the first one on the enum
                IPowerup p = PowerUpFactory.Get(PowerUpType.PW_MYSTERY);
                p.SetPosition(this.Transform.Position);

                GameObject.Spawn(p as GameObject);
            }
        }
Пример #2
0
 /// <summary>
 /// Removes a powerup to the player.
 /// </summary>
 /// <param name="powerup">Powerup to remove</param>
 public void RemovePowerup(IPowerup powerup)
 {
     if (currentPowerups.Contains(powerup))
     {
         currentPowerups.Remove(powerup);
     }
 }
 public static void PowerupCollected(IPowerup powerup)
 {
     if (OnPowerupCollected != null)
     {
         OnPowerupCollected(powerup);
     }
 }
Пример #4
0
 /// <summary>
 /// Adds a powerup to the player.
 /// </summary>
 /// <param name="powerup">Powerup to add</param>
 public void AddPowerup(IPowerup powerup)
 {
     if (!currentPowerups.Contains(powerup))
     {
         currentPowerups.Add(powerup);
     }
     ApplyPowerup(powerup);
 }
        private void SetupSprite(Colour pieceColour)
        {
            this.colour  = pieceColour;
            Image.sprite = GameResources.PieceSprites[((int)pieceColour).ToString()];

            Powerup = PowerupFactory.GetPowerup(pieceColour);
            PowerupSlot.Setup(Powerup, false);
        }
Пример #6
0
    private void SpawnPowerup(IPowerup powerup)
    {
        SpawnSpot spawnSpot = SpawnSpotController.randomSpawn;

        IPowerup newPowerup = Instantiate(powerup.gameObject, spawnSpot.spawnTransform.position, Quaternion.identity).GetComponent <IPowerup>();

        spawnSpot.hostedPowerup = newPowerup;
    }
Пример #7
0
 public void OnTriggerEnter(Collider collider)
 {
     if (collider.tag == "Power-up")
     {
         Debug.Log("power-up collected");
         IPowerup powerup = collider.gameObject.GetComponentInChildren <IPowerup>() as IPowerup;
         StartCoroutine(powerup.ApplyPowerup(this));
         Destroy(collider.gameObject);
     }
 }
Пример #8
0
        public virtual void Setup(IPowerup powerup, bool enableClick = true)
        {
            this.powerup = powerup;

            Icon.sprite = powerup.Icon;
            if (button != null && enableClick)
            {
                button.onClick.AddListener(() => OnButtonClicked());
            }

            previousRemaing = UserPowerupManager.Instance.GetUses(powerup);
            UpdateRemainingText(powerup);
        }
Пример #9
0
    /// <summary>
    /// Calls the powerup to take effect.
    /// </summary>
    /// <param name="powerup">Powerup to activate</param>
    private void ApplyPowerup(IPowerup powerup)
    {
        //configures powerup
        powerup.Apply(gameObject);

        //if it's a duration-type powerup
        if (typeof(IDurationPowerup).IsAssignableFrom(powerup.GetType()))
        {
            IDurationPowerup durationPowerup = (IDurationPowerup)powerup;
            //start the effect
            StartCoroutine(durationPowerup.AbilityEffect());
        }
    }
    public void Update()
    {
        if (hostedPowerup != null && building.isAblaze)
        {
            hostedPowerup.Destroy();
            hostedPowerup = null;
        }

        if (!removed && !functional)
        {
            removed = true;
            SpawnSpotController.RemoveSpawner(this);
        }
    }
        public void Setup(IPowerup powerup)
        {
            Colour colour = Colour.None;

            foreach (Colour c in Enum.GetValues(typeof(Colour)))
            {
                if (powerup.GetType() == PowerupFactory.GetPowerup(c).GetType())
                {
                    colour = c;
                    break;
                }
            }

            GetComponentInChildren <Image>().sprite = GameResources.PieceSprites[((int)colour).ToString()];
        }
Пример #12
0
        public void UsePowerup(IPowerup powerup)
        {
            var match = Powerups.FirstOrDefault(x => x.Powerup.GetType() == powerup.GetType());

            if (match != null)
            {
                match.Count--;
                if (match.Count < 0)
                {
                    match.Count = 0;
                }
            }
            UserIO.Instance.SavePowerupInfo();
            PowerupCountChanged?.Invoke(powerup);
        }
Пример #13
0
 public void impact(GameObject hit)
 {
     MonoBehaviour[] list = hit.transform.GetComponents <MonoBehaviour>();
     foreach (MonoBehaviour mb in list)
     {
         if (mb is IPowerup)
         {
             IPowerup powerup = (IPowerup)mb;
             powerup.OnActivation();
         }
         if (mb is IDamagable <float> )
         {
             IDamagable <float> objHit = (IDamagable <float>)mb;
             objHit.OnTakeDamage(damage);
         }
     }
 }
Пример #14
0
        internal void SelectPowerup(PowerupSlot slot)
        {
            if (currentSelected != null)
            {
                currentSelected.button.interactable = true;
            }

            nameText.text            = slot.powerup.Name;
            descriptionText.text     = slot.powerup.Description;
            slot.button.interactable = false;

            currentSelected = slot;
            SelectedPowerup = slot.powerup;

            FindObjectOfType <PowerupCollectionInfo>().Setup(slot.powerup);

            SetEquipButtons(!UserPowerupManager.Instance.PowerupEquipped(slot.powerup));
        }
Пример #15
0
        public void AddNewPowerup(IPowerup powerup)
        {
            var match = Powerups.FirstOrDefault(x => x.Powerup.GetType() == powerup.GetType());

            if (match == null)
            {
                Powerups.Add(new PowerupCollection()
                {
                    Powerup = powerup, Count = 1
                });
            }
            else
            {
                match.Count++;
            }
            UserIO.Instance.SavePowerupInfo();
            PowerupCountChanged?.Invoke(powerup);
        }
Пример #16
0
        public static IPowerup Get(PowerUpType type)
        {
            IPowerup toReturn = null;

            switch (type)
            {
            case PowerUpType.PW_SPEED:
                toReturn = GlobalFactory <SpeedPow> .Get(typeof(SpeedPow));

                break;

            case PowerUpType.PW_BOMB:
                toReturn = GlobalFactory <BombPow> .Get(typeof(BombPow));

                break;

            case PowerUpType.PW_BOMB_PASS:
                break;

            case PowerUpType.PW_FLAME:
                break;

            case PowerUpType.PW_FLAME_PASS:
                break;

            case PowerUpType.PW_WALL_PASS:
                toReturn = GlobalFactory <WallPass> .Get(typeof(WallPass));

                break;

            case PowerUpType.PW_MYSTERY:
                toReturn = GlobalFactory <Mystery> .Get(typeof(Mystery));

                break;

            case PowerUpType.PW_DETONATOR:
                break;

            default:
                break;
            }

            return(toReturn);
        }
Пример #17
0
        public int GetUses(IPowerup powerup)
        {
            var match = Powerups.FirstOrDefault(x => x.Powerup.GetType() == powerup.GetType());

            if (match != null)
            {
                return(match.Count);
            }
            else
            {
                if (Debug.isDebugBuild)
                {
                    return(99);
                }
                else
                {
                    return(0);
                }
            }
        }
Пример #18
0
        private void UpdateRemainingText(IPowerup powerup)
        {
            if (powerup == null || this.powerup == null)
            {
                return;
            }

            if (powerup.GetType() != this.powerup.GetType())
            {
                return;
            }

            int remaining = UserPowerupManager.Instance.GetUses(powerup);

            if (remaining > previousRemaing)
            {
                activateOnEnable = true;
            }

            remainingText.text = remaining.ToString();
            previousRemaing    = remaining;
        }
Пример #19
0
        private void OnTriggerEnter2D(Collider2D other)
        {
            var powerupComponent = other.gameObject.GetComponent <PlayerPowerup>();

            // Check that the other colliding GameObject is a player.
            if (powerupComponent == null)
            {
                return;
            }
            IPowerup powerup = GetPowerUpFromType(myPowerupType);

            // Remove the effects of any previously held powerup.
            powerupComponent.CancelEffects();
            // Apply the new powerup
            powerupComponent.ApplyPowerup(powerup);
            // Play the audio for the power up
            GameObject audio        = Instantiate(myAudioController);
            var        powerupAudio = GetPowerupMetadataWithType(myPowerupType).Audio;

            audio.GetComponent <PowerupSoundPlayback>().SetAudio(powerupAudio);
            // Tell the powerup spawner that its no longer there.
            OnPickUp?.Invoke();
            Destroy(gameObject);
        }
Пример #20
0
    private bool GeneratePowerup(List <GameObject> levelPowerups, List <GameObject> hits)
    {
        bool generated = false;

        foreach (GameObject powerup in levelPowerups)
        {
            IPowerup thisPowerup = powerup.GetComponent <IPowerup>();
            float    randomInt   = Utility.GenerateRandomInt(0, 100);
            if (thisPowerup.ChanceToSpawn != 0f && randomInt <= thisPowerup.ChanceToSpawn)
            {
                hits.Add(powerup);
                generated = true;
            }
        }

        if (generated)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Пример #21
0
 void Start()
 {
     powerupHandler = ServiceLocator.getService<IPowerup>();
     swipeDirectionModifier = PlayerPrefs.GetInt("SwipeControlls");
 }
Пример #22
0
 public bool PowerupEquipped(IPowerup powerup)
 {
     return(EquippedPowerups.Any(x => x.GetType() == powerup.GetType()));
 }
Пример #23
0
 internal void EquipPowerup(IPowerup powerup, int slot)
 {
     EquippedPowerups[slot] = powerup;
     UserIO.Instance.SaveEquippedPowerupInfo();
 }
Пример #24
0
 private void CollectPowerup(IPowerup powerup)
 {
     this.powerups.Add(powerup);
 }
Пример #25
0
 public void ApplyPowerup(IPowerup powerup)
 {
     myActivePowerUp = powerup;
     StartCoroutine(myActivePowerUp.ScheduleEffect(gameObject));
 }
Пример #26
0
 void Awake()
 {
     lineRenderer = GetComponent<LineRenderer>();
     lineRenderer.sortingLayerName = "Frog";
     lineRenderer.sortingOrder = 50;
     jumpMarkerSensor = GetComponentInChildren<JumpMarkerSensor>();
     jumpPathSensor = GetComponentInChildren<JumpPathSensor>();
     powerup = ServiceLocator.getService<IPowerup>();
     shotgun = GetComponentInChildren<ShotgunController>(true);
 }
Пример #27
0
 // Start is called before the first frame update
 void Start()
 {
     powerup      = GetComponent <IPowerup>();
     powerupLabel = GameObject.FindGameObjectWithTag("Player").transform.Find("UI/Powerup/Label").GetComponent <TextMeshProUGUI>();
     prefab       = (GameObject)Resources.Load(powerupPrefab.name);
 }
Пример #28
0
 void Start()
 {
     GetPelletComponenets();
     powerup = ServiceLocator.getService<IPowerup>();
     animator = GetComponentInParent<Animator>();
     myAudio = ServiceLocator.getService<IAudio>();
 }