Ejemplo n.º 1
0
        public override void OnHit(GameObject hitObject)
        {
            if (hitObject is Player)
            {
                if (RandomGenerator.GetRandom(0, 100) < PROB_LIFE)
                {
                    ExtraLife extraLife = (ExtraLife)ItemPickableManager.GetItem(PickableType.ExtraLife);
                    extraLife.IsActive = true;
                    extraLife.Position = Position;
                    extraLife.OnPlayerPick();
                }
                else
                {
                    int             randomApples        = RandomGenerator.GetRandom(MIN_APPLE, MAX_APPLE + 1);
                    List <Pickable> apples              = ItemPickableManager.GetItems(PickableType.Apple, randomApples);
                    Vector2         offsetBetweenApples = Vector2.Zero;

                    for (int i = 0; i < apples.Count; i++)
                    {
                        Apple apple = (Apple)apples[i];
                        apple.IsActive       = true;
                        apple.Position       = Position + offsetBetweenApples;
                        offsetBetweenApples += new Vector2(apple.Width / 3, apple.Height / 2);
                        apple.OnPlayerPick();
                    }
                }
            }

            base.OnHit(hitObject);
        }
        public static void Init()
        {
            items = new Queue <Pickable> [Enum.GetValues(typeof(PickableType)).Length];

            for (int i = 0; i < items.Length; i++)
            {
                items[i] = new Queue <Pickable>();

                switch ((PickableType)i)
                {
                case PickableType.Apple:

                    for (int j = 0; j < 150; j++)
                    {
                        Apple apple = new Apple(Vector2.Zero);
                        apple.IsActive = false;
                        items[i].Enqueue(apple);
                    }

                    break;

                case PickableType.ExtraLife:

                    for (int j = 0; j < 50; j++)
                    {
                        ExtraLife life = new ExtraLife(Vector2.Zero);
                        life.IsActive = false;
                        items[i].Enqueue(life);
                    }

                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public override void OnHit(GameObject hitObject)
        {
            if (hitObject is Player && !isHitted)
            {
                ExtraLife extraLife = (ExtraLife)ItemPickableManager.GetItem(PickableType.ExtraLife);
                extraLife.IsActive = true;
                extraLife.Position = Position;
                extraLife.OnPlayerPick();
            }

            base.OnHit(hitObject);
        }
Ejemplo n.º 4
0
        private static void InstantiatePickable(XmlNode objectNode, Dictionary <int, XmlNode> dictProperties, ref List <ICheckpointLoadable> objectsLoadable)
        {
            string xString = objectNode.Attributes["x"].Value;
            float  xPos    = float.Parse(xString, System.Globalization.CultureInfo.InvariantCulture);

            string yString = objectNode.Attributes["y"].Value;
            float  yPos    = float.Parse(yString, System.Globalization.CultureInfo.InvariantCulture);

            Vector2 pos           = new Vector2(xPos + (int.Parse(objectNode.Attributes["width"].Value) / 2), yPos - (int.Parse(objectNode.Attributes["height"].Value) / 2));
            int     globalIdCrate = int.Parse(objectNode.Attributes["gid"].Value) - 1;

            XmlNode properties = dictProperties[globalIdCrate];

            PickableType type = (PickableType)int.Parse(properties.FirstChild.Attributes["value"].Value);
            Pickable     p    = null;

            switch (type)
            {
            case PickableType.Apple:
                p = new Apple(pos);
                break;

            case PickableType.ExtraLife:
                p = new ExtraLife(pos);
                break;

            case PickableType.Crystal:
                p = new CrystalPickable(pos);
                break;
            }

            if (p != null)
            {
                objectsLoadable.Add(p);
            }
        }