Beispiel #1
0
        private static void InstantiateCrate(XmlNode objectNode, Dictionary <int, XmlNode> dictProperties, ref Dictionary <BorderCrate, int> borderCrates,
                                             ref Dictionary <int, TriggerIronCrate> triggerCrates, ref Dictionary <int, TriggerNitroCrate> triggerNitros, ref List <ICheckpointLoadable> objectLoadable, ref List <CheckpointCrate> checkpoints)
        {
            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];
            XmlNodeList childList     = properties.ChildNodes;
            XmlNode     propertyCrate = SearchNodeWithAttribute(ref childList, "name", "crateType");
            CrateType   type          = (CrateType)int.Parse(propertyCrate.Attributes["value"].Value);

            Crate c = null;

            switch (type)
            {
            case CrateType.Apple:
                c = new AppleCrate(pos);
                break;

            case CrateType.Random:
                c = new RandomCrate(pos);
                break;

            case CrateType.Life:
                c = new LifeCrate(pos);
                break;

            case CrateType.Aku:
                c = new AkuAkuCrate(pos);
                break;

            case CrateType.Bounce_Apple:
                c = new AppleBounceCrate(pos);
                break;

            case CrateType.Bounce_Wooden:
                c = new WoodenBounceCrate(pos);
                break;

            case CrateType.Bounce_Iron:
                c = new IronBounceCrate(pos);
                break;

            case CrateType.Iron:
                c = new IronCrate(pos);
                break;

            case CrateType.Trigger_Iron:

                c = new TriggerIronCrate(pos);
                XmlNode idCrate = objectNode.FirstChild.LastChild;
                int     id      = int.Parse(idCrate.Attributes["value"].Value);
                triggerCrates.Add(id, (TriggerIronCrate)c);
                break;

            case CrateType.Tnt:
                c = new TntCrate(pos);
                break;

            case CrateType.Nitro:
                c = new NitroCrate(pos);

                if (objectNode.HasChildNodes)
                {
                    XmlNodeList list = objectNode.FirstChild.ChildNodes;
                    XmlNode     node = SearchNodeWithAttribute(ref list, "name", "vTriggerNitroId");
                    if (node != null)
                    {
                        int idN = int.Parse(node.Attributes["value"].Value);
                        if (idN > 0)
                        {
                            triggerNitros[idN].AddNitroCrate((NitroCrate)c);
                        }
                    }
                }

                break;

            case CrateType.Border_Crate:

                XmlNode   borderTypeNode = objectNode.FirstChild.FirstChild;
                CrateType borderType;

                if (borderTypeNode.Attributes["name"].Value.Equals("borderCrate"))
                {
                    borderType = (CrateType)int.Parse(borderTypeNode.Attributes["value"].Value);
                }
                else
                {
                    borderType = CrateType.Iron;
                }

                BorderCrate b = new BorderCrate(pos, borderType);
                borderCrates.Add(b, int.Parse(objectNode.FirstChild.LastChild.Attributes["value"].Value));
                objectLoadable.Add(b);
                return;

            case CrateType.Trigger_Iron_Nitro:
                c = new TriggerNitroCrate(pos);
                XmlNode idNitroCrate = objectNode.FirstChild.LastChild;
                int     idTrigger    = int.Parse(idNitroCrate.Attributes["value"].Value);
                triggerNitros.Add(idTrigger, (TriggerNitroCrate)c);
                break;

            case CrateType.Checkpoint_Crate:
                checkpoints.Add(new CheckpointCrate(pos));
                return;
            }

            if (c != null)
            {
                objectLoadable.Add(c);
            }
            //if (c != null && objectNode.HasChildNodes)
            //{
            //    if (objectNode.FirstChild.FirstChild.Attributes["name"].Value == "useGravity")
            //        c.UseGroundableGravity = bool.Parse(objectNode.FirstChild.FirstChild.Attributes["value"].Value);
            //}
        }
        public BorderCrate(Vector2 position, CrateType type) : base(position, "borderCrate", DrawManager.Layer.Playground)
        {
            Crate c = null;

            switch (type)
            {
            case CrateType.Apple:
                c = new AppleCrate(position);
                break;

            case CrateType.Random:
                c = new RandomCrate(position);
                break;

            case CrateType.Life:
                c = new LifeCrate(position);
                break;

            case CrateType.Aku:
                c = new AkuAkuCrate(position);
                break;

            case CrateType.Bounce_Apple:
                c = new AppleBounceCrate(position);
                break;

            case CrateType.Bounce_Wooden:
                c = new WoodenBounceCrate(position);
                break;

            case CrateType.Bounce_Iron:
                c = new IronBounceCrate(position);
                break;

            case CrateType.Iron:
                c = new IronCrate(position);
                break;

            case CrateType.Trigger_Iron:
                c = new TriggerIronCrate(position);
                break;

            case CrateType.Tnt:
                c = new TntCrate(position);
                break;

            case CrateType.Nitro:
                c = new NitroCrate(position);
                break;

            default:
                c = new IronCrate(position);
                break;
            }

            Crate = c;

            clipTriggered   = AudioManager.GetAudioClip("crateTriggered");
            crateTriggered  = false;
            timeToTriggered = TIME_TO_TRIGGER_CRATE;

            PhysicsManager.RemoveItem(RigidBody);
            RigidBody = null;
        }