This class defines a sprite : texture, transformations, color, and draw on screen
See also the note on coordinates and undistorted rendering in SFML.Graphics.Transformable.
Inheritance: Transformable, Drawable
Example #1
0
        public override void Draw(RenderTarget rt)
        {
            Vector2f actualPosition = Position + (Selected ? new Vector2f(0, -12.0f - 5.0f * GetSelectedIndex()) : new Vector2f());

            // Draw card
            Sprite sprite = new Sprite(Assets.LoadTexture(Info.Type == CardType.White ? "CardWhite.png" : "CardBlack.png"));
            Size = new Vector2f(sprite.GetGlobalBounds().Width, sprite.GetGlobalBounds().Height);
            sprite.Position = actualPosition;
            sprite.Scale = Scale;
            rt.Draw(sprite);

            // Draw text
            Text text = GameUtility.Wrap(Info.Value, Assets.LoadFont("arialbd.ttf"), (uint)Math.Floor(24.0f * Scale.X),
                                     Math.Floor(207.0f * Scale.X));

            text.Color = Info.Type == CardType.White ? Color.Black : Color.White;
            text.Position = actualPosition + new Vector2f(16.0f * Scale.X, 10.0f * Scale.Y);
            text.Round();
            rt.Draw(text);

            // Draw decorations
            if (Info.PickCount > 1)
            {
                Sprite pickMultiple = new Sprite(Assets.LoadTexture(Info.PickCount == 2 ? "PickTwo.png" : "PickThree.png"))
                {
                    Position =
                        actualPosition +
                        new Vector2f((241.0f - 56.0f - 10.0f - 4.0f) * Scale.X, (320.0f - 10.0f - 20.0f) * Scale.Y),
                    Scale = Scale
                };

                rt.Draw(pickMultiple);
            }
        }
Example #2
0
        public void parseTileLayer(Texture tilemap)
        {
            foreach (TiledSharp.TmxLayer l in test.Layers)
            {
                foreach (TiledSharp.TmxLayerTile t in l.Tiles)
                {
                    SFML.Graphics.Sprite bodySprite = null;

                    if (t.Gid != 0)
                    {
                        bodySprite          = new SFML.Graphics.Sprite(tilemap, new SFML.Graphics.IntRect((t.Gid % 27 - 1) * 37, t.Gid / 27 * 37, 32, 32));
                        bodySprite.Position = new SFML.System.Vector2f(t.X * 32, t.Y * 32);
                        Sprite nightTexture = bodySprite;
                        nightTexture.Color = new Color(0, 0, 0, 80);
                        nightTexture.Color = new Color(128, 128, 128, 200);
                        TileSpriteList.Add(bodySprite);
                        TileSpriteList.Add(nightTexture);
                    }
                    if (l.Name == "walls")
                    {
                        if (t.Gid != 0)
                        {
                            Map.AddTile(t.X, t.Y, true);
                        }
                        else
                        {
                            Map.AddTile(t.X, t.Y, false);
                        }
                    }
                }
            }
        }
Example #3
0
        public Deathmatch()
            : base()
        {
            Projectiles = new List<Projectile>();
            BackgroundImages = new List<Sprite>();
            BackgroundImagesFar = new List<Sprite>();
            BackgroundTracks = new List<Sprite>();
            BackgroundGameObjects = new List<GameObject>();
            Players = new List<Actor>();
            Mailman = new ClientMailman(this);

            shader = new RenderStates(new Shader(null, "Content/bgPrlx.frag"));
            Image mapImg = new Image("Content/mapCol.png");
            mapBytes = mapImg.Pixels;
            mapSprite = new Sprite(new Texture(mapImg));
            mapWidth = (int)mapImg.Size.X;
            mapHeight = (int)mapImg.Size.Y;

            player = new ClientPlayer(this);
            player.Pos = new Vector2f(46, 62);
            Players.Add(player);

            trainSoundExterior = new SoundInstance(Content.GetSound("trainSpeed2.wav"), 1f, 0, 15, true);
            trainSoundInterior = new SoundInstance(Content.GetSound("trainSpeed0.wav"), 1, 0, 15, true);
            trainSound = trainSoundExterior;

            MainGame.Camera.Center = player.Pos - new Vector2f(0, 90);
        }
Example #4
0
        public static Sprite GetSprite(string filename)
        {
            Sprite sprite = new Sprite(GetTexture(filename));
            sprite.Texture.Smooth = true;

            return sprite;
        }
Example #5
0
        public Client(RenderWindow window, ImageManager imageManager)
            : base(window, imageManager)
        {
            this.window = window;
            world = new RenderImage(800, 600);

            inputManager = new InputManager(this);

            ticker = new Ticker();

            window.ShowMouseCursor (false);
            window.SetFramerateLimit (60);

            NetPeerConfiguration netConfiguration = new NetPeerConfiguration("2dThing");
            client = new NetClient(netConfiguration);

            uMsgBuffer = new UserMessageBuffer();
            otherClients = new Dictionary<int, NetworkClient>();
            chat = new Chat(this);

            LoadRessources();

            blockTypeDisplay = new Cube(blockType, imageManager);
            blockTypeDisplay.Position = new Vector2f(window.Width - 2*Cube.WIDTH, window.Height - 2* Cube.HEIGHT);
            layerDisplay = new LayerDisplay(imageManager);
            layerDisplay.Position = blockTypeDisplay.Position - new Vector2f(0, 50);

            mouse = new Sprite (imageManager.GetImage("mouse"));
        }
        public void Draw()
        {
            SFML.Graphics.Sprite s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Button)[ID]);
            s.Position = new Vector2f(X, Y);
            _screen.Draw(s);

            Text t = new Text();
            t.Font = Program.Data.Font;
            t.CharacterSize = 14;

            CraftGUI g = (CraftGUI)Program.SM.States[1].GameGUI[10];
            Items i = Program.Data.MyItems[Logic.KnownRecipeForThisCharacter(Logic.CurrentParty.MainParty.MyParty[0], g.CurClass).Count];
            {
                if (SlotID + 3 * g.CurPage < i.ItemRequired.Count)
                {
                    s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Items)[Program.Data.MyItems[i.ItemRequired.ElementAt(SlotID + 3 * g.CurPage).Key].Sprite]);
                    s.Position = new Vector2f(X, Y);
                    _screen.Draw(s);

                    t.DisplayedString = Program.Data.MyItems[i.ItemRequired.ElementAt(SlotID + 3 * g.CurPage).Key].Name + ": " + i.ItemRequired.ElementAt(SlotID + 3 * g.CurPage).Value;
                    t.Position = new Vector2f(X + 38, Y + 8);
                    _screen.Draw(t);
                }
            }
        }
Example #7
0
 public Explosion(Vector2 position)
 {
     explosionTexture         = new Texture(@"Resources/explosion.png");
     explosionSprite          = new Sprite(explosionTexture, new IntRect(0, 0, spriteSize, spriteSize));
     explosionSprite.Origin   = new SFML.System.Vector2f(spriteSize / 2, spriteSize / 2);
     explosionSprite.Position = new SFML.System.Vector2f(ConvertUnits.ToDisplayUnits(position.X), ConvertUnits.ToDisplayUnits(position.Y));
 }
Example #8
0
        public bool Collision(Sprite sprite1, Sprite sprite2, uint alphaLimit)
        {
            FloatRect intersection;
            if (sprite1.GetGlobalBounds().Intersects(sprite2.GetGlobalBounds(), out intersection))
            {
                IntRect subRect1 = sprite1.TextureRect;
                IntRect subRest2 = sprite2.TextureRect;
                uint[] mask1 = Bitmasks[sprite1.Texture];
                uint[] mask2 = Bitmasks[sprite2.Texture];

                for (int i = (int)intersection.Left; i < intersection.Left + intersection.Width; i++)
                    for (int j = (int)intersection.Top; j < intersection.Top + intersection.Height; j++)
                    {
                        Vector2f vector1 = sprite1.InverseTransform.TransformPoint(i, j);
                        Vector2f vector2 = sprite2.InverseTransform.TransformPoint(i, j);

                        if (vector1.X > 0 && vector1.Y > 0 && vector2.X > 0 && vector2.Y > 0 &&
                           vector1.X < subRect1.Width && vector1.Y < subRect1.Height &&
                           vector2.X < subRest2.Width && vector2.Y < subRest2.Height)
                            if (GetPixel(mask1, sprite1.Texture, (uint)(vector1.X) + (uint)subRect1.Left, (uint)(vector1.Y) + (uint)subRect1.Top) > alphaLimit &&
                                GetPixel(mask2, sprite2.Texture, (uint)vector2.X + (uint)subRest2.Left, (uint)vector2.Y + (uint)subRest2.Top) > alphaLimit)
                                return true;
                    }

            }

            return false;
        }
 public void DrawTop(RenderWindow rw)
 {
     SFML.Graphics.Sprite s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Resource)[Program.Data.GetResourceList()[ID].Sprite]);
     s.Position = new Vector2f((X + Logic.CurrentParty.MainParty.MyParty[0].CurMap.MinX) * Program.Data.TileSizeX, (Y + Logic.CurrentParty.MainParty.MyParty[0].CurMap.MinY - 1) * Program.Data.TileSizeX);
     s.TextureRect = new IntRect(0, 0, (int)(s.Texture.Size.X), (int)(s.Texture.Size.Y - Program.Data.GetResourceList()[ID].SizeY * 16));
     rw.Draw(s);
 }
        //totalbars - maxShown = max topBar
        internal BarracksScrollList(Barracks b, Vector2f start)
        {
            //int x = (overallRect.Height - 2 * 25) / champBarRect.Height;
            //scroll = overallRect.Height - (x * champBarRect.Height);
            maxShown = (int)((overallRect.Height - 2 * scroll) / champBarRect.Height - 1);
            totalBars = b.getTotalChamps();
            mBarracks = b;
            this.start = start;

            disabledButtons = new List<int>();
            champsItemIcons = new List<IconToolTip>();
            for(int i=0;i<totalBars;i++){
                ItemID item = mBarracks.getChamps()[i].item;
                Sprite itemS = new Sprite(Item.getItemTexture(item), new IntRect(0, 0, Item.ICON_WIDTH, Item.ICON_WIDTH));
                if (item == ItemID.none) {
                    IconToolTip itt = new IconToolTip(itemS, "none", "none");
                    champsItemIcons.Add(itt);
                } else {
                    Item ite = new Item(item);
                    champsItemIcons.Add(new IconToolTip(itemS, ite.name, ite.description));
                }
            }

            champBarSprite = new Sprite(champBarTexture);
            unitIconSprite = new Sprite();

            topBarDebugText = new Text(topBar + " ",GameBox.corbalFont,30U);
            topBarDebugText.Color = Color.Yellow;
            playerClassText = new Text("playerclass", GameBox.corbalFont, 15U);
            playerItemText = new Text("playeritem", GameBox.corbalFont, 15U);
        }
        public void Draw()
        {
            SFML.Graphics.Sprite s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Button)[ID]);
            s.Position = new Vector2f(X, Y);
            _screen.Draw(s);

            PickWorldGUI g = (PickWorldGUI)Program.State[0].GameGUI[5];

            Text t = new Text();
            t.CharacterSize = 11;
            t.Color = Color.White;
            t.Font = Program.Data.Font;

            for (int i = 0; i < 11; i++)
            {
                if (i + g.SaveDown < Program.Data.MyWorldData.Count)
                {
                    t.DisplayedString = Program.Data.MyWorldData[i + g.SaveDown].Name;
                    t.Position = new Vector2f(X + 4, Y + 2 + 16 * i);
                    _screen.Draw(t);
                }
            }

            if (Program.Data.MyWorldData.Count > 0)
            {
                s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Button)[SelectID]);
                s.Position = new Vector2f(X, Y + 16 * g.SelectedWorld);
                _screen.Draw(s);
            }
        }
        public BlueprintButton(string c1, string c1N, string c2, string c2N, string res, string resname,
                               IResourceManager resourceManager)
        {
            _resourceManager = resourceManager;

            Compo1 = c1;
            Compo1Name = c1N;

            Compo2 = c2;
            Compo2Name = c2N;

            Result = res;
            ResultName = resname;

            _icon = _resourceManager.GetSprite("blueprint");

            Label = new TextSprite("blueprinttext", "", _resourceManager.GetFont("CALIBRI"))
                        {
                            Color = new SFML.Graphics.Color(248, 248, 255),
                            ShadowColor = new SFML.Graphics.Color(105, 105, 105),
                            ShadowOffset = new Vector2f(1, 1),
                            Shadowed = true
                        };

            Update(0);
        }
 public void DrawBot(RenderWindow rw)
 {
     SFML.Graphics.Sprite s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Resource)[Program.Data.GetResourceList()[ID].Sprite]);
     s.Position = new Vector2f((X + Program.MyMap.MinX) * Program.Data.TileSizeX, (Y + Program.MyMap.MinY) * Program.Data.TileSizeY);
     s.TextureRect = new IntRect(0, (int)(s.Texture.Size.Y - Program.Data.GetResourceList()[ID].SizeY * 16), (int)(s.Texture.Size.X), Program.Data.GetResourceList()[ID].SizeY * 16);
     rw.Draw(s);
 }
Example #14
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;
        }
Example #15
0
 public static Sprite LoadSprite(string fileName, Vector2f scale)
 {
     Image image = new Image(fileName);
     Texture texture = new Texture(image);
     Sprite sprite = new Sprite(texture) { Scale = scale };
     return sprite;
 }
        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);
        }
Example #17
0
        public Player(string name, bool sandbox, Image image, uint width = 0, uint height = 0)
        {
            this.name = name;
            this.alive = true;
            this.health = 100;
            this.sandbox = sandbox;
            this.image = image;

            this.sprite = new Sprite(image);

            this.sprite.Position = new Vector2(10, 10);

            if (width > 0 && height > 0)
            {
                this.sprite.Width = width;
                this.sprite.Height = height;
            }
            else
            {
                this.sprite.Width = 32;
                this.sprite.Height = 64;
            }

            this.inventoryList = new List<Item>();
        }
Example #18
0
        public Hud(GameBase state)
        {
            _state = state;

            _selected = new Sprite(Assets.LoadTexture("wep_selected.png")).Center();

            _statusBack = new RectangleShape(new Vector2f(BarWidth + Padding * 2, BarHeight * 2 + Padding * 3));
            _statusBack.Position = new Vector2f(Padding, Padding);
            _statusBack.FillColor = new Color(0, 0, 0);
            _statusBack.OutlineThickness = 2;
            _statusBack.OutlineColor = new Color(38, 38, 38);

            _health = new RectangleShape(new Vector2f(BarWidth, BarHeight));
            _health.Position = _statusBack.Position + new Vector2f(Padding, Padding);
            _health.FillColor = new Color(0, 120, 0);

            _healthText = new Text("", Program.Font, (int)(BarHeight - Padding));
            _healthText.Position = _health.Position + new Vector2f(BarWidth / 2, BarHeight / 2);
            _healthText.Color = new Color(225, 225, 225);

            _energy = new RectangleShape(new Vector2f(BarWidth, BarHeight));
            _energy.Position = _health.Position + new Vector2f(0, BarHeight + Padding);
            _energy.FillColor = new Color(30, 30, 180);

            _energyText = new Text("", Program.Font, (int)(BarHeight - Padding));
            _energyText.Position = _energy.Position + new Vector2f(BarWidth / 2, BarHeight / 2);
            _energyText.Color = new Color(225, 225, 225);
        }
Example #19
0
        public GameStateMultiplayer()
        {
            _background = new Sprite(ResourceManager.Instance["menu/background"] as Texture);

            Game.Instance.AudioManager.PauseAllBackground();
            Game.Instance.AudioManager.PlaySound("menu/background_music", true);

            PrepareUi();

            Game.Instance.Window.MouseButtonReleased += Window_MouseButtonReleased;

            try
            {
                var id = GameClient.Instance.InitConnection();
                Game.Instance.Player.Id = id;
            }
            catch
            {
            }

            if (GameClient.Connected)
            {
                RefeshGameClick(null, null);
            }
        }
Example #20
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();
            }
        }
        public void Draw()
        {
            Text t = new Text();
            t.Font = Program.Data.Font;
            t.CharacterSize = 14;

            SFML.Graphics.Sprite s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Button)[ID]);
            s.Position = new Vector2f(X, Y);
            _screen.Draw(s);

            BuildGUI g = (BuildGUI)Program.State[1].GameGUI[8];
            if (g.CurPick + 3 * g.PickPage < Logic.KnownBluePrintForThisCharacter(Program.Data.MyPlayerData[Program.CurrentSaveData].MainParty.MyParty[0], g.CurClass).Count)
            {
                if (SlotID + 3 * g.CurPage < Program.Data.GetBuildableList()[Logic.KnownBluePrintForThisCharacter(Program.Data.MyPlayerData[Program.CurrentSaveData].MainParty.MyParty[0], g.CurClass)[g.CurPick + 3 * g.PickPage]].RequiredItems.Count)
                {
                    s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Items)[Program.Data.GetBuildableList()[Logic.KnownBluePrintForThisCharacter(Program.Data.MyPlayerData[Program.CurrentSaveData].MainParty.MyParty[0], g.CurClass)[g.CurPick + 3 * g.PickPage]].RequiredItems.ElementAt(SlotID + 3 * g.CurPage).Key.ID]);
                    s.Position = new Vector2f(X, Y);
                    _screen.Draw(s);

                    t.DisplayedString = Program.Data.MyItems[Program.Data.GetBuildableList()[Logic.KnownBluePrintForThisCharacter(Program.Data.MyPlayerData[Program.CurrentSaveData].MainParty.MyParty[0], g.CurClass)[g.CurPick + 3 * g.PickPage]].RequiredItems.ElementAt(SlotID + 3 * g.CurPage).Key.ID].Name + ": " + Program.Data.GetBuildableList()[Logic.KnownBluePrintForThisCharacter(Program.Data.MyPlayerData[Program.CurrentSaveData].MainParty.MyParty[0], g.CurClass)[g.CurPick + 3 * g.PickPage]].RequiredItems.ElementAt(SlotID + 3 * g.CurPage).Value;
                    t.Position = new Vector2f(X + 40, Y + 7);
                    _screen.Draw(t);
                }
            }
        }
Example #22
0
        public PauseState(StateStack stack, Context context)
            : base(stack, context)
        {
            RenderWindow window = mContext.window;

            mBackgroundSprite = new Sprite();
            mPausedText = new Text();
            mInstructionText = new Text();

            mPausedText.Font = mContext.fonts.get(FontID.Main);
            mPausedText.DisplayedString = "Game Paused";
            mPausedText.CharacterSize = 70;
            mPausedText.centerOrigin();
            mPausedText.Position = new Vector2f(0, 0);

            mInstructionText.Font = mContext.fonts.get(FontID.Main);
            mInstructionText.DisplayedString = "(Press Backspace to return to main menu)";
            mInstructionText.centerOrigin();
            mInstructionText.Position = new Vector2f(0, 0);

            backgroundShape = new RectangleShape();
            backgroundShape.FillColor = new Color(0, 0, 0, 150);
            backgroundShape.Position = window.GetView().Center;
            backgroundShape.centerOrigin();
            backgroundShape.Size = window.GetView().Size;
        }
Example #23
0
        /// <summary>
        /// Prepares the <see cref="SFML.Graphics.Sprite"/> used to draw to a <see cref="RenderTarget"/>.
        /// </summary>
        /// <param name="sprite">The <see cref="SFML.Graphics.Sprite"/> to prepare.</param>
        /// <param name="target">The <see cref="RenderTarget"/> begin drawn to.</param>
        protected override void PrepareDrawToTargetSprite(SFML.Graphics.Sprite sprite, RenderTarget target)
        {
            base.PrepareDrawToTargetSprite(sprite, target);

            // Always use alpha blending
            sprite.BlendMode = BlendMode.Multiply;
        }
Example #24
0
        public MainMenu(RenderWindow window, ImageManager imageManager, Client client, Server server)
            : base(window, imageManager)
        {
            imageManager = new ImageManager();
            p = new Player(null, imageManager);
            mouse = new Sprite(imageManager.GetImage("mouse"));
            pImage = new RenderImage(window.Width, window.Height);
            pImage.DefaultView.Zoom(0.08F);
            pImage.DefaultView.Center = p.Center + new Vector2f(0, -30);
            pImage.SetView(pImage.DefaultView);

            this.window = window;
            this.client = client;
            this.server = server;
            items = new MenuItem[nbrItem];
            items[0] = new MenuItem("Local Game", new Vector2f(0, 100), StartLocal);
            items[1] = new MenuItem("Connect", new Vector2f(0, 130), Connect);
            items[2] = new MenuItem("Options", new Vector2f(0, 160), Option);
            items[3] = new MenuItem("Load map", new Vector2f(0, 190), LoadMap);
            items[4] = new MenuItem("Save map", new Vector2f(0, 220), SaveMap);
            items[5] = new MenuItem("Exit", new Vector2f(0, 280), Exit);

            foreach (MenuItem i in items)
                i.CenterX((int)window.Width);
        }
Example #25
0
        /// <summary>
        /// Prepares the <see cref="SFML.Graphics.Sprite"/> used to draw to a <see cref="RenderTarget"/>.
        /// </summary>
        /// <param name="sprite">The <see cref="SFML.Graphics.Sprite"/> to prepare.</param>
        /// <param name="target">The <see cref="RenderTarget"/> begin drawn to.</param>
        protected override void PrepareDrawToTargetSprite(SFML.Graphics.Sprite sprite, RenderTarget target)
        {
            base.PrepareDrawToTargetSprite(sprite, target);

            // Always use BlendMode.None
            sprite.BlendMode = BlendMode.None;
        }
        public void Draw()
        {
            SFML.Graphics.Sprite s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Button)[ID]);
            s.Position = new Vector2f(X, Y);
            _screen.Draw(s);

            Text t = new Text();
            t.Font = Program.Data.Font;
            t.CharacterSize = 11;
            t.Color = Color.Yellow;

            KnowledgeGUI g = (KnowledgeGUI)Program.SM.States[1].GameGUI[11];
            switch (g.CurView)
            {
                case 0:
                    if (g.KnowledgeDown + SlotID < Program.Data.MyKnowledge.Count)
                    {
                        s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Knowledge)[g.KnowledgeDown + SlotID]);
                        s.Position = new Vector2f(X + 1, Y + 1);
                        _screen.Draw(s);

                        t.DisplayedString = Program.Data.MyKnowledge[g.KnowledgeDown + SlotID].Name;
                        t.Position = new Vector2f(X + 30, Y + 5);
                        _screen.Draw(t);

                        if (Logic.CurrentParty.MainParty.MyParty[0].KnowledgeKnown.Contains(g.KnowledgeDown + SlotID))
                            s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Button)[62]);
                        else
                            s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Button)[59]);
                        s.Position = new Vector2f(X + 152, Y + 12);
                        _screen.Draw(s);
                    }
                    break;
            }
        }
Example #27
0
        internal static void drawBeam(RenderWindow window, Vector2f v1, Vector2f v2, Sprite sprite)
        {
            Vector2f currentLoc = v1;
            int spacingX = 2, spacingY = 2;

            //double xNeeded = d.getMid().X - start.X;
            //double yNeeded = d.getMid().Y - start.Y;
            if (Math.Sign(v1.X - v2.X) > 0) {
                spacingX *= -1;
            }
            if (Math.Sign(v1.Y - v2.Y) > 0) {
                spacingY *= -1;
            }
            bool xGood, yGood;
            do{
                double d1 = Math.Abs(currentLoc.X - v2.X);
                if (!(xGood = (d1 <= Math.Abs(spacingX))))
            //double amtMovedX = ((gameTime - startMoveTime) / (travelTime * 1000)) * xNeeded;
                    currentLoc.X += spacingX;// (float)amtMovedX;
                double d2 = Math.Abs(currentLoc.Y - v2.Y);
                if (!(yGood = (d2 <= Math.Abs(spacingY))))
            //double amtMovedY = ((gameTime - startMoveTime) / (travelTime * 1000)) * yNeeded;
                    currentLoc.Y += spacingY;//(float)amtMovedY;
                sprite.Position = currentLoc;
                window.Draw(sprite);
            } while (!xGood || !yGood);
        }
 public override void Dispose()
 {
     text = null;
     icon = null;
     base.Dispose();
     GC.SuppressFinalize(this);
 }
Example #29
0
        public void InitMapEditedMenu()
        {
            _lines3.Clear();
            _selected = 0;

            // Get all maps
            _maps = Directory.GetFiles(@"..\..\..\..\Maps\Edited\", "*.totmap");

            // Init menu
            //Background
            // Set background
            _background = new SFML.Graphics.Sprite(new Texture(@"..\..\..\..\Assets\Backgrounds\time-travel-background.png"));
            if (_background == null)
            {
                throw new Exception("Sprite null!");
            }

            _window.Draw(_background);

            //Lines
            for (int i = 0; i < _maps.Length; i++)
            {
                _lines3.Add(new Text(StringBetweenString(_maps[i], @"..\..\..\..\Maps\Edited\", ".totmap"), _font, _charSize));
            }

            _lines3.Add(new Text("Back", _font, _charSize));

            for (int i = 0; i < _lines3.Count; i++)
            {
                _lines3[i].Position = new SFML.System.Vector2f(_window.Size.X / 2 - (_lines3[i].GetGlobalBounds().Width) / 2, (_window.Size.Y / 6) * (i + 1));
            }

            _window.Display();
        }
Example #30
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Sprite" /> class
 /// </summary>
 public Sprite()
 {
     TexturePath = "";
     transform   = new Transform();
     sprite      = new SFML.Graphics.Sprite();
     RenderManager.Attach(this);
 }
Example #31
0
        public void StartMainMenu()
        {
            //Background
            // Set background
            _background = new SFML.Graphics.Sprite(new Texture(@"..\..\..\..\Assets\Backgrounds\time-travel-background.png"));
            if (_background == null)
            {
                throw new Exception("Sprite null!");
            }

            //_background.Scale = new SFML.System.Vector2f(_window.Size.X / 1920, _window.Size.Y / 1080);
            _window.Draw(_background);

            //Lines
            _lines[0] = new Text("1 Player", _font, _charSize);
            _lines[1] = new Text("2 Player", _font, _charSize);
            _lines[2] = new Text("Map Editor", _font, _charSize);
            _lines[3] = new Text("Settings", _font, _charSize);
            _lines[4] = new Text("Quit", _font, _charSize);

            for (int i = 0; i < MAX_LINES; i++)
            {
                _lines[i].Position = new SFML.System.Vector2f(_window.Size.X / 2 - (_lines[i].GetGlobalBounds().Width) / 2, (_window.Size.Y / 7) * (i + 1));
            }
        }
Example #32
0
 public Checkbox(IResourceManager resourceManager)
 {
     _resourceManager = resourceManager;
     checkbox = _resourceManager.GetSprite("checkbox0");
     checkboxCheck = _resourceManager.GetSprite("checkbox1");
     Update(0);
 }
Example #33
0
        public Edge()
            : base("edge post-effect")
        {
            // Create the off-screen surface
            mySurface = new RenderTexture(800, 600);
            mySurface.Smooth = true;

            // Load the textures
            myBackgroundTexture = new Texture("resources/sfml.png");
            myBackgroundTexture.Smooth = true;
            myEntityTexture = new Texture("resources/devices.png");
            myEntityTexture.Smooth = true;

            // Initialize the background sprite
            myBackgroundSprite = new Sprite(myBackgroundTexture);
            myBackgroundSprite.Position = new Vector2f(135, 100);

            // Load the moving entities
            myEntities = new Sprite[6];
            for (int i = 0; i < myEntities.Length; ++i)
            {
                myEntities[i] = new Sprite(myEntityTexture, new IntRect(96 * i, 0, 96, 96));
            }

            // Load the shader
            myShader = new Shader(null, "resources/edge.frag");
            myShader.SetParameter("texture", Shader.CurrentTexture);
        }
        public void GaussianBlurRadius11_ShouldBlur()
        {
            preblur = new RenderImage("testGaussianBlur", 1280, 768);
            _gaussianBlur = new GaussianBlur(_resourceManager);

            _gaussianBlur.SetRadius(11);
            _gaussianBlur.SetAmount(2);
            _gaussianBlur.SetSize(new Vector2f(preblur.Width, preblur.Height));

            while (CluwneLib.IsRunning)
            {
                var lastFrameTime = clock.ElapsedTime.AsSeconds();
                clock.Restart();
                _frameEvent = new FrameEventArgs(lastFrameTime);
                CluwneLib.ClearCurrentRendertarget(Color.Black);
                CluwneLib.Screen.DispatchEvents();

                preblur.BeginDrawing(); // set temp as CRT (Current Render Target)
                //preblur.Clear();       //Clear
                sprite = _resourceManager.GetSprite("flashlight_mask");
                sprite.Position = new Vector2f();
                sprite.Draw();
                preblur.EndDrawing();  // set previous rendertarget as CRT (screen in this case)

                //_gaussianBlur.PerformGaussianBlur(preblur); // blur rendertarget

                preblur.Blit(0,0, preblur.Width, preblur.Height,Color.White, BlitterSizeMode.Crop ); // draw blurred nosprite logo

                CluwneLib.Screen.Display();

            }
        }
Example #35
0
        public MainTitleScreen(RenderWindow window)
            : base(window)
        {
            Type = ScreenType.MainTitleScreen;

            base.Init();
               // Gui.AddGameWidget(imb);

            initMenu();

            StraightLineVariableData slvd = new StraightLineVariableData(200F, 100 * 4);
               // slvd.AddKeyData(.25F, 100F);
            slvd.AddKeyData(.5F, 300F);
               // slvd.AddKeyData(.75F, 100F);
            slvd.ComputeData();

            img = new Image(800, 600, new Color(0, 0, 0, 0));
            for (int i = 0; i < slvd.GetCount(); ++i)
            {
               // Log.Cl(slvd.GetData(i));
                img.SetPixel((uint)(100 + i / 4), (uint)slvd.GetData(i), Color.Red);
               // img.SetPixel((uint)(100 + i / 4), (uint)slvd.GetData(i) + 4, Color.Blue);
            }

            tex = new SFML.Graphics.Texture(img);
            spre = new Sprite(tex);

            imb.AddMessage("hoy hoy !");
            imb.OnStopping += new MessageBox.EventHandler(imb_OnStopping);
        }
 public ParticleSystem(Sprite particleSprite, Vector2f position)
 {
     MaximumParticleCount = 200;
     //TODO start with sane defaults
     Acceleration = new Vector2f();
     AccelerationVariance = 0f;
     ColorRange = new SS14.Shared.Utility.Range<Vector4f>(Vector4f.UnitX * 255, Vector4f.Zero);
     ColorVariance = 0f;
     EmissionOffset = new Vector2f();
     EmissionRadiusRange = new SS14.Shared.Utility.Range<float>(0f, 0f);
     Emit = false;
     EmitRate = 1;
     EmitterPosition = position;
     Lifetime = 1.0f;
     LifetimeVariance = 0f;
     ParticleSprite = particleSprite;
     RadialAcceleration = 0f;
     RadialAccelerationVariance = 0f;
     RadialVelocity = 0f;
     RadialVelocityVariance = 0f;
     SizeRange = new SS14.Shared.Utility.Range<float>(1, 0);
     SizeVariance = 0.1f;
     SpinVelocity = new SS14.Shared.Utility.Range<float>(0f, 0f);
     SpinVelocityVariance = 0f;
     TangentialAcceleration = 0;
     TangentialAccelerationVariance = 0;
     TangentialVelocity = 0;
     TangentialVelocityVariance = 0;
     Velocity = new Vector2f();
     VelocityVariance = 0;
 }
Example #37
0
        /// <summary>
        /// Creates a Sprite from RenderImage Texture and draws it to the screen
        /// </summary>
        /// <param name="Position"> Position of Texture </param>
        /// <param name="Size"> Size of the Texture </param>
        /// <param name="color"> Global color of object </param>
        public void Blit(SFML.System.Vector2f position, SFML.System.Vector2f Size, SFML.Graphics.Color color)
        {
            isStillDrawing();
            blitsprite          = new SFML.Graphics.Sprite(Texture);
            blitsprite.Position = position;
            blitsprite.Color    = color;
            var bounds = blitsprite.GetLocalBounds();

            if (Mode == BlitterSizeMode.Scale)
            {
                SFML.System.Vector2f scale = new SFML.System.Vector2f((Size.X / bounds.Width), (Size.Y / bounds.Height));
                blitsprite.Scale = scale;
            }
            else if (Mode == BlitterSizeMode.Crop)
            {
                IntRect crop = new IntRect((int)position.X, (int)position.Y, (int)Size.X, (int)Size.Y);
                blitsprite.TextureRect = crop;
            }


            if (CluwneLib.CurrentRenderTarget == this)
            {
                return;
            }

            blitsprite.Draw();
        }
Example #38
0
        private void ShowSplashScreen()
        {
            // Do nothing when we're on DEBUG builds.
            // The splash is just annoying.
#if !DEBUG
            const uint SIZE_X = 600;
            const uint SIZE_Y = 300;
            // Size of the NT logo in the bottom left.
            const float  NT_SIZE_X = SIZE_X / 10f;
            const float  NT_SIZE_Y = SIZE_Y / 10f;
            CluwneWindow window    = CluwneLib.ShowSplashScreen(new VideoMode(SIZE_X, SIZE_Y));

            var logoTexture = new Texture(_resourceManager.ContentFileRead(@"Textures/Logo/logo.png"));
            var logo        = new SFML.Graphics.Sprite(logoTexture);
            var logoSize    = logoTexture.Size;
            logo.Position = new Vector2f(SIZE_X / 2 - logoSize.X / 2, SIZE_Y / 2 - logoSize.Y / 2);

            var backgroundTexture = new Texture(_resourceManager.ContentFileRead(@"Textures/Logo/background.png"));
            var background        = new SFML.Graphics.Sprite(backgroundTexture);
            var backgroundSize    = backgroundTexture.Size;
            background.Scale = new Vector2f((float)SIZE_X / backgroundSize.X, (float)SIZE_Y / backgroundSize.Y);

            var nanotrasenTexture = new Texture(_resourceManager.ContentFileRead(@"Textures/Logo/nanotrasen.png"));
            var nanotrasen        = new SFML.Graphics.Sprite(nanotrasenTexture);
            var nanotrasenSize    = nanotrasenTexture.Size;
            nanotrasen.Scale    = new Vector2f(NT_SIZE_X / nanotrasenSize.X, NT_SIZE_Y / nanotrasenSize.Y);
            nanotrasen.Position = new Vector2f(SIZE_X - NT_SIZE_X - 5, SIZE_Y - NT_SIZE_Y - 5);
            nanotrasen.Color    = new Color(255, 255, 255, 64);

            window.Draw(background);
            window.Draw(logo);
            window.Draw(nanotrasen);
            window.Display();
#endif
        }
        public MainMenuScreen(Vector2u gameResolution, Vector2u windowResolution)
        {
            this.GameResolution = gameResolution;
            this.WindowResolution = windowResolution;
            this.IsDrawn = true;
            this.IsUpdated = true;
            this.ParentScreen = null;

            //mPlayer = new MusicPlayer();
            //mPlayer.add("bg", new Music(@"Content/music/never_short.ogg"));
            //mPlayer.currentMusic.Volume = 50;
            //mPlayer.currentMusic.Loop = true;
            //mPlayer.play();

            contentManager = new ContentManager(Game1.defaultWorldParameters);
            IO.loadLevel(contentManager, @"Content/levels/menuLevel.xml");

            backGround = new Sprite(contentManager.Media.loadTexture("Content/images/bg.jpg", true));
            backGround.Scale = new Vector2f(gameResolution.X / (float)backGround.Texture.Size.X, gameResolution.Y / (float)backGround.Texture.Size.Y);

            lightLayer = new LightLayer(this.GameResolution, this.WindowResolution);
            lightLayer.add(new Light(new Vector2f(700, 350), new Color(255, 255, 200), .55f));
            lightLayer.add(new Light(new Vector2f(1920 - 700, 350), new Color(255, 255, 200), .55f));

            contentManager.foreceBlocks();
            lightLayer.setPolygons(contentManager.getLightPolygons());

            mainMenu = new MenuScreen(this, this.contentManager, null, new Vector2i(0, 0), true, true, false);
            mainMenu.Title.Color = Color.Black;
            mainMenu.ButtonColor = Color.Black;
            mainMenu.addButtons(new string[] { "Play",  "Level Editor", "Options",  "Help", "Credits", "Quit"});
            mainMenu.MouseClick += mainMenu_ButtonClick;
            mainMenu.MouseEnter += mainMenu_MouseEnter;
            mainMenu.MouseLeave += mainMenu_MouseLeave;
        }
Example #40
0
 public Shot(SFML.Window.Vector2f pos, string sprite, int dmg, int fireRate)
 {
     _damage          = dmg;
     _fireRate        = fireRate;
     _sprite          = new SFML.Graphics.Sprite();
     _sprite.Texture  = new SFML.Graphics.Texture(sprite, new SFML.Graphics.IntRect(10, 10, 5, 5));
     _sprite.Position = new SFML.Window.Vector2f(pos.X + 15, pos.Y + 32);
 }
Example #41
0
        public LightArea(ShadowmapSize shadowmapSize, SFML.Graphics.Sprite mask)
        {
            var baseSize = 2 << (int)shadowmapSize;

            LightAreaSize = new Vector2(baseSize, baseSize);
            RenderTarget  = new RenderImage("LightArea" + shadowmapSize, (uint)baseSize, (uint)baseSize);
            Mask          = mask;
        }
Example #42
0
        public void DieMenu2()
        {
            View view1 = new View(new Vector2f(Settings.XResolution / 2, Settings.YResolution / 2), new Vector2f(Settings.XResolution, Settings.YResolution));

            view1.Viewport = new FloatRect(0f, 0f, 1f, 1f);
            view1.Size     = new Vector2f(Settings.XResolution, Settings.YResolution);
            _window.SetView(view1);

            SFML.Graphics.Sprite background = new SFML.Graphics.Sprite(new Texture(@"..\..\..\..\Assets\Backgrounds\time-travel-background.png"));
            if (background == null)
            {
                throw new Exception("Sprite null!");
            }

            background.Scale = new SFML.System.Vector2f(_window.Size.X / 550, _window.Size.Y / 550);
            _window.Draw(background);

            List <Text> lines = new List <Text>();

            //Lines
            lines.Add(new Text("PLAYER 2 DIEEEEED", _globalFont, 64));
            lines.Add(new Text("Killed by : " + _game2.GetPlayer2.KilledBy2, _globalFont, 48));
            lines.Add(new Text("in : " + _game.TimeElapsed / 1000 + " seconds !", _globalFont, 32));
            lines.Add(new Text("Press ENTER/A to QUIT", _globalFont, 32));

            lines[0].FillColor = Color.Green;
            lines[1].FillColor = Color.Yellow;
            lines[2].FillColor = Color.Red;
            lines[3].FillColor = Color.Black;

            for (int i = 0; i < lines.Count; i++)
            {
                lines[i].Position = new SFML.System.Vector2f(_window.Size.X / 2 - (lines[i].GetGlobalBounds().Width) / 2, (_window.Size.Y / 6) * i);
                _window.Draw(lines[i]);
            }

            _window.Display();

            bool quit = false;

            while (!quit)
            {
                Joystick.Update();
                if (Keyboard.IsKeyPressed(Keyboard.Key.Enter) || (Joystick.IsConnected(0) && Joystick.IsButtonPressed(0, 0)))
                {
                    quit = true;
                }
                System.Threading.Thread.Sleep(1);
            }

            // QUAND QUITTE LE MENU
            _menu     = new Menu(_window);
            _settings = new Settings(this, _window);
            _gui      = new GUI(this, _window);
            _timer    = new Stopwatch();
            _timer.Start();
            _game = null;
        }
Example #43
0
        public static void Init()
        {
            Layers = new List<Layer>();
            LayersDict = new Dictionary<string, Layer>();

            Buffer = new RenderTexture(Core.ScrW, Core.ScrH);
            Spr = new SFML.Graphics.Sprite(Buffer.Texture);
            ClearRect = new RectangleShape(new SFML.System.Vector2f(Core.ScrW, Core.ScrH)) { FillColor = Color.Black };
        }
Example #44
0
        /// <summary>
        /// Draws a raw <see cref="SFML.Graphics.Sprite"/>. Recommended to avoid using when possible, but when needed,
        /// can provide a slight performance boost when drawing a large number of sprites with identical state.
        /// </summary>
        /// <param name="sprite">The <see cref="SFML.Graphics.Sprite"/> to draw.</param>
        /// <param name="shader">The <see cref="Shader"/> to use while drawing.</param>
        public virtual void Draw(SFML.Graphics.Sprite sprite, Shader shader = null)
        {
            if (sprite == null || !IsAssetValid(sprite.Image))
            {
                return;
            }

            _rt.Draw(sprite, shader);
        }
Example #45
0
        /// <summary>
        /// Draws a raw <see cref="SFML.Graphics.Sprite"/>. Recommended to avoid using when possible, but when needed,
        /// can provide a slight performance boost when drawing a large number of sprites with identical state.
        /// </summary>
        /// <param name="sprite">The <see cref="SFML.Graphics.Sprite"/> to draw.</param>
        /// <param name="shader">The <see cref="Shader"/> to use while drawing.</param>
        public virtual void Draw(SFML.Graphics.Sprite sprite, Shader shader = null)
        {
            if (sprite == null || !IsAssetValid(sprite.Texture))
            {
                return;
            }

            _renderState.Shader = shader;
            _rt.Draw(sprite, _renderState);
        }
Example #46
0
        /// <summary>
        /// Handles the actual drawing of the buffer to a <see cref="RenderTarget"/>.
        /// </summary>
        /// <param name="buffer">The <see cref="Image"/> of the buffer that is to be drawn to the <paramref name="target"/>.</param>
        /// <param name="sprite">The <see cref="SFML.Graphics.Sprite"/> set up to draw the <paramref name="buffer"/>.</param>
        /// <param name="target">The <see cref="RenderTarget"/> to draw the <paramref name="buffer"/> to.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> that was used during the creation of the buffer.</param>
        protected override void HandleDrawBufferToTarget(Image buffer, SFML.Graphics.Sprite sprite, RenderTarget target,
                                                         ICamera2D camera)
        {
            // Set up the shader
            DrawToTargetShader.SetTexture("ColorMap", _colorMap);
            DrawToTargetShader.SetTexture("NoiseMap", buffer);

            // Draw to the target
            target.Draw(sprite, DrawToTargetShader);
        }
Example #47
0
 public Sprite(int zorder = 0)
     : base(zorder)
 {
     Sheets        = new List <SpriteSheet>();
     Spr           = new SFML.Graphics.Sprite();
     SrcRect       = new IntRect();
     FCurrentSheet = 0;
     AnimSpeed     = 1;
     Animated      = false;
 }
Example #48
0
        public Background(string texture, Vector2D position, Vector2D push)
        {
            this.push     = push;
            this.pushRate = 0.15f;

            this.position = position;

            this.texture = GeneralTextureManager.GetTexture(texture);
            this.sprite  = new Sprite(this.texture);
        }
Example #49
0
        /// <summary>
        /// Handles the actual drawing of the buffer to a <see cref="RenderTarget"/>.
        /// </summary>
        /// <param name="buffer">The <see cref="Texture"/> of the buffer that is to be drawn to the <paramref name="target"/>.</param>
        /// <param name="sprite">The <see cref="SFML.Graphics.Sprite"/> set up to draw the <paramref name="buffer"/>.</param>
        /// <param name="target">The <see cref="RenderTarget"/> to draw the <paramref name="buffer"/> to.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> that was used during the creation of the buffer.</param>
        protected override void HandleDrawBufferToTarget(Texture buffer, SFML.Graphics.Sprite sprite, RenderTarget target, ICamera2D camera, RenderStates renderStates)
        {
            renderStates.BlendMode = BlendMode.None;

            // Set up the shader
            DrawToTargetShader.SetParameter("ColorMap", _colorMap);
            DrawToTargetShader.SetParameter("NoiseMap", buffer);

            base.HandleDrawBufferToTarget(buffer, sprite, target, camera, renderStates);
        }
Example #50
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Sprite" /> class
        /// </summary>
        /// <param name="texturePath">The texture path</param>
        public Sprite(string texturePath)
        {
            TexturePath = texturePath;

            transform = new Transform();

            sprite = new SFML.Graphics.Sprite(new Texture(texturePath));
            Size   = new Vector2(sprite.TextureRect.Width, sprite.TextureRect.Height);
            Console.WriteLine(@$ "witdh ={Size.X} | height={Size.Y}");
            RenderManager.Attach(this);
        }
Example #51
0
        public void Setup()
        {
            base.InitializeCluwneLib(1280, 720, false, 60);

            resources       = base.GetResourceCache;
            testRenderImage = new RenderImage("TestShaders", 1280, 720);
            testsprite      = resources.GetSprite("flashlight_mask");

            SS14UnitTest.InjectedMethod += LoadTestShader_ShouldDrawAllRed;

            base.StartCluwneLibLoop();
        }
Example #52
0
        public SfmlRenderer(RenderWindow window, CommonResource resource, bool highResolution)
        {
            sfmlWindow = window;
            palette    = resource.Palette;

            colors = InitColors(palette);

            sfmlWindowWidth  = (int)window.Size.X;
            sfmlWindowHeight = (int)window.Size.Y;

            if (highResolution)
            {
                screen            = new DrawScreen(resource.Wad, 640, 400);
                sfmlTextureWidth  = 512;
                sfmlTextureHeight = 1024;
            }
            else
            {
                screen            = new DrawScreen(resource.Wad, 320, 200);
                sfmlTextureWidth  = 256;
                sfmlTextureHeight = 512;
            }

            sfmlTextureData = new byte[4 * screen.Width * screen.Height];

            try
            {
                sfmlTexture = new SFML.Graphics.Texture((uint)sfmlTextureWidth, (uint)sfmlTextureHeight);
                sfmlSprite  = new SFML.Graphics.Sprite(sfmlTexture);
            }
            catch (Exception e)
            {
                Dispose();
                ExceptionDispatchInfo.Capture(e).Throw();
            }

            sfmlSprite.Position = new Vector2f(0, 0);
            sfmlSprite.Rotation = 90;
            var scaleX = (float)sfmlWindowWidth / screen.Width;
            var scaleY = (float)sfmlWindowHeight / screen.Height;

            sfmlSprite.Scale = new Vector2f(scaleY, -scaleX);

            sfmlStates = new RenderStates(BlendMode.None);

            menu            = new MenuRenderer(resource.Wad, screen);
            threeD          = new ThreeDRenderer(resource, screen);
            statusBar       = new StatusBarRenderer(resource.Wad, screen);
            intermission    = new IntermissionRenderer(resource.Wad, screen);
            openingSequence = new OpeningSequenceRenderer(resource.Wad, screen, this);
            autoMap         = new AutoMapRenderer(screen);
        }
Example #53
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OffscreenRenderBufferManagerBase"/> class.
        /// </summary>
        protected OffscreenRenderBufferManagerBase()
        {
            _sb = CreateSpriteBatch();

            _drawToTargetSprite = new SFML.Graphics.Sprite
            {
                Color    = Color.White,
                Rotation = 0,
                Scale    = Vector2.One,
                Origin   = Vector2.Zero,
                Position = Vector2.Zero
            };
        }
Example #54
0
        public Renderer()
        {
            blitState           = new SFML.Graphics.RenderStates();
            blitState.Transform = Transform.Identity;
            blitState.Shader    = null;
            blitState.BlendMode = BlendMode.Add;

            if (UsePlaceholderSprite)
            {
                placeholderSprite = new SFML.Graphics.Sprite();
            }
            rectSprite = new SFML.Graphics.Sprite();
        }
Example #55
0
        internal void LoadMap()
        {
            if (!_window.IsOpen)
            {
                throw new Exception("Window is not open!");
            }

            // Set background
            Texture backgroundTexture = new Texture(_context.GetGame.GetMapObject.GetBackground);

            if (backgroundTexture == null)
            {
                throw new Exception("Texture null!");
            }
            backgroundTexture.Repeated = true;

            _background = new SFML.Graphics.Sprite(backgroundTexture);
            if (_background == null)
            {
                throw new Exception("Sprite null!");
            }

            _background.Scale = new SFML.System.Vector2f(_window.Size.X / 550, _window.Size.Y / 550);
            _window.Draw(_background);

            // Set lifeBar
            _lifebarTexture = new Texture(_context.GetGame.GetMapObject.GetLifeBar);
            if (_lifebarTexture == null)
            {
                throw new Exception("Texture null!");
            }

            _hpBar = new SFML.Graphics.Sprite(_lifebarTexture);
            if (_hpBar == null)
            {
                throw new Exception("Sprite null!");
            }
            _hpBar.TextureRect = new IntRect(new SFML.System.Vector2i(0, 0), new SFML.System.Vector2i((int)_lifebarTexture.Size.X - ((int)_lifebarTexture.Size.X / 100) * (_context.GetGame.GetPlayer.GetLife.GetMaxPoint() - _context.GetGame.GetPlayer.GetLife.GetCurrentPoint), (int)_lifebarTexture.Size.Y));
            _window.Draw(_hpBar);

            Dictionary <Position, Sprite> map = _context.GetGame.GetMapObject.GetMap;

            _spritesDisplayed.Clear();

            foreach (KeyValuePair <Position, Sprite> s in map)
            {
                s.Value.GetSprite.Position = new SFML.System.Vector2f(s.Key.X * 128, _window.Size.Y + s.Key.Y * -128); //128*128 = Size of a sprite
                _window.Draw(s.Value.GetSprite);
                _spritesDisplayed.Add(s.Value.GetSprite.Position, s.Value);
            }
        }
Example #56
0
 internal GUI(Engine context, RenderWindow window)
 {
     _context           = context;
     _context2          = context;
     _window            = window;
     _spritesDisplayed  = new Dictionary <SFML.System.Vector2f, Sprite>();
     _spritesDisplayed2 = new Dictionary <SFML.System.Vector2f, Sprite>();
     _background        = new SFML.Graphics.Sprite();
     _moveTheMapOf      = new SFML.System.Vector2f(0, 0);
     _moveTheMapOf2     = new SFML.System.Vector2f(0, 0);
     _hpBar             = new SFML.Graphics.Sprite();
     _rect1             = new SFML.Graphics.Sprite();
     _spDegats          = new List <Stopwatch>();
 }
Example #57
0
        public void Dispose()
        {
            Console.WriteLine("Shutdown renderer.");

            if (this.sfmlSprite != null)
            {
                this.sfmlSprite.Dispose();
                this.sfmlSprite = null;
            }

            if (this.sfmlTexture != null)
            {
                this.sfmlTexture.Dispose();
                this.sfmlTexture = null;
            }
        }
Example #58
0
        public void Dispose()
        {
            if (sfmlSprite != null)
            {
                sfmlSprite.Dispose();
                sfmlSprite = null;
            }

            if (sfmlTexture != null)
            {
                sfmlTexture.Dispose();
                sfmlTexture = null;
            }

            Console.WriteLine("SFML resources are disposed.");
        }
Example #59
0
        public Ppu(RenderWindow window, int scale)
        {
            vRam           = new byte[0x2000];
            oam            = new byte[0xa0];
            pixels         = new byte[ScreenWidth * ScreenHeight * sizeof(uint)];
            scanlineBuffer = new int[160];

            this.window = window;
            texture     = new Texture(ScreenWidth, ScreenHeight);
            framebuffer = new SfmlSprite(texture)
            {
                Scale = new Vector2f(scale, scale)
            };

            stat.Init();
        }
Example #60
0
        public Layer(string name, int zorder = 0, bool chunked = true)
            : base(0, 0, (int)Core.ScrW, (int)Core.ScrH, zorder)
        {
            Buffer  = new RenderTexture((uint)FW, (uint)FH);
            View    = new View(new FloatRect(0, 0, FW, FH));
            SrcRect = new FloatRect(0, 0, FW, FH);
            Spr     = new SFML.Graphics.Sprite(Buffer.Texture);

            States.Transform = Transform.Identity;
            Spr.Color        = Color;

            if (chunked)
            {
                Chunks = new DrawableChunkCollection(256);
            }

            Chunked = chunked;
            Name    = name;
        }