Display() public method

Update the contents of the target texture
public Display ( ) : void
return void
Ejemplo n.º 1
0
        public MapGraphicsComponent(TmxMap Map)
        {
            var tileWidth = Map.Tilesets.Single().TileWidth;
            var tileHeight = Map.Tilesets.Single().TileHeight;
            var tileSpacing = Map.Tilesets.Single().Spacing;
            var tileMargins = Map.Tilesets.Single().Margin;

            texture = new RenderTexture((uint)(Map.Width * tileWidth), (uint)(Map.Height * tileHeight));

            foreach (var layer in Map.Layers)
            {
                foreach (var tile in layer.Tiles)
                {
                    var columns = (int)tileset.Texture.Size.X / (tileWidth + tileSpacing);

                    int x = (tile.Gid - 1) % columns,
                        y = (tile.Gid - 1) / columns;

                    tileset.TextureRect = new IntRect(x * (tileWidth + tileSpacing) + tileMargins,
                                                        y * (tileHeight + tileSpacing) + tileMargins, tileWidth,
                                                        tileHeight);
                    tileset.Position = new Vector2f(tile.X * tileWidth, tile.Y * tileHeight);

                    texture.Draw(tileset);
                }
            }

            texture.Display();
            Sprite = new Sprite(texture.Texture);
        }
Ejemplo n.º 2
0
        private void SetupGrid(Vector2u mapSize)
        {
            const int gridSize = 16;
            _gridTexture = new RenderTexture(2000, 2000);
            var col = new Color(120, 120, 120);
            var verticies = new List<Vertex>();
            for (int x = 0; x < mapSize.X; x += gridSize)
            {
                verticies.Add(new Vertex(new Vector2f(x, 0), col));
                verticies.Add(new Vertex(new Vector2f(x, mapSize.Y), col));
            }
            for (int y = 0; y < mapSize.Y; y += gridSize)
            {
                verticies.Add(new Vertex(new Vector2f(0, y), col));
                verticies.Add(new Vertex(new Vector2f(mapSize.X, y), col));
            }
            _gridlines = verticies.ToArray();

            _gridTexture.Clear(new Color(190, 190, 190));
            //_view = new View(new FloatRect(0,0,displaySize.X, displaySize.Y));
            _view = new View(new FloatRect(0, 0, DisplayView.Size.X, DisplayView.Size.Y));
            DisplayView = _view;
            //_gridTexture.SetView(_view);
            _gridTexture.Draw(_gridlines, PrimitiveType.Lines);
            _gridTexture.Display();

            _grid = new Sprite(_gridTexture.Texture);
            AddItemToDraw(_grid, 0);
        }
Ejemplo n.º 3
0
        public static bool CreateShadows()
        {

            Image img = spriteSheet.Texture.CopyToImage();

            for (uint k = 0; k < img.Size.X; k++)
                for (uint j = 0; j < img.Size.Y; j++)
                {
                    Color c = img.GetPixel(k, j);
                    if (c.A == 255)
                    {
                        Color d = new Color();
                        d.A = 40;
                        d.R = d.G = d.B = 0;
                        img.SetPixel(k, j, d);
                    }
                }

            Texture tex = new Texture(img);
            Sprite tempsprite = new Sprite();
            tempsprite.Texture = tex;

            shadowSpriteSheet = new RenderTexture(textureSize, textureSize);
            shadowSpriteSheet.Draw(tempsprite);
            shadowSpriteSheet.Display();

            shadowSprite.Texture = shadowSpriteSheet.Texture;

            img.Dispose();
            tempsprite.Dispose();
            tex.Dispose();

            return true;
        }
Ejemplo n.º 4
0
        public static void Main(String[] args)
        {
            RenderWindow window = new RenderWindow(new VideoMode(1000, 700), "title");
            RenderTexture tex = new RenderTexture(1000, 700);
            Sprite texSprite = new Sprite(tex.Texture);

            Fractal fractal = new Fractal();

            fractal.CreateTreeFractal(500, 700, 3, 100, 0);
            Console.WriteLine(fractal.Nodes.Count);

            while (window.IsOpen())
            {
                window.Clear();
                tex.Clear(new Color(0, 0, 0, 200
                    ));
                foreach (Shape s in fractal.Nodes)
                {
                    window.Draw(s);
                }
                tex.Display();
                window.Draw(texSprite);
                window.Display();
                Image img = window.Capture();
                img.SaveToFile("C:/i.png");
                Console.ReadLine();
            }
        }
Ejemplo n.º 5
0
 public FastTextureAtlas(TextureAtlas atlas)
 {
     TextureAtlas = atlas;
     _atlas = new Sprite(TextureAtlas.Texture);
     RenderTexture = new RenderTexture(atlas.Size, atlas.Size);
     RenderTexture.Draw(_atlas);
     RenderTexture.Display();
     _replace = new RenderStates(BlendMode.None, Transform.Identity, null, null);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// .ctor
 /// </summary>
 public ScreenSaverEngine(ScreenSaverSettings settings)
 {
     _viewPorts = new ViewPortCollection(settings.IsFullscreen, settings.IsMultiMonitorEnabled);
     _canvas = new RenderTexture((uint) _viewPorts.WorkingArea.Width, (uint) _viewPorts.WorkingArea.Height, false);
     _canvas.Clear(Color.Black);
     _canvas.Display(); // Needed due to FBO causing inverted co-ords otherwise
     _chrono = new Chrono();
     _fpsLimiter = new FpsLimiter(settings.MaxFps);
 }
        private void RenderBuggy()
        {
            shapeTwo.Position = new Vector2f(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y);

            textureTwo.Clear();
            textureTwo.Draw(shapeTwo);
            textureTwo.Display();

            window.Clear();
            var renderSprite = new Sprite(textureTwo.Texture);

            window.Draw(renderSprite);
        }
Ejemplo n.º 8
0
        public GlyphStreamManager(GlyphStreamManagerConfig settings, Vector2u workingArea)
        {
            _workingArea = workingArea.ToRectangle();
            streams = new List<GlyphStream>();
            _settings = settings;

            if (!string.IsNullOrEmpty(settings.ShaderType)) // TODO: configurable shader
            {
                shader = ShaderWrapper.Get(settings.ShaderType);
                tempCanvas = new RenderTexture(workingArea.X, workingArea.Y, true);
                tempCanvas.Display();
            }

            _maximumStreams = settings.MaximumGlyphStreams;
            _chanceOfNewStream = settings.ChanceOfNewGlyphStream;
        }
        private void RenderWorking()
        {
            window.Clear(Color.Black);

            textureOne.Clear(Color.White);
            textureOne.Display();

            var renderSprite = new Sprite(textureOne.Texture);

            // Note #2
            // renderSprite.Position = new Vector2f(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y);

            renderSprite.Draw(window, RenderStates.Default);

            // Note #1
            // window.Display();
        }
Ejemplo n.º 10
0
        private void RenderMoreBuggy()
        {
            textureThree.Clear(new Color(
                                   (byte)(DateTime.Now.Millisecond % 128),
                                   (byte)(DateTime.Now.Millisecond % 64),
                                   (byte)(DateTime.Now.Millisecond % 255)
                                   ));
            textureThree.Display();

            shapeThree.Position = new Vector2f(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y);
            shapeThree.Rotation = 0.36f * DateTime.Now.Millisecond;
            textureThree.Draw(shapeThree);

            window.Clear();
            var renderSprite = new Sprite(textureThree.Texture);

            window.Draw(renderSprite);
        }
Ejemplo n.º 11
0
        private Texture getBackgroundTexture()
        {
            var sprBack = new Sprite(Root.Singleton.Material("img/map/map_back.png"));
            var sprSectorBackground = new Sprite(Root.Singleton.Material(Sector.Background));
            var sprMask = new Sprite(Root.Singleton.Material("img/map/map_zonemask_white.png"));
            var sprOverlay = new Sprite(Root.Singleton.Material("img/map/map_overlay.png"));

            sprBack.Position += new Vector2f(0, 28);
            sprSectorBackground.Position += new Vector2f(0, 28);
            sprMask.Position += new Vector2f(0, 28);
            sprOverlay.Position += new Vector2f(0, 28);

            var rt = new RenderTexture(1000, 1000);

            rt.Draw(sprBack);
            rt.Draw(sprSectorBackground);
            rt.Draw(sprMask, new RenderStates(BlendMode.Multiply));
            rt.Draw(sprOverlay);

            rt.Display();
            return new Texture(rt.Texture);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Draw the Surface.
        /// </summary>
        /// <param name="x">The X position offset.</param>
        /// <param name="y">The Y position offset.</param>
        public override void Render(float x = 0, float y = 0)
        {
            Display();

            SFMLDrawable = RenderShaders();

            base.Render(x, y);

            if (saveNextFrame) {
                saveNextFrame = false;
                var saveTarget = new RenderTexture((uint)Width, (uint)Height);
                saveTarget.Draw(SFMLDrawable, states);
                saveTarget.Display();
                saveTarget.Texture.CopyToImage().SaveToFile(saveNameFramePath);
                saveTarget.Dispose();
            }

            if (AutoClear) Clear();
        }
Ejemplo n.º 13
0
        public void Start()
        {
            System.Drawing.Rectangle r = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
            RenderWindow window = new RenderWindow(new VideoMode(1024, 786), "One Bullet", Styles.Titlebar | Styles.Close, settings);
            window.LostFocus += (s, e) => { focus = false; };
            window.GainedFocus += (s, e) => { focus = true; };
            Width = (int)window.Size.X;
            Height = (int)window.Size.Y;
            window.Closed += window_Closed;

            window.KeyPressed += window_KeyPressed;
            window.KeyReleased += window_KeyReleased;

            Finish();

            player.OnShoot += Shoot;

            window.SetFramerateLimit(60);

            Font font = new Font("Content/consolas.ttf");

            Text healthText = new Text("", font, 72);
            healthText.Color = Color.Red;

            Text dialog = new Text("", font, 48);
            dialog.Color = new Color(128, 128, 128);

            Texture bulletUI = new Texture("Content/bulletUI.png");

            RectangleShape bulletRect = new RectangleShape();
            bulletRect.Size = new Vector2f(72, 108);
            bulletRect.Origin = new Vector2f(72, 108);
            bulletRect.Texture = bulletUI;

            light = new RenderTexture(window.Size.X, window.Size.Y);

            lightCircle = new CircleShape(0, 20);

            RectangleShape lightDisplay = new RectangleShape();
            lightDisplay.Size = new Vector2f(window.Size.X, window.Size.Y);
            lightDisplay.Position = new Vector2f();

            blur = new Shader("Content/blur.vs", "Content/blur.fs");
            blur.SetParameter("rad", 0.004f);

            RenderStates blurStates = new RenderStates(RenderStates.Default);
            blurStates.Shader = blur;

            RectangleShape imageFrame = new RectangleShape();
            imageFrame.Position = new Vector2f(Width / 2 - 400, 16);
            imageFrame.Size = new Vector2f(800, 600);

            Texture white = new Texture(1, 1);
            Texture blood = new Texture("Content/bloodOverlay.png");

            Text startBtn = new Text("START GAME", font, 100);
            startBtn.Position = new Vector2f(Width / 2 - startBtn.GetGlobalBounds().Width / 2, Height / 5);

            bloodSystem = new ParticleSystem(new Texture("Content/bloodParticle.png"));

            Texture aimImage = new Texture("Content/finalScene.png");

            Text copyright = new Text("Game by WebFreak001. Made for Ludum Dare 28", font, 48);
            copyright.Position = new Vector2f(Width / 2 - copyright.GetLocalBounds().Width / 2, 32);

            bool mouseOld = false;

            #region Achivements

            if (!File.Exists("ach.txt"))
            {
                File.WriteAllText("ach.txt", "0:0\n1:0\n2:0");
            }

            achivements = new Dictionary<int, Achivement>();
            string[] achs = File.ReadAllLines("ach.txt");
            bool done1 = false;
            bool done2 = false;
            bool done3 = false;
            if (achs.Length > 2)
            {
                if (achs[0].StartsWith("0"))
                {
                    char c = achs[0].Last();
                    if (c == '1') done1 = true;
                }
                if (achs[1].StartsWith("1"))
                {
                    char c = achs[1].Last();
                    if (c == '1') done2 = true;
                }
                if (achs[2].StartsWith("1"))
                {
                    char c = achs[2].Last();
                    if (c == '1') done3 = true;
                }
            }
            achivements.Add(0, new Achivement() { Done = done1, Text = "Start the game" });
            achivements.Add(1, new Achivement() { Done = done2, Text = "You Missed" });
            achivements.Add(2, new Achivement() { Done = done3, Text = "Finish the Game" });

            Texture achiveTex = new Texture("Content/achivement.png");
            achiveTex.Smooth = true;
            RectangleShape achTL = new RectangleShape();
            RectangleShape achT = new RectangleShape();
            RectangleShape achTR = new RectangleShape();
            RectangleShape achL = new RectangleShape();
            RectangleShape achR = new RectangleShape();
            RectangleShape achBL = new RectangleShape();
            RectangleShape achB = new RectangleShape();
            RectangleShape achBR = new RectangleShape();
            RectangleShape ach = new RectangleShape();

            achTL.TextureRect = new IntRect(0, 0, 32, 32);
            achT.TextureRect = new IntRect(31, 0, 2, 32);
            achTR.TextureRect = new IntRect(32, 0, 32, 32);
            achL.TextureRect = new IntRect(0, 31, 32, 2);
            achR.TextureRect = new IntRect(32, 31, 32, 2);
            achBL.TextureRect = new IntRect(0, 32, 32, 32);
            achB.TextureRect = new IntRect(31, 32, 2, 32);
            achBR.TextureRect = new IntRect(32, 32, 32, 32);
            ach.TextureRect = new IntRect(31, 31, 2, 2);

            achTL.Position = new Vector2f(Width / 2 - 232, 16);
            achT.Position = new Vector2f(Width / 2 - 200, 16);
            achTR.Position = new Vector2f(Width / 2 + 200, 16);
            achL.Position = new Vector2f(Width / 2 - 232, 48);
            achR.Position = new Vector2f(Width / 2 + 200, 48);
            achBL.Position = new Vector2f(Width / 2 - 232, 118);
            achB.Position = new Vector2f(Width / 2 - 200, 118);
            achBR.Position = new Vector2f(Width / 2 + 200, 118);
            ach.Position = new Vector2f(Width / 2 - 200, 48);

            achTL.Size = new Vector2f(32, 32);
            achT.Size = new Vector2f(400, 32);
            achTR.Size = new Vector2f(32, 32);
            achL.Size = new Vector2f(32, 70);
            achR.Size = new Vector2f(32, 70);
            achBL.Size = new Vector2f(32, 32);
            achB.Size = new Vector2f(400, 32);
            achBR.Size = new Vector2f(32, 32);
            ach.Size = new Vector2f(400, 70);

            achTL.Texture = achiveTex;
            achT.Texture = achiveTex;
            achTR.Texture = achiveTex;
            achL.Texture = achiveTex;
            achR.Texture = achiveTex;
            achBL.Texture = achiveTex;
            achB.Texture = achiveTex;
            achBR.Texture = achiveTex;
            ach.Texture = achiveTex;

            Text achivementGetText = new Text("Achivement Get!", font, 40);
            achivementGetText.Position = new Vector2f(Width / 2 - 200, 32);
            achivementGetText.Color = Color.Black;
            Text achivementContent = new Text("", font, 26);
            achivementContent.Position = new Vector2f(Width / 2 - 200, 80);
            achivementContent.Color = Color.Black;

            Text fps = new Text("", font, 20);
            fps.Position = new Vector2f(16, 16);

            #endregion

            while (window.IsOpen())
            {
                window.DispatchEvents();

                light.Clear(Color.Transparent);
                window.Clear(Color.Black);

                if (playing)
                {
                    if (aiming)
                    {
                        imageFrame.Texture = aimImage;
                        window.Draw(imageFrame);
                        if (Mouse.IsButtonPressed(Mouse.Button.Left) && !mouseOld)
                        {
                            Vector2i m = Mouse.GetPosition(window);
                            if (m.X > imageFrame.Position.X && m.Y > imageFrame.Position.Y && m.X < imageFrame.Position.X + imageFrame.Size.X && m.Y < imageFrame.Position.Y + imageFrame.Size.Y)
                            {
                                Finish();
                            }
                            else
                            {
                                Achivement(1);
                                Finish();
                            }
                        }
                        mouseOld = Mouse.IsButtonPressed(Mouse.Button.Left);
                    }
                    else
                    {
                        if (focus)
                        {
                            if (up) player.MoveAbsolute(0, -1);
                            if (down) player.MoveAbsolute(0, 1);
                            if (left) player.MoveAbsolute(-1, 0);
                            if (right) player.MoveAbsolute(1, 0);
                            int result = level.Move(player.PreUpdate());

                            if (result == 1 || result == 2) player.Update();
                            else if (result == 3) Finish();
                            else if (result == 4)
                            {
                                WriteLn("I must kill IT");
                                WriteLn("I've found a gun... But it has only 1 Bullet.");
                                level.RemoveGun();
                                player.Arm();
                                player.Update();
                            }
                            else if (result == 5)
                            {
                                WriteLn("But I have only 1 try. If i don't hit him he will call the police");
                                WriteLn("In there is the man who had sex with my wife!");
                                WriteLn("That's the Office...");
                                player.Update();
                            }
                            else player.Stuck();

                            if (level.Intersect(player) || suiciding)
                            {
                                player.Health--;
                                recentAttack = 10;
                                bloodSystem.Emit(player.Location);
                                level.ShakeScreen(0.4f, 1);
                                if (player.Health <= 0)
                                {
                                    Dead();
                                }
                            }
                            if (Mouse.IsButtonPressed(Mouse.Button.Left) && !mouseOld)
                            {
                                player.Shoot();
                            }
                            mouseOld = Mouse.IsButtonPressed(Mouse.Button.Left);
                        }
                        if (drawCliparts)
                        {
                            imageFrame.Texture = cliparts[clipart];
                            window.Draw(imageFrame);
                        }
                        else
                        {

                            player.Rotate(Mouse.GetPosition(window) - level.offset.Vec2i);

                            level.Draw(window, player);

                            foreach (Location l in level.Lights)
                            {
                                Lighten(l * 32 + 16 + level.offset, 150.0f);
                            }

                            bloodSystem.Draw(window, level.offset);

                            player.Draw(window, level.offset);

                            Lighten(player.Location + level.offset, 100.0f, 0.5f);

                            light.Display();

                            lightDisplay.Texture = light.Texture;
                            lightDisplay.TextureRect = new IntRect(0, 0, (int)light.Size.X, (int)light.Size.Y);
                            blurStates.Texture = light.Texture;
                            window.Draw(lightDisplay, blurStates);

                            if (player.canShoot)
                            {
                                bulletRect.Position = new Vector2f(window.Size.X - 16, window.Size.Y - 16);
                                window.Draw(bulletRect);
                            }
                        }

                        healthText.DisplayedString = (player.Health * 0.1f) + "%";
                        healthText.Position = new Vector2f(16, window.Size.Y - healthText.GetGlobalBounds().Height - 48);
                        window.Draw(healthText);
                        dialog.CharacterSize = 42;
                        dialog.DisplayedString = ln1;
                        dialog.Position = new Vector2f(window.Size.X / 2 - dialog.GetGlobalBounds().Width / 2, window.Size.Y - 135);
                        window.Draw(dialog);
                        dialog.CharacterSize = 34;
                        dialog.DisplayedString = ln2;
                        dialog.Position = new Vector2f(window.Size.X / 2 - dialog.GetGlobalBounds().Width / 2, window.Size.Y - 90);
                        window.Draw(dialog);
                        dialog.CharacterSize = 26;
                        dialog.DisplayedString = ln3;
                        dialog.Position = new Vector2f(window.Size.X / 2 - dialog.GetGlobalBounds().Width / 2, window.Size.Y - 50);
                        window.Draw(dialog);

                        lightDisplay.Texture = blood;
                        lightDisplay.TextureRect = new IntRect(0, 0, 800, 600);
                        lightDisplay.FillColor = new Color(255, 255, 255, (byte)(recentAttack / 10.0f * 200));
                        window.Draw(lightDisplay);

                        recentAttack--;
                        recentAttack = Math.Max(recentAttack, 0);

                        lightDisplay.Texture = white;
                        lightDisplay.FillColor = new Color(255, 20, 23, (byte)((1000 - player.Health) / 1000.0f * 50));
                        window.Draw(lightDisplay);
                        lightDisplay.FillColor = Color.White;
                    }
                }
                else
                {
                    window.Draw(startBtn);
                    if (Mouse.IsButtonPressed(Mouse.Button.Left) && !mouseOld)
                    {
                        Vector2i p = Mouse.GetPosition(window);
                        if (p.Y > startBtn.Position.Y && p.Y < startBtn.Position.Y + 150)
                        {
                            ResumeGame();
                        }
                    }

                    mouseOld = Mouse.IsButtonPressed(Mouse.Button.Left);
                }
                if (achivement)
                {
                    window.Draw(achTL);
                    window.Draw(achT);
                    window.Draw(achTR);
                    window.Draw(achL);
                    window.Draw(ach);
                    window.Draw(achR);
                    window.Draw(achBL);
                    window.Draw(achB);
                    window.Draw(achBR);
                    window.Draw(achivementGetText);
                    achivementContent.DisplayedString = achivementtext;
                    window.Draw(achivementContent);
                }

                window.Display();
            }
        }
Ejemplo n.º 14
0
        public static bool LoadTextures()
        {

            textures = new Dictionary<string, Texture>();

            spriteSheet = new RenderTexture(textureSize, textureSize);
            spriteSheetLocation = new Dictionary<string,Vector2i>();

            spriteSheet.Clear(new Color(0, 0, 0, 0));

            font = new Font(assembly.GetManifestResourceStream("TrainBox.8bit16.ttf"));

            textures.Add("player", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.player.png")));
            textures.Add("playerwalk1", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.playerwalk1.png")));
            textures.Add("playerwalk2", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.playerwalk2.png")));

            textures.Add("block", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.block.png")));
            textures.Add("box", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.box.png")));

            textures.Add("cranebottom", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.crane1.png")));
            textures.Add("cranesegment", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.crane2.png")));
            textures.Add("cranehook", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.crane3.png")));

            textures.Add("ladderbottom", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.ladder1.png")));
            textures.Add("laddersegment", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.ladder2.png")));

            textures.Add("conv1", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.conv1.png")));
            textures.Add("conv2", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.conv2.png")));
            textures.Add("convrail", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.conv3.png")));

            textures.Add("wagon", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.wagon.png")));

            textures.Add("key", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.key.png")));
            textures.Add("keylock", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.keylock.png")));
            textures.Add("keyblock", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.keyblock.png")));

            textures.Add("dynamite", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.dynamite.png")));
            textures.Add("detonator", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.detonatorbox.png")));
            textures.Add("detonatorhandle", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.detonatorhandle.png")));

            textures.Add("infobox", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.infobox.png")));

            textures.Add("star", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.star.png")));
            textures.Add("star2", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.star2.png")));
            textures.Add("star3", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.star3.png")));

            textures.Add("starblock", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.starblock.png")));
            textures.Add("starblock2", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.starblock2.png")));

            textures.Add("exit", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.exit.png")));
            textures.Add("exit1", new Texture(assembly.GetManifestResourceStream("TrainBox.gfx.exit1.png")));

            float x = 0;
            float y = 0;

            Sprite temp = new Sprite();

            foreach (KeyValuePair<string,Texture> a in textures )
            {
                temp.Position = new Vector2f(x, y);
                temp.Texture = a.Value;
                spriteSheet.Draw(temp);

                spriteSheetLocation.Add(a.Key, new Vector2i((int)x,(int)y));

                x += 16;

                if (x > textureSize - 16)
                {
                    x = 0;
                    y += 16;
                }
              
            }

            spriteSheet.Display();
            sprite.Texture = spriteSheet.Texture;

            textures = null;

            return true;
        }
Ejemplo n.º 15
0
        public void StartTrainBoxApp()
        {

            Level.PrepareEntityTypes();

            bool quit = false;

            TextureMan.LoadTextures();
            TextureMan.CreateShadows();

            bufferSpr = new Sprite();

            buffer = new RenderTexture(320, 120);
            buffer.Clear(Color.Black);

            menu.Active = true;
            menu.State = Menu.MenuState.Intro;
            menu.CounterReset();
            menu.LoadLevelInfo();

            while (true)
            {
                if (fullScreen)
                {
                    screenSizeX = 1366;
                    screenSizeY = 768;                    
                }
                else
                {
                    screenSizeX = 960;
                    screenSizeY = 540;                    
                }

                if (fullScreen) window = new RenderWindow(new VideoMode(screenSizeX, screenSizeY), 
                    "Super Starbox", Styles.Fullscreen);  
                else window = new RenderWindow(new VideoMode(screenSizeX, screenSizeY), 
                    "Super Starbox", Styles.Titlebar);
                    
                window.SetMouseCursorVisible(!fullScreen);

                window.SetVisible(true);
                window.Closed += new EventHandler(OnClosed);
                window.SetFramerateLimit(60);

                window.LostFocus += new EventHandler(OnLostFocus);
                window.GainedFocus += new EventHandler(OnGainedFocus);

                bool editorButtonTrigger = false;

                SoundMan.PlayMusic();

                while (true)
                {

                    buffer.Clear(Color.Black);

                    if (!menu.Active)
                    {
                        level.DrawLevel(buffer);
                    }
                    
                    
                    if (fadeOut != 0)
                    {
                        RectangleShape rect = new RectangleShape();

                        rect.Position = new Vector2f(0,0);
                        rect.Size = new Vector2f(320, 120);
                        rect.FillColor = new Color(0, 0, 0, (byte)fadeOut);

                        buffer.Draw(rect);
                    }

                    if (menu.Active) menu.Draw(buffer);
                    if (editor.Active) editor.Draw(buffer);

                    buffer.Display();

                    bufferSpr.Texture = buffer.Texture;
                    bufferSpr.Scale = new Vector2f((screenSizeX / 320f) * screenScale, (screenSizeY / 120f) * screenScale);
                    
                    bufferSpr.Origin = new Vector2f(160, 60);
                    bufferSpr.Position = new Vector2f(screenSizeX/2, screenSizeY/2);

                    if (screenShake > 0)
                    {
                        bufferSpr.Position = new Vector2f(bufferSpr.Position.X + (float)new Random().Next(-200,200)/75, 
                                                          bufferSpr.Position.Y + (float)new Random().Next(-200,200)/75);
                    }

                    if (gameState == GameState.ResetFadeOut)
                    {
                        
                        bufferSpr.Rotation = gameStateC / 2;

                        screenScale = 1f + (float)gameStateC / 50f;
              
                    }

                    if (gameState == GameState.LevelFinished)
                    {

                        bufferSpr.Rotation = gameStateC / 2;

                        screenScale = 1f + (float)gameStateC / 25f;

                    }
                    
                    if (gameState == GameState.ResetFadeIn)
                    {

                        bufferSpr.Rotation = (50-gameStateC) / 2;

                        screenScale = 1f + (float)(50 - gameStateC) / 50f;

                    }                    

                    if (gameState == GameState.GamePlay || menu.Active)
                    {
                        screenScale = 1;
                        bufferSpr.Rotation = 0;
                    }

                    window.DispatchEvents();
                    window.Clear(Color.Black);
                    window.Draw(bufferSpr);
                    window.Display();


                    if (Keyboard.IsKeyPressed(Keyboard.Key.F4))
                    {
                        fullScreen = !fullScreen;
                        break;
                    }

                    if (Keyboard.IsKeyPressed(Keyboard.Key.F10) && false)
                    {
                        if (!menu.Active)
                        if (!editorButtonTrigger)
                        {
                            editor.Active = !editor.Active;
                            if (editor.Active)
                            {
                                editor.LevelName = levelName;
                                level.ResetLevel();
                                level.ResetScrollBounds();
                                CollisionMan.Entities = level.GetEntities();
                                EntityFinder.Entities = level.GetEntities();
                                editor.Level = level;
                            }
                            else
                            {
                                levelName = editor.LevelName;
                                level = editor.Level;
                                level.FindScrollBounds();
                                gameState = GameState.StartLevel;
                            }
                        }
                        editorButtonTrigger = true;
                    }
                    else editorButtonTrigger = false;

                    if (!editor.Active && !menu.Active)
                    {
                        GameLoop();
                    }

                    if (editor.Active) if (windowHasFocus) editor.Loop(window);
                    if (menu.Active)
                    {
                        if (windowHasFocus) menu.Loop(window);

                        if (menu.State == Menu.MenuState.Quit)
                        {
                            quit = true;
                            break;
                        }

                        if (menu.State == Menu.MenuState.StartLevel)
                        {
                            levelName = menu.LevelName;

                            menu.Active = false;
                            level.LoadLevel(levelName);

                            gameStateC = 0;
                            gameState = GameState.ResetFadeIn;
                            fadeOut = 255;

                            CollisionMan.Entities = level.GetEntities();
                            EntityFinder.Entities = level.GetEntities();
                        }
                    }
                }

                window.Dispose();
                if (quit) break;
            }

            menu.SaveLevelInfo();
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            RenderWindow window = new RenderWindow(new SFML.Window.VideoMode(800, 600), "Title");

            RenderTexture treeTexture = new RenderTexture(800, 600);
            Sprite treeSprite = new Sprite(treeTexture.Texture);

            // List of tree nodes.
            List<Node> nodes = new List<Node>();
            List<Node> dividedNodes = new List<Node>();

            DateTime timeOfLastDraw = DateTime.Now;
            // Create root node.
            Node root = new Node(new SFML.Window.Vector2f(5, 2));
            root.Origin = new SFML.Window.Vector2f(1, 0);
            root.Position = new SFML.Window.Vector2f(400, 600);
            root.FillColor = new Color(0, 200, 50);
            root.Generation = 1;
            nodes.Add(root);

            DateTime timeOfLastUpdate = DateTime.Now;

            // Loop
            while (window.IsOpen())
            {
                window.Clear(Color.White);

                for (int i = 0; i < nodes.Count; i++)
                {
                    treeTexture.Draw(nodes[i]);
                    if (nodes[i].Divided)
                    {
                        dividedNodes.Add(nodes[i]);
                        nodes.RemoveAt(i);
                        continue;
                    }
                    // Grow the node until it meets its max size.
                    else if (nodes[i].Size.Y > -25)
                    {
                        nodes[i].Size += new SFML.Window.Vector2f(0, -100 * (float)(Utilities.GetTimeDifference(timeOfLastUpdate)));
                    }
                    else // Node reached maximum size and can be cloned.
                    {
                        // Mark current node as divided, meaning it won't get any more branches and will be ignored by the loop.
                        nodes[i].Divided = true;

                        // Decide if current branch will extend.
                        if (rnd.Next(0, 101) > 20)
                        {
                            nodes.Add(AddBranch(nodes[i]));
                        }

                        // Devide if the branch will split.
                        if (rnd.Next(0, 101) > 40)
                        {
                            nodes.Add(AddBranch(nodes[i], true));
                        }
                    }
                }
                timeOfLastUpdate = DateTime.Now;
                treeTexture.Display();

                window.Draw(treeSprite);
                foreach (Node node in dividedNodes)
                {
                    treeTexture.Draw(node);
                }

                window.Display();
            }
        }
Ejemplo n.º 17
0
        private RenderTexture GetRenderTexture()
        {
            int wallThickness = 2;
            int tileBorderThickness = 1;

            // Colours
            var colTile = new Color(228, 226, 216);
            var colWall = new Color(0, 0, 0);
            var colTileBorder = new Color(198, 196, 192);
            var colSystem = new Color(128, 128, 128);
            //colTile = new Color(0, 0, 50);

            // Vectors
            var origin = new Vector2f(Ship.FloorOffsetX, Ship.FloorOffsetY);
            var tileX = new Vector2f(Ship.TileWidth, 0.0f);
            var tileY = new Vector2f(0.0f, Ship.TileHeight);
            var tileBorder = new Vector2f(tileBorderThickness / 2, tileBorderThickness / 2);
            var wallX = new Vector2f(wallThickness / 2, 0.0f);
            var wallY = new Vector2f(0.0f, wallThickness / 2);

            // Textures
            Texture baseGraphic = Root.Singleton.Material(Ship.BaseGraphic, false);
            Texture floorGraphic = Root.Singleton.Material(Ship.FloorGraphic, false);

            var rtWidth = baseGraphic.Size.X;
            var rtHeight = baseGraphic.Size.Y;
            RenderTexture rt = new RenderTexture(rtWidth, rtHeight);
            rt.Clear(new Color(0, 0, 0, 0));

            // Draw the ship and floor
            DrawTexture(rt, new Vector2f(0.0f, 0.0f), new Vector2f(rtWidth, rtHeight), baseGraphic);
            if (!ShowRooms) return rt;
            DrawTexture(rt, new Vector2f(0.0f, 0.0f), new Vector2f(rtWidth, rtHeight), floorGraphic);

            // Draw rooms
            foreach (var room in Ship.Rooms)
            {
                var roomCorner = origin + tileX * room.X + tileY * room.Y;
                var roomCenter = roomCorner + tileX * (room.GetBoundingBox().Left + (float)room.GetBoundingBox().Width / 2) +
                                              tileY * (room.GetBoundingBox().Top + (float)room.GetBoundingBox().Height / 2);
                foreach (var tile in room.GetTiles())
                {
                    var tileCorner = roomCorner + tileX * tile.X + tileY * tile.Y;
                    DrawQuad(rt, tileCorner + tileBorder, tileCorner + tileX + tileY - tileBorder, colTile);
                    DrawLine(rt, tileCorner, tileCorner + tileX, colTileBorder, tileBorderThickness);
                    DrawLine(rt, tileCorner + tileY + wallX, tileCorner + wallX, colTileBorder, tileBorderThickness);
                }
                if (room.BackgroundGraphic != null)
                {
                    var roomGraphic = Root.Singleton.Material(room.BackgroundGraphic, false);
                    DrawTexture(rt, roomCorner, roomCorner + new Vector2f(roomGraphic.Size.X, roomGraphic.Size.Y), roomGraphic);
                }
                if (room.System != null)
                {
                    var system = Root.Singleton.mgrState.Get<Library>().GetSystem(room.System);
                    if (system != null)
                    {
                        var systemGraphic = Root.Singleton.Material(system.IconGraphics["overlay"], false);
                        if (systemGraphic != null)
                        {
                            DrawColoredTexture(rt, roomCenter - new Vector2f(systemGraphic.Size.X, systemGraphic.Size.Y) / 2,
                                                   roomCenter + new Vector2f(systemGraphic.Size.X, systemGraphic.Size.Y) / 2, systemGraphic, colSystem);
                        }
                    }
                }
            }

            // Draw walls
            foreach (var room in Ship.Rooms)
            {
                var roomCorner = origin + tileX * room.X + tileY * room.Y;
                foreach (var tile in room.GetTiles())
                {
                    var tileCorner = roomCorner + tileX * tile.X + tileY * tile.Y;

                    // Top
                    if (!room.HasTile(tile.X, tile.Y - 1))
                    {
                        DrawLine(rt, tileCorner + wallY, tileCorner + tileX + wallY, colWall, wallThickness);
                    }

                    // Right
                    if (!room.HasTile(tile.X + 1, tile.Y))
                    {
                        DrawLine(rt, tileCorner + tileX - wallX, tileCorner + tileX + tileY - wallX, colWall, wallThickness);
                    }

                    // Bottom
                    if (!room.HasTile(tile.X, tile.Y + 1))
                    {
                        DrawLine(rt, tileCorner + tileX + tileY - wallY, tileCorner + tileY - wallY, colWall, wallThickness);
                    }

                    // Left
                    if (!room.HasTile(tile.X - 1, tile.Y))
                    {
                        DrawLine(rt, tileCorner + tileY + wallX, tileCorner + wallX, colWall, wallThickness);
                    }
                }
            }

            // Doorways
            foreach (var door in Ship.Doors)
            {
                foreach (var entrance in door.Entrances)
                {
                    if (!Ship.Rooms.Contains(entrance.RoomID)) continue;
                    var room = Ship.Rooms[entrance.RoomID];
                    var tileCorner = origin + tileX * (room.X + entrance.X) + tileY * (room.Y + entrance.Y);
                    switch (entrance.Direction)
                    {
                        case Door.Direction.Up:
                            DrawLine(rt, tileCorner + tileX * 0.14F + wallY, tileCorner + tileX * (1 - 0.14F) + wallY, colTile, wallThickness);
                            break;
                        case Door.Direction.Down:
                            DrawLine(rt, tileCorner + tileX * 0.14F + tileY - wallY, tileCorner + tileX * (1 - 0.14F) + tileY - wallY, colTile, wallThickness);
                            break;
                        case Door.Direction.Left:
                            DrawLine(rt, tileCorner + tileY * 0.14F + wallX, tileCorner + tileY * (1 - 0.14F) + wallX, colTile, wallThickness);
                            break;
                        case Door.Direction.Right:
                            DrawLine(rt, tileCorner + tileY * 0.14F + tileX - wallX, tileCorner + tileY * (1 - 0.14F) + tileX - wallX, colTile, wallThickness);
                            break;
                    }
                }
            }

            // TODO: oxygen, breaches, fire, etc.
            rt.Display();
            return rt;
        }
Ejemplo n.º 18
0
        private void generate_texture()
        {
            buttons = new RenderTexture(button.Size.X, button.Size.Y);
            buttons.Draw(new Sprite(new Texture(button)));

            text_on_button.Position += new Vector2f(10, button.Size.Y / 4 - 10);
            buttons.Draw(text_on_button);

            text_on_button.Position += new Vector2f(5, button.Size.Y / 2 + 3);
            buttons.Draw(text_on_button);

            buttons.Display();
        }
Ejemplo n.º 19
0
        void renderPoints()
        {
            points_of_all_blockdomino = new RenderTexture(image_of_blockdomino.Size.X * 7, image_of_blockdomino.Size.Y / 2);
            points_of_all_blockdomino.Clear(Color.Transparent);
            Shape circle = new CircleShape(3);
            //circle.Position = new Vector2f(10, 4);
            circle.FillColor = Color.Black;

            //drawable

            {
                for (int i = 1; i < 7; i++)
                {
                    for (int j = 0; j < i; j++)
                    {
                        if (i <= 3)
                        {
                            circle.Position = new Vector2f(image_of_blockdomino.Size.X * (i) + image_of_blockdomino.Size.X * j / i + 5, image_of_blockdomino.Size.Y / 4 - 5);
                        }
                        else
                        {
                            if (j < (i / 2))
                            {
                                circle.Position = new Vector2f(image_of_blockdomino.Size.X * (i) + image_of_blockdomino.Size.X * j / i + 7, image_of_blockdomino.Size.Y / 4 - 10);
                            }
                            else
                            {
                                circle.Position = new Vector2f(image_of_blockdomino.Size.X * (i) + image_of_blockdomino.Size.X * (j - 2) / i + 7, image_of_blockdomino.Size.Y / 4);
                            }
                        }
                        points_of_all_blockdomino.Draw(circle);
                    }
                }
            }
            points_of_all_blockdomino.Display();
        }
Ejemplo n.º 20
0
        private void renderTextures()
        {
            texture_of_all_blockdomino = new RenderTexture(image_of_blockdomino.Size.X * 7, image_of_blockdomino.Size.Y * 7);
            Texture block_domino = new Texture(image_of_blockdomino);
            block_domino.Repeated = true;
            Sprite newSprite = new Sprite(block_domino, new IntRect(0, 0, (int)image_of_blockdomino.Size.X * 7, (int)image_of_blockdomino.Size.Y * 7));
            texture_of_all_blockdomino.Draw(newSprite);

            //
            for(int i=0 ; i<=6; i++)
                for (int j = 0; j <= 6; j++)
                {
                    Sprite upSprite = get_point(i);
                    upSprite.Position += new Vector2f(image_of_blockdomino.Size.X * j, image_of_blockdomino.Size.Y * i);

                    Sprite downSprite = get_point(j);
                    downSprite.Position += new Vector2f(image_of_blockdomino.Size.X * j, image_of_blockdomino.Size.Y * i + image_of_blockdomino.Size.Y/2);

                    texture_of_all_blockdomino.Draw(upSprite);
                    texture_of_all_blockdomino.Draw(downSprite);
                }

            texture_of_all_blockdomino.Display();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Pres the render and draw background and tiles.
        /// </summary>
        void PreRenderAndDrawBackground(RenderWindow context, Controller c)
        {
            if (PreRenderTexture == null || c.ResetGraphics) {
            c.ResetGraphics = false;
            PreRenderTexture = new RenderTexture ((uint)Game.Width, (uint)Game.Height, false);

              PreRenderTexture.Draw (DAO.GetSprite (Element.HDOcean));

            foreach (Tile tile in c.LevelMap.CollisionTiles.Values) {
              tile.UpdatePosition ();
              PreRenderTexture.Draw (tile.DstSprite);
            }
            PreRenderTexture.Display ();
            BackgroundAndTilesSprite = new Sprite (PreRenderTexture.Texture);
              } else {
            context.Draw (BackgroundAndTilesSprite);
              }
        }
Ejemplo n.º 22
0
        private Texture GetHullMeterTexture()
        {
            var sprOverlay = new Sprite(Root.Singleton.Material((100 * PlayerShip.Hull / PlayerShip.MaxHull > 25) ?
                                                                "img/statusUI/top_hull.png" :
                                                                "img/warnings/top_hull_red.png"));

            var sprMask = new Sprite(Root.Singleton.Material("img/statusUI/top_hull_bar_mask.png"));
            sprMask.Position = new Vector2f(11, 0);

            var shpBars = new RectangleShape(new Vector2f(sprMask.Texture.Size.X * PlayerShip.Hull / PlayerShip.MaxHull, sprMask.Texture.Size.Y));
            shpBars.Position = new Vector2f(11, 0);
            shpBars.FillColor = Color.Green;

            var rt = new RenderTexture(sprOverlay.Texture.Size.X, sprOverlay.Texture.Size.Y);
            rt.Draw(shpBars);
            rt.Draw(sprMask, new RenderStates(BlendMode.Multiply));
            rt.Draw(sprOverlay);

            rt.Display();

            return new Texture(rt.Texture);
        }