Exemple #1
0
        private static DirSheet getDirSheetCache(string num, string pattern, LRUCache <string, DirSheet> cache)
        {
            DirSheet sheet;

            if (cache.TryGetValue(num, out sheet))
            {
                return(sheet);
            }

            try
            {
                if (System.IO.File.Exists(String.Format(pattern, num)))
                {
                    //read file and read binary data
                    using (FileStream stream = File.OpenRead(String.Format(pattern, num)))
                    {
                        using (BinaryReader reader = new BinaryReader(stream))
                        {
                            sheet = DirSheet.Load(reader);
                            cache.Add(num, sheet);
                            return(sheet);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DiagManager.Instance.LogError(new Exception("Error loading " + String.Format(pattern, num) + "\n", ex));
            }
            DirSheet newSheet = DirSheet.LoadError();

            cache.Add(num, newSheet);
            return(newSheet);
        }
Exemple #2
0
        public override void Draw(SpriteBatch spriteBatch, Loc offset)
        {
            if (Finished)
            {
                return;
            }

            DirSheet sheet = GraphicsManager.GetBackground(Anim.AnimIndex);

            int   frame = Time.ToFrames();
            Loc   diff  = Movement * frame / 60 - offset;
            float fade  = 1f;// (float)Math.Min(Math.Min(FadeTime, frame), (TotalTime > 0) ? Math.Min(FadeTime, TotalTime - frame) : FadeTime) / FadeTime;

            if (sheet.Width == 1 && sheet.Height == 1)
            {
                sheet.DrawTile(spriteBatch, new Rectangle(0, 0, GraphicsManager.ScreenWidth, GraphicsManager.ScreenHeight), 0, 0, Color * ((float)Anim.Alpha * fade / 255f));
            }
            else
            {
                for (int x = diff.X % sheet.TileWidth - sheet.TileWidth; x < GraphicsManager.ScreenWidth; x += sheet.TileWidth)
                {
                    for (int y = diff.Y % sheet.TileHeight - sheet.TileHeight; y < GraphicsManager.ScreenHeight; y += sheet.TileHeight)
                    {
                        sheet.DrawDir(spriteBatch, new Vector2(x, y), Anim.GetCurrentFrame(Time, sheet.TotalFrames), Anim.AnimDir, Color * ((float)Anim.Alpha * fade / 255f));
                    }
                }
            }
        }
Exemple #3
0
        public static string GetExportString(DirSheet sheet, string basename)
        {
            string suffix = "";

            switch (sheet.Dirs)
            {
            case RotateType.None:
            {
                if (sheet.TileWidth == sheet.TileHeight)
                {
                    suffix = sheet.Dirs.ToString();
                }
                else
                {
                    suffix = sheet.TotalFrames.ToString();
                }
            }
            break;

            default:
                suffix = sheet.Dirs.ToString();
                break;
            }
            return(basename + "." + suffix);
        }
Exemple #4
0
        public static DirSheet GetAttackSheet(string num)
        {
            IEffectAnim sheet;

            if (vfxCache.TryGetValue("Particle-" + num, out sheet))
            {
                return((DirSheet)sheet);
            }

            try
            {
                if (File.Exists(String.Format(PARTICLE_PATTERN, num)))
                {
                    //read file and read binary data
                    using (FileStream fileStream = File.OpenRead(String.Format(PARTICLE_PATTERN, num)))
                    {
                        using (BinaryReader reader = new BinaryReader(fileStream))
                        {
                            sheet = DirSheet.Load(reader);
                            vfxCache.Add("Particle-" + num, sheet);
                            return((DirSheet)sheet);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DiagManager.Instance.LogError(new Exception("Error loading " + String.Format(PARTICLE_PATTERN, num) + "\n", ex));
            }
            DirSheet newSheet = DirSheet.LoadError();

            vfxCache.Add("Particle-" + num, newSheet);
            return(newSheet);
        }
Exemple #5
0
        public override void Draw(SpriteBatch spriteBatch, Loc offset)
        {
            Loc drawLoc = GetDrawLoc(offset);

            DirSheet sheet = GraphicsManager.GetItem(Sprite);

            sheet.DrawDir(spriteBatch, drawLoc.ToVector2(), 0);
        }
Exemple #6
0
 public void Draw(SpriteBatch spriteBatch, Loc parentLoc, Dir8 dir, int locHeight, float sizeRatio)
 {
     foreach (MultiAnimSprite sprite in Sprites)
     {
         DirSheet sheet = GraphicsManager.GetAttackSheet(sprite.AnimIndex);
         sheet.DrawDir(spriteBatch, new Vector2(parentLoc.X, parentLoc.Y - locHeight) + sprite.Position.ToVector2() * sizeRatio, sprite.Frame, DirExt.AddAngles(dir, sprite.AnimDir), Color.White * ((float)sprite.Alpha / 255));
     }
 }
Exemple #7
0
        public override void Draw(SpriteBatch spriteBatch, Loc offset)
        {
            if (Finished)
            {
                return;
            }

            Loc drawLoc = GetDrawLoc(offset);

            DirSheet sheet = GraphicsManager.GetAttackSheet(Anim.AnimIndex);

            sheet.DrawDir(spriteBatch, new Vector2(drawLoc.X, drawLoc.Y - LocHeight), Anim.GetCurrentFrame(ActionTime + FrameOffset, GraphicsManager.GetAttackSheet(Anim.AnimIndex).TotalFrames), Anim.GetDrawDir(Direction), Color.White * ((float)Anim.Alpha / 255));
        }
Exemple #8
0
        public override void Draw(SpriteBatch spriteBatch, Loc offset)
        {
            if (Finished)
                return;

            Loc drawLoc = GetDrawLoc(offset);
            Loc modOffset = new Loc(GraphicsManager.ScreenWidth - offset.X % GraphicsManager.ScreenWidth, GraphicsManager.ScreenHeight - offset.Y % GraphicsManager.ScreenHeight);
            drawLoc = drawLoc + modOffset;
            Vector2 drawDest = new Vector2(drawLoc.X % GraphicsManager.ScreenWidth, (drawLoc.Y - LocHeight) % GraphicsManager.ScreenHeight);

            DirSheet sheet = GraphicsManager.GetAttackSheet(Anim.AnimIndex);
            sheet.DrawDir(spriteBatch, drawDest, Anim.GetCurrentFrame(ActionTime, GraphicsManager.GetAttackSheet(Anim.AnimIndex).TotalFrames), DirExt.AddAngles(Direction, Anim.AnimDir), Color.White * ((float)Anim.Alpha / 255));

        }
Exemple #9
0
        public override void Update(BaseScene scene, FrameTick elapsedTime)
        {
            CurrentBurstTime += elapsedTime;
            while (CurrentBurstTime >= Math.Max(1, BurstTime))
            {
                CurrentBurstTime -= Math.Max(1, BurstTime);
                for (int ii = 0; ii < ParticlesPerBurst; ii++)
                {
                    if (Anims.Count > 0)
                    {
                        List <int> openDirs  = getOpenDirs();
                        int        openIndex = openDirs[MathUtils.Rand.Next(openDirs.Count)];
                        Coverages[openIndex] = true;

                        double angle = (openIndex + MathUtils.Rand.NextDouble()) * Math.PI / 4;

                        int dist       = StartDistance + MathUtils.Rand.Next(StartVariance + 1);
                        Loc startDelta = new Loc((int)Math.Round(Math.Cos(angle) * dist), (int)Math.Round(Math.Sin(angle) * dist));

                        double endAngle = MathUtils.Rand.NextDouble() * Math.PI * 2;
                        int    endDist  = MathUtils.Rand.Next(EndDistance + 1);
                        Loc    endDelta = new Loc((int)Math.Round(Math.Cos(endAngle) * endDist), (int)Math.Round(Math.Sin(endAngle) * endDist));

                        Loc particleSpeed = ((UseDest ? Destination : Origin) + endDelta - (Origin + startDelta)) * GraphicsManager.MAX_FPS / TravelTime;

                        Loc startLoc = Origin + startDelta;
                        {
                            AnimData animData   = Anims[MathUtils.Rand.Next(Anims.Count)];
                            AnimData scaledAnim = new AnimData(animData);
                            DirSheet fxSheet    = GraphicsManager.GetAttackSheet(animData.AnimIndex);
                            scaledAnim.FrameTime = (int)Math.Round((float)TravelTime / scaledAnim.GetTotalFrames(fxSheet.TotalFrames) / Math.Max(1, Cycles));
                            scaledAnim.FrameTime = Math.Max(1, scaledAnim.FrameTime);
                            ParticleAnim anim = new ParticleAnim(scaledAnim, 0, TravelTime);
                            anim.SetupEmitted(startLoc, particleSpeed, Loc.Zero, 0, 0, 0, particleSpeed.ApproximateDir8());
                            scene.Anims[(int)Layer].Add(anim);
                        }
                    }
                }
                CurrentBursts++;

                if (CurrentBursts >= Math.Max(1, Bursts))
                {
                    break;
                }
            }
        }
Exemple #10
0
        public override void Draw(SpriteBatch spriteBatch, Loc offset)
        {
            if (Finished)
            {
                return;
            }

            DirSheet sheet = GraphicsManager.GetBackground(Anim.AnimIndex);

            int   frame = Time.ToFrames();
            Color color = StartColor;

            if (frame < FadeInTime)
            {
                color = interpolateColor(StartColor, EndColor, frame, FadeInTime);
            }
            else if (frame < FadeInTime + HoldTime)
            {
                color = EndColor;
            }
            else if (frame < FadeInTime + HoldTime + FadeOutTime)
            {
                int endTime = FadeInTime + HoldTime + FadeOutTime;
                color = interpolateColor(StartColor, EndColor, endTime - frame, FadeOutTime);
            }

            Loc diff = -offset;

            if (sheet.Width == 1 && sheet.Height == 1)
            {
                sheet.DrawTile(spriteBatch, new Rectangle(0, 0, GraphicsManager.ScreenWidth, GraphicsManager.ScreenHeight), 0, 0, color);
            }
            else
            {
                for (int x = diff.X % sheet.TileWidth - sheet.TileWidth; x < GraphicsManager.ScreenWidth; x += sheet.TileWidth)
                {
                    for (int y = diff.Y % sheet.TileHeight - sheet.TileHeight; y < GraphicsManager.ScreenHeight; y += sheet.TileHeight)
                    {
                        sheet.DrawDir(spriteBatch, new Vector2(x, y), Anim.GetCurrentFrame(Time, sheet.TotalFrames), Anim.GetDrawDir(Dir8.None), color);
                    }
                }
            }
        }
Exemple #11
0
 public static void Export(DirSheet sheet, string filepath)
 {
     using (Stream stream = new FileStream(filepath, FileMode.Create, FileAccess.Write, FileShare.None))
         ExportTex(stream, sheet.baseTexture);
 }