Example #1
0
        public static void PlaySong(string name)
        {
            if (player == null)
            {
                return;
            }
            if (Mix.FileExists(name))
            {
                var sound  = new Sound();
                var data   = Mix.GetBytes(name);
                var exInfo = new CREATESOUNDEXINFO()
                {
                    cbsize = 112,
                    length = (uint)data.Length,
                };
                if (System.IO.File.Exists("kafe.dls"))
                {
                    exInfo.dlsname = "kafe.dls";
                }
                var ret = player.CreateSound(data, Mode.Loop | Mode.OpenMemory, ref exInfo, ref sound);
                if (ret != Result.OK)
                {
                    return;
                }
                ret = player.PlaySound(CHANNELINDEX.REUSE, sound, true, ref musicChannel);
                if (ret != Result.OK)
                {
                    return;
                }

                if (name.EndsWith(".ogg"))
                {
                    var  tag       = new TAG();
                    uint loopStart = 0;
                    uint loopEnd   = 0;
                    ret = sound.GetTag("LOOP_START", 0, ref tag);
                    if (ret != Result.ERR_TOOMANYCHANNELS)
                    {
                        if (ret != Result.ERR_TAGNOTFOUND)
                        {
                            loopStart = uint.Parse(tag.StringData);
                        }
                        ret = sound.GetTag("LOOP_END", 0, ref tag);
                        if (ret != Result.ERR_TAGNOTFOUND)
                        {
                            loopEnd = uint.Parse(tag.StringData);
                        }
                        if (loopEnd > 0)
                        {
                            sound.SetLoopPoints(loopStart, TIMEUNIT.PCM, loopEnd, TIMEUNIT.PCM);
                        }
                    }
                }

                musicChannel.SetPaused(false);
            }
        }
Example #2
0
        public void Reload(string jsonFile, int palIndex, bool refresh)
        {
            Console.WriteLine("Loading Character from \"{0}\"...", jsonFile);
            json = Mix.GetJson("fighters\\" + jsonFile, false) as JsonObj;
            Name = json.Path <string>("/name");
            var baseName = json.Path <string>("/base");

            var keys = new string[json.Keys.Count];

            json.Keys.CopyTo(keys, 0);
            foreach (var key in keys)
            {
                if (json[key] is string && ((string)json[key]).StartsWith("import://"))
                {
                    json[key] = Mix.GetJson("fighters\\" + ((string)json[key]).Substring(9));
                }
            }

            atlas = Atlas.FromJson(json["sprites"]);
            json.Remove("sprites");

            if (sheets.ContainsKey(baseName) && !refresh)
            {
                Console.WriteLine("Reusing spritesheet \"{0}\"...", baseName);
                sheet = sheets[baseName];
                if (palettes.ContainsKey(baseName))
                {
                    palette = palettes[baseName];
                }
                if (icons.ContainsKey(baseName))
                {
                    icon = icons[baseName];
                }
            }
            else
            {
                Console.WriteLine("Loading spritesheet \"{0}\"...", baseName);
                sheet            = Mix.GetTexture("fighters\\" + baseName);
                sheets[baseName] = sheet;

                if (Mix.FileExists("fighters\\" + baseName + "-pal.png"))
                {
                    palette            = Mix.GetTexture("fighters\\" + baseName + "-pal.png");
                    palettes[baseName] = palette;

                    var timer1 = DateTime.Now;
                    Console.WriteLine("Palette start at {0}", timer1.ToLongTimeString());

                    var numPals     = palette.Height;
                    var paletteData = new int[palette.Width * palette.Height];
                    palette.GetData(paletteData);
                    var spriteData = new int[sheet.Width * sheet.Height];
                    sheet.GetData(spriteData);
                    for (var j = 0; j < spriteData.Length; j++)
                    {
                        for (var p = 0; p < palette.Width; p++)
                        {
                            if (spriteData[j] == paletteData[p])
                            {
                                spriteData[j] = 0x10000000 + p;
                            }
                        }
                    }
                    sheet.SetData(spriteData);

                    ColorSwaps = numPals;
                    if (palIndex >= numPals)
                    {
                        palIndex %= numPals;
                    }
                    if (palIndex == 0)
                    {
                        palIndex++;
                    }

                    var timer2 = DateTime.Now;
                    Console.WriteLine("Palette end at {0}", timer2.ToLongTimeString());
                    var timer3 = timer2 - timer1;
                    Console.WriteLine("Palette remapping took {0}", timer3);
                }

                if (Mix.FileExists("fighters\\" + baseName + "-icon.png"))
                {
                    icon            = Mix.GetTexture("fighters\\" + baseName + "-icon.png");
                    icons[baseName] = icon;
                }
            }

            ColorSwap = palIndex;

            animations = json.Path <List <JsonObj> >("/animations");
            if (!refresh)
            {
                animation = animations[0];
            }
            else
            {
                animation = animations[(int)currentAnim];
            }
            Position = new Vector2(160, 160);
            SetupFrames();
            if (!refresh || currentFrame >= totalFrames)
            {
                currentFrame = 0;
            }
            SetupImage();

            MultiplyColor = new Vector4(1);
            AddColor      = new Vector4(0);

            inputSequence = string.Empty;
            Console.WriteLine("Finished loading {0}.", Name);
        }