Пример #1
0
 public MyGame()
 {
     _graphics             = new GraphicsDeviceManager(this);
     _inputProvider        = new KeyboardInputProvider();
     _spritePack           = new SpritePack();
     Content.RootDirectory = "Content";
 }
Пример #2
0
        public SpritePack Load(IEnumerable <SpriteSheetDto> sheets)
        {
            var pack = new SpritePack();

            foreach (var sheet in sheets)
            {
                if (!_textures.TryGetValue(sheet.TextureName, out var texture))
                {
                    texture = _manager.Load <Texture2D>(sheet.TextureName);
                    _textures.Add(sheet.TextureName, texture);
                }

                foreach (var sprite in sheet.Sprites)
                {
                    SetSprite(pack, sprite.Key, ToSprite(sprite.Value, texture));
                }
            }

            return(pack);
        }
Пример #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load all sprites
            var mapJson = File.ReadAllText("Content/External/sprite_maps.json");
            var sheets  = JsonConvert.DeserializeObject <SpriteSheetDto[]>(mapJson);

            _spritePack = new SpritePackLoader(Content).Load(sheets);

            // Create walking sprite
            var animation = new AnimatedSprite(new []
            {
                _spritePack.King1,
                _spritePack.King2,
                _spritePack.King3,
                _spritePack.King4
            }, 300);

            // Create Player
            _player = new PlayerEntity(_spritePack.King1, animation, Vector2.One, 0.5f);
        }
Пример #4
0
        private static void SetSprite(SpritePack pack, string name, Sprite value)
        {
            switch (name)
            {
            case "King1":
                pack.King1 = value;
                break;

            case "King2":
                pack.King2 = value;
                break;

            case "King3":
                pack.King3 = value;
                break;

            case "King4":
                pack.King4 = value;
                break;

            case "King5":
                pack.King5 = value;
                break;

            case "King6":
                pack.King6 = value;
                break;

            case "King7":
                pack.King7 = value;
                break;

            case "King8":
                pack.King8 = value;
                break;
            }
        }