Exemplo n.º 1
0
        public override void Read(GameAssetStore store, IDeserializer context)
        {
            base.Read(store, context);
            this.Crew           = context.Read <int>("crew");
            this.Passengers     = context.Read <int>("passengers");
            this.Acceleration   = context.Read <float>("acceleration");
            this.TurnSpeed      = context.Read <float>("turn_speed");
            this.MaxHealth      = context.Read <float>("health");
            this.Mass           = context.Read <float>("mass");
            this.RadarRadius    = context.Read <float>("radar");
            this.EnginePosition = context.Read <Vector2>("engine", CommonSerialize.Read);
            var spriteName = context.Read <string>("sprite");

            this.SpriteTemplate = store.Sprites[spriteName];
            var weapons = context.ReadList("weapons", (ctx) =>
            {
                var name = ctx.Read <string>("weapon");
                var pos  = ctx.Read <Vector2>("pos", CommonSerialize.Read);
                return(new WeaponPlacement
                {
                    Weapon = store.Objects.Get <WeaponTemplate>(name),
                    LocalPosition = pos,
                });
            });

            this.AddWeapons(weapons);
        }
        public SpriteCompositeTemplate AddTemplate(SpriteTransform transform, ISpriteTemplate template)
        {
            var def = new TemplateDefinition
            {
                Template = template,
                Transform = transform
            };

            this.templateDefinitions.Add(def);
            return this;
        }
Exemplo n.º 3
0
        public override void Read(GameAssetStore store, IDeserializer context)
        {
            base.Read(store, context);
            this.ProjectileVelocity = context.Read <float>("projectile_velocity");
            this.ProjectileMass     = context.Read <float>("projectile_mass");
            this.FireRate           = TimeSpan.FromSeconds(context.Read <double>("fire_rate"));
            this.Damage             = context.Read <float>("damage");
            var spriteName = context.Read <string>("sprite");

            this.SpriteTemplate = store.Sprites[spriteName];
        }
Exemplo n.º 4
0
        public static void Save(BinaryWriter writer, ISpriteTemplate sprite)
        {
            var asSheet = sprite as SingleSpriteFromSheetTemplate;

            if (asSheet != null)
            {
                var index = asSheet.Parent.IndexOf(asSheet);
                writer.Write((byte)TagSpriteFromSheet);
                writer.Write(asSheet.Parent.Name);
                writer.Write((Int32)index);
            }
            else
            {
                writer.Write((byte)TagGeneralSprite);
                writer.Write(sprite.Name);
            }
        }
Exemplo n.º 5
0
        private static void Write(ISerializer context, ISpriteTemplate sprite)
        {
            var asSheet = sprite as SingleSpriteFromSheetTemplate;

            if (asSheet != null)
            {
                var index = asSheet.Parent.IndexOf(asSheet);
                context.Write("type", 0);
                context.Write("parent", asSheet.Parent.Name);
                context.Write("index", index);
            }
            else
            {
                context.Write("type", 1);
                context.Write("sprite", sprite.Name);
            }
        }
Exemplo n.º 6
0
        public override void SetUp()
        {
            base.SetUp();

            Store.Instance.LoadFromJson("Content\\StopTheBoats.json");
            Store.Instance.LoadFromJson("Content\\BoundsEditor.json");

            this.cursor = Store.Instance.Sprites <SpriteTemplate>("BoundsEditor", "editor_cursor");

            foreach (var kvp in Store.Instance["StopTheBoats"].Sprites.All)
            {
                if (kvp.Value.Shape is PolygonShape)
                {
                    this.sprites.Add(kvp);
                }
            }

            this.SetCurrent(0);
        }
Exemplo n.º 7
0
        public static void Read(Store store, IDeserializer context, out ISpriteTemplate sprite)
        {
            var type = context.Read <int>("type");

            switch (type)
            {
            case 0:
                var parent = context.Read <string>("parent");
                var index  = context.Read <int>("index");
                sprite = (store.Sprites(parent) as SpriteSheetTemplate).Sprites[index];
                break;

            case 1:
                var name = context.Read <string>("sprite");
                sprite = store.Sprites(name);
                break;

            default:
                throw new InvalidOperationException("Unknown sprite type");
            }
        }
Exemplo n.º 8
0
 public SpriteImage(ISpriteTemplate sprite, Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null) : base(size, anchor, offset)
 {
     this.Sprite = sprite;
     UpdateStyle(DefaultStyle);
 }
 public SpriteCompositeTemplate AddTemplate(ISpriteTemplate template, SpriteTransform transform = null)
 {
     return this.AddTemplate(transform, template);
 }
Exemplo n.º 10
0
 public VisibleObjectPrefab(PlatformContext context, ISpriteTemplate sprite)
 {
     this.context = context;
     this.sprite  = sprite;
 }
Exemplo n.º 11
0
 public AttachedObject(IGameContext context, ISpriteTemplate spriteTemplate) : base(context)
 {
     this.sprite = new Sprite(spriteTemplate);
 }
Exemplo n.º 12
0
 public FixedObstacle(IGameContext context, World world, ISpriteTemplate sprite) : base(context, world, sprite)
 {
     this.Body.BodyType       = BodyType.Static;
     this.Fixture.Restitution = 0.001f;
 }