Ejemplo n.º 1
0
        public Prop SpawnProp(PropTemplate template, Vec2 position, bool make_player = false, bool is_trigger = false)
        {
            Body  physics = null;
            Shape shape   = null;

            if (template.Image.Height > 0)
            {
                physics = LevelContext.Context.PhysicsContext.CreateBody(new BodyDef()
                {
                    LinearDamping = template.Mass * 10f * template.Friction,
                    FixedRotation = true,
                    Position      = position,
                });
                var box = new PolygonDef()
                {
                    IsSensor = is_trigger, Density = template.CanMove ? 1.0f : 0.0f, Friction = template.Friction
                };
                box.Filter.MaskBits = (ushort)(template.Collides ? 1 : 0);
                box.SetAsBox(template.PhysicsBounds.X / 2f, template.PhysicsBounds.Y / 2f, new Vec2(template.PhysicsBounds.X / 2, template.PhysicsBounds.Y / 2f), 0.0f);
                shape = physics.CreateShape(box);
                physics.SetMassFromShapes();
            }
            var prop = new Prop(template, LevelContext.Context.ActiveLevel, physics, shape);

            _props.Add(prop);
            physics?.SetUserData(prop);

            if (make_player)
            {
                LevelContext.Context.Player = prop;
            }
            return(prop);
        }
Ejemplo n.º 2
0
        public void OnSave()
        {
            if (string.IsNullOrEmpty(NameField.text))
            {
                return;
            }
            eventsOff_ = true;
            var template = PropTemplate.Create(
                NameField.text,
                Props.ToArray(),
                DescriptionField.text);

            template.Save();
            SavesListBox.Populate();
            eventsOff_ = false;
            OnNameChanged();
        }