예제 #1
0
        public override void Update()
        {
            base.Update();
            if (Tank.Collider == null)
            {
                throw new InvalidOperationException("to use this decorator, the tank must have the getdamage collider");
            }
            //get all colliding entities
            List <Entity> collisionList = Tank.Collider.CollideEntities(Tank.X, Tank.Y, CollidableTags.PowerUp);

            if (collisionList.Count > 0)
            {
                foreach (Entity powerUp in collisionList)
                {
                    //cast to powerup
                    PowerUp p = (PowerUp)powerUp;
                    //get enum position name
                    string powerUpName = p.PowerUpType.ToString();
                    //parse to tank decorator enum -> power up types must be tank decorators!
                    Code.Decorators tankDecorator = Utilities.ParseEnum <Code.Decorators>(powerUpName);
                    //add to tank
                    Tank.AddDecorator(tankDecorator);
                    //remove the powerup
                    p.RemoveSelf();
                }
            }
        }