Ejemplo n.º 1
0
        public static Deco CreateDeco(DecoMetadata decoMD, Coord2D coords, Coord2D relativeCoords, int altitude)
        {
            Type type = Type.GetType(decoMD.TypeName);
            var  deco = Activator.CreateInstance(type) as Deco;

            deco.Position       = World.IsoFlatCoordToWorldPosition(coords);
            deco.PositionOffset = decoMD.PositionOffset;
            deco.Coords         = relativeCoords;
            deco.Altitude       = altitude;
            deco.IsSolid        = decoMD.IsSolid == BooleanEnum.True ? true : false;
            // Odd NxN takes priority over even NxN when coords along same horizontal line.
            deco.Dimensions = decoMD.Dimensions;
            if (deco.Dimensions.X % 2 == 0)
            {
                deco.DrawPriority = -1;
            }
            var rand = new Random();

            // Create deco animator.
            var spriteSheet = SpriteSheet.CreateNew(decoMD.Texture, decoMD.ContentPath, decoMD.SheetRows, decoMD.SheetColumns);

            deco.Animator = new Animator(deco, spriteSheet, decoMD.StartFrame, decoMD.CurrentFrame, decoMD.FrameCount, decoMD.FrameSpeed, decoMD.AnimState);

            for (int i = 0; i < decoMD.Dimensions.X; i++)
            {
                for (int j = 0; j < decoMD.Dimensions.Y; j++)
                {
                    for (int k = 0; k < decoMD.Dimensions.Z; k++)
                    {
                        deco.OccupiedCoords.Add(new Coord3D(deco.Coords, deco.Altitude) + new Coord3D(i - decoMD.Dimensions.X / 2, -j + decoMD.Dimensions.Y / 2, k));
                    }
                }
            }

            if (decoMD.AnimState == AnimationState.None)
            {
                var i  = rand.Next(0, decoMD.ActiveFrames.Count());
                var cf = decoMD.ActiveFrames.ToArray()[i];
                deco.Animator.CurrentFrame = cf;
            }
            else
            {
                deco.Animator.CurrentFrame = decoMD.CurrentFrame;
            }

            return(deco);
        }
Ejemplo n.º 2
0
        public static Cube CreateCube(CubeMetadata cubeTopMD, CubeMetadata cubeBaseMD, Coord2D isoFlatCoord, Coord3D isoCoord3D)
        {
            var cube = new Cube()
            {
                Position = World.IsoFlatCoordToWorldPosition(isoFlatCoord),
                Coords   = new Coord2D(isoCoord3D.X, isoCoord3D.Y),
                Altitude = isoCoord3D.Z
            };
            var rand = new Random();

            // Create cube top animator.
            var spriteSheet = SpriteSheet.CreateNew(cubeTopMD.Texture, cubeTopMD.ContentPath, cubeTopMD.SheetRows, cubeTopMD.SheetColumns);

            cube.AnimatorTop = new Animator(cube, spriteSheet, cubeTopMD.StartFrame, cubeTopMD.CurrentFrame, cubeTopMD.FrameCount, cubeTopMD.FrameSpeed, cubeTopMD.AnimState);
            if (cubeTopMD.AnimState == AnimationState.None)
            {
                var i  = rand.Next(0, cubeTopMD.ActiveFrames.Count());
                var cf = cubeTopMD.ActiveFrames.ToArray()[i];
                cube.AnimatorTop.CurrentFrame = cf;
            }
            else
            {
                cube.AnimatorTop.CurrentFrame = cubeTopMD.CurrentFrame;
            }

            // Create cube base animator.
            var spriteSheetBase = SpriteSheet.CreateNew(cubeBaseMD.Texture, cubeBaseMD.ContentPath, cubeBaseMD.SheetRows, cubeBaseMD.SheetColumns);

            cube.AnimatorBase = new Animator(cube, spriteSheetBase, cubeBaseMD.StartFrame, cubeBaseMD.CurrentFrame, cubeBaseMD.FrameCount, cubeBaseMD.FrameSpeed, cubeBaseMD.AnimState);
            if (cubeBaseMD.AnimState == AnimationState.None)
            {
                var i  = rand.Next(0, cubeBaseMD.ActiveFrames.Count());
                var cf = cubeBaseMD.ActiveFrames.ToArray()[i];
                cube.AnimatorBase.CurrentFrame = cf;
            }
            else
            {
                cube.AnimatorBase.CurrentFrame = cubeBaseMD.CurrentFrame;
            }

            return(cube);
        }