Esempio n. 1
0
        void DestroyableObjectComponent_OnDyingAnimationFinished(object sender, EventArgs e)
        {
            var entity = ((DyingComponent)sender).Parent;

            //Drops item
            if (DropsItem && DroppableItems.Count != 0)
            {
                Random rand     = new Random();
                float  chance   = (float)rand.NextDouble();
                float  droprate = DropRate;
                float  floor    = 0f;
                string item     = "";
                foreach (string i in DroppableItems)
                {
                    if (floor < chance && chance <= (droprate + floor))
                    {
                        item = i;
                        break;
                    }
                    floor    += droprate;
                    droprate /= DropCoefficient;
                }
                if (!string.IsNullOrEmpty(item))
                {
                    var powerup = EntityBlueprint.GetBlueprint(item).CreateEntity();
                    powerup.Size     = new Vector2(16, 16);
                    powerup.Position = new Vector2(Parent.Location.Center.X, Parent.Location.Top);
                    entity.Scene.AddEntity(powerup);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Loads a new Entity that can be used for the player.
        /// </summary>
        public static Entity LoadPlayerEntity()
        {
            // TODO: Allow support for different 'classes' by just using different blueprints.
            var Blueprint    = EntityBlueprint.GetBlueprint("Player");
            var PlayerEntity = Blueprint.CreateEntity();

            PlayerEntity.Size = new Vector2(36, 36);
            return(PlayerEntity);
        }
Esempio n. 3
0
        private void DropWeapon(string weaponToDrop, float launchModifier = 1f)
        {
            var mc        = this.GetDependency <MovementComponent>();
            var scene     = Parent.Scene;
            var oldWeapon = EntityBlueprint.GetBlueprint(weaponToDrop).CreateEntity();

            oldWeapon.Position = new Vector2(Parent.Position.X + -CorvusExtensions.GetSign(mc.CurrentDirection) * (Parent.Size.X + 5), Parent.Position.Y - Parent.Size.Y - 5);
            oldWeapon.Size     = new Vector2(22, 22);
            scene.AddEntity(oldWeapon);

            Random rand = new Random();
            float  rMod = (float)rand.Next(20, 50);
            var    pc   = oldWeapon.GetComponent <PhysicsComponent>();

            pc.Velocity = new Vector2(-CorvusExtensions.GetSign(mc.CurrentDirection) * 225f * launchModifier + rMod, -325f * launchModifier + rMod);
        }
Esempio n. 4
0
        private void GenerateCoinEntity(string coinName, float xmod)
        {
            var c = EntityBlueprint.GetBlueprint(coinName).CreateEntity();

            c.Size     = new Vector2(12, 12);
            c.Position = new Vector2(Parent.Location.Center.X, Parent.Location.Top);
            Parent.Scene.AddEntity(c);

            Random rand = new Random();
            var    pc   = c.GetComponent <PhysicsComponent>();

            pc.HorizontalDragCoefficient = 0.01f;
            pc.GravityCoefficient        = 0.2f;
            var mc = this.GetDependency <MovementComponent>();

            pc.VelocityX = ((mc == null) ? ((rand.Next(0, 5) <= 2) ? 1 : -1) : -CorvusExtensions.GetSign(mc.CurrentDirection)) * (50f * xmod);
        }
Esempio n. 5
0
        private static Entity ParseEntity(XmlNode ObjectNode)
        {
            float           Width         = float.Parse(ObjectNode.Attributes["width"].Value);
            float           Height        = float.Parse(ObjectNode.Attributes["height"].Value);
            float           X             = float.Parse(ObjectNode.Attributes["x"].Value);
            float           Y             = float.Parse(ObjectNode.Attributes["y"].Value);
            string          BlueprintName = ObjectNode.Attributes["type"].Value.Trim();
            string          EntityName    = ObjectNode.Attributes["name"] == null ? null : ObjectNode.Attributes["name"].Value.Trim();
            EntityBlueprint Blueprint     = EntityBlueprint.GetBlueprint(BlueprintName);
            Entity          Entity        = Blueprint.CreateEntity();

            if (!String.IsNullOrWhiteSpace(EntityName))
            {
                Entity.Name = EntityName;
            }
            Entity.Position = new Vector2(X, Y);
            Entity.Size     = new Vector2(Width, Height);

            foreach (XmlNode PropertiesNode in ObjectNode.SelectNodes("properties"))
            {
                foreach (XmlNode PropertyNode in PropertiesNode.SelectNodes("property"))
                {
                    string Name = PropertyNode.Attributes["name"].Value.Trim();
                    // So, this is quite a hack.
                    // Tiled doesn't allow us to re-order properties; it's all alphabetical.
                    // So we just support sticking a # in front of the property to make it go to the top of the list, and then ignore that #.
                    while (Name.FirstOrDefault() == '#')
                    {
                        Name = Name.Substring(1);
                    }
                    string   Value             = PropertyNode.Attributes["value"].Value.Trim();
                    string[] NamePropertySplit = Name.Split('.');
                    if (NamePropertySplit.Length != 2)
                    {
                        throw new FormatException("Expected object property name to be in the format of 'PathComponent.Nodes'.");
                    }
                    string            ComponentName  = NamePropertySplit[0].Trim();
                    string            PropertyName   = NamePropertySplit[1].Trim();
                    ComponentArgument Argument       = ComponentArgument.Parse(Value).Single();
                    ComponentProperty ParsedProperty = new ComponentProperty(ComponentName, PropertyName, Argument);
                    var Component = Entity.Components[ComponentName];
                    ParsedProperty.ApplyValue(Component);
                }
            }
            return(Entity);
        }