GetFrame() public method

public GetFrame ( int frame ) : SLPFrame
frame int
return SLPFrame
示例#1
0
        public static void Initialize()
        {
            var style = Styles.Titlebar | Styles.Close;
            size = new Vector2f(Configuration.Width, Configuration.Height);

            Window = new RenderWindow(new VideoMode(Configuration.Width, Configuration.Height), "Open Empires", style);
            Window.SetFramerateLimit(Configuration.Framerate);
            Window.SetVerticalSyncEnabled(Configuration.VSync);

            Window.Closed += (sender, args) => Window.Close();
            Window.Resized += (sender, args) => Resize(new Vector2f(args.Width, args.Height));
            /*Window.MouseButtonPressed += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, true, args.X, args.Y));
            Window.MouseButtonReleased += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, false, args.X, args.Y));
            Window.MouseWheelMoved += (sender, args) => DispatchEvent(new MouseWheelInputArgs(args.Delta, args.X, args.Y));
            Window.MouseMoved += (sender, args) => DispatchEvent(new MouseMoveInputArgs(args.X, args.Y));*/

            Window.MouseMoved += new EventHandler<MouseMoveEventArgs>(Window_MouseMoved);
            Window.MouseWheelMoved += (sender, args) =>
            {
                /* Mouse wheel zoom implementation where the view will zoom
                 * towards the area the cursor is pointing to
                 */
                var mousePos = Mouse.GetPosition(Window);
                float relX = (float) mousePos.X / Window.Size.X - 0.5f;
                float relY = (float) mousePos.Y / Window.Size.Y - 0.5f;

                GameView.Move(new Vector2f {
                    X = relX * GameView.Size.X,
                    Y = relY * GameView.Size.Y
                });

                GameView.Zoom(1 - (args.Delta * 0.1f));

                GameView.Move(new Vector2f {
                    X = -relX * GameView.Size.X,
                    Y = -relY * GameView.Size.Y
                });
            };

            Window.KeyPressed += (sender, args) =>
            {
                KeyStates[(int)args.Code] = true;
            };

            Window.KeyReleased += (sender, args) =>
            {
                KeyStates[(int)args.Code] = false;
            };

            Blendomatic.ReadBlendomatic(new System.IO.FileStream("blendomatic.dat", System.IO.FileMode.Open));
            map = new Map();

            GameView = new View(DefaultView);
            GameView.Center = new Vector2f((map.Width/2)*96, 0);

            var blend = Blendomatic.BlendingModes[2];
            var tile = blend.Tiles[12];

            var img = new Image(97, 49);
            for (var y = 0; y < img.Size.Y; y++)
                for (var x = 0; x < img.Size.X; x++)
                    img.SetPixel((uint)x, (uint)y, new Color(255, 0, 0, 0));

            var i = 0;
            for (var y = 0; y < img.Size.X; y++)
            {
                var bytesPerRow = y < 24 ? 1 + (4 * y) : 97 - (4 * (y - 24));

                var startX = 48 - (bytesPerRow / 2);
                for (var x = 0; x < bytesPerRow; x++)
                    img.SetPixel((uint)(startX + x), (uint)y, new Color(0, 0, 0, tile[i++]));
            }

            var slpFile = new SLPFile();
            slpFile.LoadFile("textures/ter15002.slp");

            var spritewidth = slpFile.GetFrame(0).m_Width;
            var spriteheight = slpFile.GetFrame(0).m_Height;

            var imgg = new Image((uint)spritewidth, (uint)(spriteheight ), slpFile.GetFrame(0).GetRGBAArray());

            for (var y = 0; y < imgg.Size.Y; y++)
                for (var x = 0; x < imgg.Size.X; x++)
                {
                    var col = imgg.GetPixel((uint)x, (uint)y);
                    col.A = (byte)(Math.Min(255, (128-img.GetPixel((uint)x, (uint)y).A)*2));

                    if (img.GetPixel((uint)x, (uint)y).R == 255)
                        col.A = 0;

                    imgg.SetPixel((uint)x, (uint)y, col);
                }

            selected = new Sprite(new Texture(imgg));

            /* blend sand to forest now */

            var blend2 = Blendomatic.BlendingModes[2];
            var tile2 = blend2.Tiles[12];

            var img2 = new Image(97, 49);
            for (var y = 0; y < img2.Size.Y; y++)
                for (var x = 0; x < img2.Size.X; x++)
                    img2.SetPixel((uint)x, (uint)y, new Color(255, 0, 0, 0));

            var i2 = 0;
            for (var y = 0; y < img.Size.X; y++)
            {
                var bytesPerRow = y < 24 ? 1 + (4 * y) : 97 - (4 * (y - 24));

                var startX = 48 - (bytesPerRow / 2);
                for (var x = 0; x < bytesPerRow; x++)
                    img2.SetPixel((uint)(startX + x), (uint)y, new Color(0, 0, 0, tile[i2++]));
            }

            var slpFile2 = new SLPFile();
            slpFile2.LoadFile("textures/ter15017.slp");

            var spritewidth2 = slpFile2.GetFrame(0).m_Width;
            var spriteheight2 = slpFile2.GetFrame(0).m_Height;

            var imgg2 = new Image((uint)spritewidth2, (uint)(spriteheight2), slpFile2.GetFrame(0).GetRGBAArray());

            for (var y = 0; y < imgg2.Size.Y; y++)
                for (var x = 0; x < imgg2.Size.X; x++)
                {
                    var col = imgg2.GetPixel((uint)x, (uint)y);
                    col.A = (byte)(Math.Min(255, (128 - img.GetPixel((uint)x, (uint)y).A) * 2));

                    if (img2.GetPixel((uint)x, (uint)y).R == 255)
                        col.A = 0;

                    imgg2.SetPixel((uint)x, (uint)y, col);
                }

            selected2 = new Sprite(new Texture(imgg2));

            EntManager = new EntityManager();
        }
示例#2
0
        private void LoadTerrainTexture(byte tex)
        {
            var slpFile = new SLPFile();
            slpFile.LoadFile("textures/ter" + Configuration.TerrainTextureLookups[tex] + ".slp");

            var spritewidth = slpFile.GetFrame(0).m_Width;
            var spriteheight = slpFile.GetFrame(0).m_Height;

            List<byte> constructorbot = new List<byte>(spritewidth * spriteheight * slpFile.m_Frames.Count);

            foreach (var frame in slpFile.m_Frames)
            {
                byte[] b = frame.GetRGBAArray();
                foreach (byte by in b)
                    constructorbot.Add(by);
            }

            var img = new Image((uint)spritewidth, (uint)(spriteheight * slpFile.m_Frames.Count), constructorbot.ToArray());

            tilesetTextures[tex] = new Texture(img);
        }