示例#1
0
        static Position GetStartPosition(Map.CharacterReference characterReference)
        {
            var position = characterReference.Positions[0];

            // The positions are stored 1-based.
            return(new Position(position.X - 1, position.Y - 1));
        }
示例#2
0
 private MapCharacter2D(Game game, IRenderView renderView, Layer layer, IMapManager mapManager,
                        RenderMap2D map, uint characterIndex, Map.CharacterReference characterReference)
     : base(game, renderView.GetLayer(layer), TextureAtlasManager.Instance.GetOrCreate(layer),
            renderView.SpriteFactory, () => AnimationProvider(game, map.Map, mapManager,
                                                              characterReference, renderView.GraphicProvider), map, GetStartPosition(characterReference),
            () => Math.Max(1, map.Map.PaletteIndex) - 1, () => NullOffset)
 {
     this.game               = game;
     this.map                = map.Map;
     tileset                 = mapManager.GetTilesetForMap(this.map);
     this.characterIndex     = characterIndex;
     this.characterReference = characterReference;
     lastTimeSlot            = game.GameTime.TimeSlot;
 }
示例#3
0
        static Character2DAnimationInfo AnimationProvider(Game game, Map map, IMapManager mapManager,
                                                          Map.CharacterReference characterReference, IGraphicProvider graphicProvider)
        {
            bool usesTileset = characterReference.CharacterFlags.HasFlag(Flags.UseTileset);

            if (usesTileset)
            {
                var tileset = mapManager.GetTilesetForMap(map);
                var tile    = tileset.Tiles[characterReference.GraphicIndex - 1];

                return(new Character2DAnimationInfo
                {
                    FrameWidth = RenderMap2D.TILE_WIDTH,
                    FrameHeight = RenderMap2D.TILE_HEIGHT,
                    StandFrameIndex = tile.GraphicIndex - 1,
                    SitFrameIndex = 0,
                    SleepFrameIndex = 0,
                    NumStandFrames = (uint)tile.NumAnimationFrames,
                    NumSitFrames = 0,
                    NumSleepFrames = 0,
                    TicksPerFrame = map.TicksPerAnimationFrame * 2,
                    NoDirections = true,
                    IgnoreTileType = true,
                    UseTopSprite = false
                });
            }
            else
            {
                var playerAnimationInfo = game.GetPlayerAnimationInfo();
                return(new Character2DAnimationInfo
                {
                    FrameWidth = 16,  // NPC width
                    FrameHeight = 32, // NPC height
                    StandFrameIndex = Graphics.GetNPCGraphicIndex(map.NPCGfxIndex, characterReference.GraphicIndex, graphicProvider),
                    SitFrameIndex = playerAnimationInfo.SitFrameIndex,
                    SleepFrameIndex = playerAnimationInfo.SleepFrameIndex,
                    NumStandFrames = NumNPCFrames[(graphicProvider.NPCGraphicOffsets.TryGetValue((int)map.NPCGfxIndex, out int offset) ? offset : 0) + characterReference.GraphicIndex],