GetGlobalBounds() public method

Get the global bounding rectangle of the entity. The returned rectangle is in global coordinates, which means that it takes in account the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the sprite in the global 2D world's coordinate system.
public GetGlobalBounds ( ) : FloatRect
return FloatRect
示例#1
0
 public TextButton(WindowManager _WM,string StartString, int _X, int _Y, int _SizeX, int _SizeY, EventHandler callback)
     : base(_WM, _X,_Y,_SizeX,_SizeY)
 {
     ButtonText = new Text(StartString, WM.font,15);
     ButtonPressed += callback;
     localx = _X;
     localy = _Y;
     BackPlate = new RectangleShape();
     //BackPlate.Size = new Vector2f(ButtonText
     BackPlate.FillColor = Color.Magenta;
     SetSize((int)ButtonText.GetGlobalBounds().Width, (int)ButtonText.GetGlobalBounds().Height*2);
     LeftSide = new Sprite(new Texture("UI.png", new IntRect(8, 32, 8, 24)));
     Center = new Sprite(new Texture("UI.png", new IntRect(17, 32, 1, 24)));
     Center.Scale = new Vector2f(sizeX-8-8, 1);
     RightSide = new Sprite(new Texture("UI.png", new IntRect(96, 32, 8, 24)));
 }
示例#2
0
        public TimeCounter()
            : base(4)
        {
            Elapsed = TimeSpan.Zero;

            Text = new Text();
            Text.DisplayedString = "00:00:00";
            Text.Font = Game.Assets.Fonts["Blocky"];
            Text.CharacterSize = 20;
            Text.Color = Color.White;
            Text.Position = new Vector2f((float)Game.Bounds.Center.X, 15);
            Text.Origin = new Vector2f(Text.GetGlobalBounds().Width * 0.5f, 0);
        }
        private Vector2f CalculatePosition(SFML.Graphics.Text textElement)
        {
            float x = 0;
            float y = 0;

            switch (HorizontalPosition)
            {
            case TextPosition.Start:
                x = ContainerPosition.X + Margins.X;
                break;

            case TextPosition.Middle:
                x = ContainerPosition.X + ContainerPosition.Width / 2 - textElement.GetGlobalBounds().Width / 2;
                break;

            case TextPosition.End:
                x = ContainerPosition.X + ContainerPosition.Width - textElement.GetGlobalBounds().Width - Margins.X;
                break;
            }

            switch (VerticalPosition)
            {
            case TextPosition.Start:
                y = ContainerPosition.Y + Margins.Y;
                break;

            case TextPosition.Middle:
                y = ContainerPosition.Y + ContainerPosition.Height / 2 - textElement.CharacterSize / 1.5F;
                break;

            case TextPosition.End:
                y = ContainerPosition.Y + ContainerPosition.Height - textElement.GetGlobalBounds().Height - Margins.Y;
                break;
            }

            return(new Vector2f((float)Math.Ceiling(x), (float)Math.Floor(y)));
        }
示例#4
0
 public ButtonElement(Screen _screen, Vector2f _position, string starttext, EventHandler callback)
     : base(_position,"DefaultButton",true)
 {
     Parent = _screen;
     text = new Text(starttext,Parent.ScreenManager.DefaultFont);
     text.Position = _position;
     this.Position = new Vector2f(text.GetGlobalBounds().Left, text.GetGlobalBounds().Top);
     Parent = _screen;
     Size = new Vector2f(text.GetGlobalBounds().Width,text.GetGlobalBounds().Height);
     debugshape = new RectangleShape(Size);//(new Vector2f(BoundingBox.Width,BoundingBox.Height));
     debugshape.Position = new Vector2f(text.GetGlobalBounds().Left, text.GetGlobalBounds().Top);
     Random rnd = new Random();
     debugshape.FillColor = new Color(0,0,0,255);
     debugshape.OutlineColor = Color.Green;
     debugshape.OutlineThickness = -1.0f;
     buttonPressed += callback;
 }
        private void DrawScore()
        {
            Text score = new Text (_score.ToString (), _font);
            Text wave = new Text ("Wave " + _wave.ToString(), _font);

            score.Color = Color.White;
            wave.Color = Color.White;
            score.CharacterSize = 40;
            wave.CharacterSize = 25;

            score.Position = new Vector2f (_window.Size.X - score.GetGlobalBounds ().Width - 10, 0);
            wave.Position = new Vector2f (10, 0);

            _window.Draw (score);
            _window.Draw (wave);
        }
        private void DrawEquationSolver()
        {
            // load font
            String eqText = _eqToSolve.GetEquation.val1 + " " + Equation.GetString(_eqToSolve.GetEquation.type) + " " + _eqToSolve.GetEquation.val2 + "\n= " + _eqCurrentInput;
            Text eq = new Text (eqText, _font);

            // align backgroud with text
            RectangleShape background = new RectangleShape (new Vector2f (eq.GetGlobalBounds().Width + 90, eq.GetGlobalBounds().Height + 45));
            background.FillColor = Color.Red;

            Vector2f pos = new Vector2f (_window.Size.X/2 - (background.Size.X/2), _window.Size.Y/2 - (background.Size.Y/2));
            background.Position = pos;
            eq.Position = new Vector2f (pos.X + 40, pos.Y + 20);

            _window.Draw (background);
            _window.Draw (eq);
        }
示例#7
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();
            }
        }
示例#8
0
		/// <summary>
		/// Funkcja wyświetla ekran tytułowy
		/// </summary>
		private static void DisplayTitle() {
			Text grad = new Text("Praca inżynierska", font, 60) {
							Color = Color.White,
							Style = Text.Styles.Bold
						};
			grad.Origin = new Vector2f(grad.GetGlobalBounds().Width / 2, grad.GetGlobalBounds().Height / 2);
			grad.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 335);

			Text author = new Text("Autor:", font, 20) {
							  Color = Color.White
						  };
			author.Origin = new Vector2f(author.GetGlobalBounds().Width / 2, author.GetGlobalBounds().Height / 2);
			author.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 275);

			Text who = new Text("Mateusz Winiarski", font, 20) {
						   Color = Color.White,
						   Style = Text.Styles.Italic | Text.Styles.Bold
					   };
			who.Origin = new Vector2f(who.GetGlobalBounds().Width / 2, who.GetGlobalBounds().Height / 2);
			who.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 250);

			Text AGH1 = new Text("Akademia Górniczo-Hutnicza", font, 25) {
							Color = Color.White
						};
			AGH1.Origin = new Vector2f(AGH1.GetGlobalBounds().Width / 2, AGH1.GetGlobalBounds().Height / 2);
			AGH1.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 200);

			Text AGH2 = new Text("im. Stanisława Staszica w Krakowie", font, 25) {
							Color = Color.White
						};
			AGH2.Origin = new Vector2f(AGH2.GetGlobalBounds().Width / 2, AGH2.GetGlobalBounds().Height / 2);
			AGH2.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 175);

			Text WFiIS = new Text("Wydział Fizyki i Informatyki Stosowanej", font, 25) {
							 Color = Color.White
						 };
			WFiIS.Origin = new Vector2f(WFiIS.GetGlobalBounds().Width / 2, WFiIS.GetGlobalBounds().Height / 2);
			WFiIS.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 125);

			Text IS = new Text("Informatyka Stosowana", font, 25) {
						  Color = Color.White
					  };
			IS.Origin = new Vector2f(IS.GetGlobalBounds().Width / 2, IS.GetGlobalBounds().Height / 2);
			IS.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 100);

			Text topic1 = new Text("Sztuczna inteligencja w grach komputerowych", font, 35) {
							  Color = Color.White
						  };
			topic1.Origin = new Vector2f(topic1.GetGlobalBounds().Width / 2, topic1.GetGlobalBounds().Height / 2);
			topic1.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 45);

			Text topic2 = new Text("na przykładzie logiki rozmytej, algorytmu stada", font, 35) {
							  Color = Color.White
						  };
			topic2.Origin = new Vector2f(topic2.GetGlobalBounds().Width / 2, topic2.GetGlobalBounds().Height / 2);
			topic2.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 10);

			Text topic3 = new Text("i problemu najkrótszej ścieżki w grze 2D.", font, 35) {
							  Color = Color.White
						  };
			topic3.Origin = new Vector2f(topic3.GetGlobalBounds().Width / 2, topic3.GetGlobalBounds().Height / 2);
			topic3.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 + 25);

			Text prom = new Text("Promotor:", font, 20) {
							Color = Color.White
						};
			prom.Origin = new Vector2f(prom.GetGlobalBounds().Width / 2, prom.GetGlobalBounds().Height / 2);
			prom.Position = new Vector2f(window.Size.X / 2 - 250, window.Size.Y / 2 + 120);

			Text promName = new Text("dr inż. Janusz Malinowski", font, 20) {
								Color = Color.White,
								Style = Text.Styles.Italic
							};
			promName.Origin = new Vector2f(promName.GetGlobalBounds().Width / 2, promName.GetGlobalBounds().Height / 2);
			promName.Position = new Vector2f(window.Size.X / 2 - 250, window.Size.Y / 2 + 145);

			Text rec = new Text("Recenzent:", font, 20) {
						   Color = Color.White
					   };
			rec.Origin = new Vector2f(rec.GetGlobalBounds().Width / 2, rec.GetGlobalBounds().Height / 2);
			rec.Position = new Vector2f(window.Size.X / 2 + 250, window.Size.Y / 2 + 120);

			Text recName = new Text("Unknown", font, 20) {
							   Color = Color.White,
							   Style = Text.Styles.Italic
						   };
			recName.Origin = new Vector2f(recName.GetGlobalBounds().Width / 2, recName.GetGlobalBounds().Height / 2);
			recName.Position = new Vector2f(window.Size.X / 2 + 250, window.Size.Y / 2 + 145);

			Text wait = new Text("Proszę czekać. Trwa generowanie mapy.", font, 30) {
							Color = Color.Red,
							Style = Text.Styles.Bold
						};
			wait.Origin = new Vector2f(wait.GetGlobalBounds().Width / 2, wait.GetGlobalBounds().Height / 2);
			wait.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 + 220);

			Text time = new Text("Może to mi troszkę zająć. Cierpliwości :)", font, 20) {
							Color = Color.Red,
							Style = Text.Styles.Bold | Text.Styles.Italic
						};
			time.Origin = new Vector2f(time.GetGlobalBounds().Width / 2, time.GetGlobalBounds().Height / 2);
			time.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 + 255);

			window.Clear();
			window.Draw(grad);
			window.Draw(author);
			window.Draw(who);
			window.Draw(AGH1);
			window.Draw(AGH2);
			window.Draw(WFiIS);
			window.Draw(IS);
			window.Draw(topic1);
			window.Draw(topic2);
			window.Draw(topic3);
			window.Draw(prom);
			window.Draw(promName);
			window.Draw(rec);
			window.Draw(recName);
			window.Draw(wait);
			window.Draw(time);
			window.Display();
		}
示例#9
0
        public override void Render(RenderTarget target)
        {
            //Setting view to camera position
            View view = target.GetView();
            view.Center = new Vector2f((int) CameraPosition.X, (int) CameraPosition.Y);
            target.SetView(view);

            var screenBounds = new FloatRect
            {
                Left = view.Center.X - (view.Size.X / 2),
                Top = view.Center.Y - (view.Size.Y / 2),
                Width = view.Size.X,
                Height = view.Size.Y
            };

            //Drawing map/tiles
            map.Render(target, screenBounds, Fog);

            RenderRallypoints(target);

            //Draw selected unit circles
            const float selectCircleRadius = 20;
            var selectedCircle = new CircleShape(selectCircleRadius);
            selectedCircle.OutlineColor = new Color(100, 255, 100, 200);
            selectedCircle.OutlineThickness = 5;
            selectedCircle.FillColor = new Color(0, 0, 0, 0);
            selectedCircle.Origin = new Vector2f(selectCircleRadius, selectCircleRadius);

            if (selectedUnits != null)
            {
                foreach (EntityBase entityBase in selectedUnits)
                {
                    selectedCircle.Position = entityBase.Position;
                    target.Draw(selectedCircle);
                }
            }

            var debugHPText = new Text();
            debugHPText.Scale = new Vector2f(.6f, .6f);
            debugHPText.Color = new Color(255, 255, 255, 100);
            var readOnly = new Dictionary<ushort, EntityBase>(entities);

            foreach (EntityBase entityBase in readOnly.Values)
            {
                if (entityBase.GetBounds().Intersects(screenBounds))
                {
                    if (Fog != null)
                    {
                        var coords = map.ConvertCoords(entityBase.Position);
                        entityBase.Render(target, Fog.Grid[(int) coords.X, (int) coords.Y].CurrentState);
                        if (Fog.Grid[(int)coords.X, (int)coords.Y].CurrentState == FOWTile.TileStates.CurrentlyViewed)
                        {
                            entityBase.HasBeenViewed = true;
                        }

                        debugHPText.Color = new Color(255, 255, 255, 200);
                        debugHPText.DisplayedString = "HP: " + entityBase.Health.ToString();
                        debugHPText.Origin = new Vector2f(debugHPText.GetGlobalBounds().Width/2,
                                                          debugHPText.GetGlobalBounds().Height);
                        debugHPText.Position = entityBase.Position;

                        target.Draw(debugHPText);
                        if (entityBase is BuildingBase)
                        {
                            var buildingCast = (BuildingBase) entityBase;
                            if (buildingCast.IsProductingUnit)
                            {
                                debugHPText.Color = new Color(255, 255, 0, 100);
                                debugHPText.DisplayedString = buildingCast.UnitBuildCompletePercent.ToString();
                                debugHPText.Position += new Vector2f(0, 50);
                                target.Draw(debugHPText);
                            }
                        }
                    }
                }
            }

            var readOnlyEffect = new List<EffectBase>(Effects);
            foreach (EffectBase effectBase in readOnlyEffect)
            {
                effectBase.Render(target);
            }

            if (releaseSelect)
            {
                var rect = new FloatRect(controlBoxP1.X, controlBoxP1.Y, controlBoxP2.X - controlBoxP1.X,
                                         controlBoxP2.Y - controlBoxP1.Y);
                var rectangle = new RectangleShape(new Vector2f(rect.Width, rect.Height));
                rectangle.Position = new Vector2f(rect.Left, rect.Top);
                rectangle.FillColor = new Color(100, 200, 100, 100);
                target.Draw(rectangle);
            }

            //Draw Alerts
            const int ALERTXOFFSET = 10;
            const int ALERTYMULTIPLE = 60;
            const int ALERTYOFFSET = 20;
            for (int i = 0; i < alerts.Count; i++)
            {
                HUDAlert alert = alerts[i];

                Sprite sprite = null;
                switch (alert.Type)
                {
                    case HUDAlert.AlertTypes.CreatedUnit:
                        sprite = alertHUDUnitCreated;
                        break;
                    case HUDAlert.AlertTypes.UnitUnderAttack:
                        sprite = alertHUDAlert;
                        break;
                    case HUDAlert.AlertTypes.UnitCreated:
                        sprite = alertHUDUnitCreated;
                        break;
                    case HUDAlert.AlertTypes.BuildingCompleted:
                        sprite = alertHUDBuildingCreated;
                        break;
                    default:
                        break;
                }

                if (sprite != null)
                {
                    sprite.Position = target.ConvertCoords(new Vector2i(ALERTXOFFSET, ALERTYOFFSET + ALERTYMULTIPLE*i));
                    sprite.Color = new Color(255, 255, 255, (byte) alert.Alpha);
                    target.Draw(sprite);
                }
            }

            //Draw bottom GUI
            bottomHUDGUI.Position = target.ConvertCoords(new Vector2i(0, 0));
            target.Draw(bottomHUDGUI);

            //Draw minimap
            miniMap.Render();
            miniMap.MapSprite.Position = target.ConvertCoords(new Vector2i((int)MINIMAPPOSX, (int)MINIMAPPOSY));
            target.Draw(miniMap.MapSprite);

            //Draw unit stats HUD

            if (selectedUnits != null)
            {
                if (selectedUnits.Length == 1)
                {
                    var hpText = new Text(selectedUnits[0].Health + "/" + selectedUnits[0].MaxHealth);
                    hpText.Position = target.ConvertCoords(new Vector2i(500, (int) target.Size.Y - 50));
                    hpText.Scale = new Vector2f(.7f, .7f);
                    target.Draw(hpText);

                    EntityBase priorUnit = prioritySelectedUnit();

                    Sprite unitAvatar = avatarWorker;

                    switch (priorUnit.Type)
                    {
                        case Entity.EntityType.Unit:
                            break;
                        case Entity.EntityType.Building:
                            break;
                        default:
                        case Entity.EntityType.Worker:
                            unitAvatar = avatarWorker;
                            break;
                        case Entity.EntityType.Resources:
                            break;
                        case Entity.EntityType.HomeBuilding:
                            break;
                        case Entity.EntityType.SupplyBuilding:
                            break;
                    }

                    if (unitAvatar != null)
                    {
                        unitAvatar.Position = hpText.Position - new Vector2f(50, 175);
                        target.Draw(unitAvatar);
                    }
                }
                else if (selectedUnits.Length > 1)
                {
                    const byte MAXROWCOUNT = 8;

                    byte XCount = 0, YCount = 0, IterateCount = 0;
                    for (int i = 0; i < selectedUnits.Length; i++)
                    {
                        Sprite boxSprite = hudBoxUnit;
                        if (selectedUnits[i] is BuildingBase)
                        {
                            boxSprite = hudBoxBuilding;
                        }
                        else if (selectedUnits[i] is UnitBase)
                        {
                            boxSprite = hudBoxUnit;
                        }

                        if (boxSprite != null)
                        {
                            const float XOFFSET = 300;
                            const float YOFFSET = 545;
                            const float XMULTIPLY = 55;
                            const float YMULTIPLY = 55;

                            boxSprite.Position = new Vector2f(XOFFSET + (XCount*XMULTIPLY), YOFFSET + (YCount*YMULTIPLY));
                            boxSprite.Position =
                                target.ConvertCoords(new Vector2i((int) boxSprite.Position.X, (int) boxSprite.Position.Y));
                            target.Draw(boxSprite);
                        }

                        XCount++;
                        if (XCount == MAXROWCOUNT)
                        {
                            XCount = 0;
                            YCount++;
                        }
                    }
                }
            }

            //Draw Control Groups
            const int CONTROLBOXXOFFSET = 310;
            const int CONTROLBOXYOFFSET = 505;
            const int CONTROLBOXXMULTIPLY = 55;

            int counter = 0;
            var controlNumberText = new Text("0");

            foreach (var controlGroup in controlGroups.Values)
            {
                if (controlGroup != null && controlGroup.Count > 0)
                {
                    controlNumberText.DisplayedString = (counter + 1).ToString();
                    controlNumberText.Scale = new Vector2f(.4f, .4f);
                    controlNumberText.Origin = new Vector2f((controlNumberText.GetGlobalBounds().Width/2),
                                                            (controlNumberText.GetGlobalBounds().Height/2));

                    hudControlBox.Position =
                        target.ConvertCoords(new Vector2i(CONTROLBOXXOFFSET + CONTROLBOXXMULTIPLY*counter,
                                                          CONTROLBOXYOFFSET));
                    controlNumberText.Position = hudControlBox.Position + new Vector2f(0, 24);
                    target.Draw(hudControlBox);
                    target.Draw(controlNumberText);

                    controlNumberText.DisplayedString = controlGroup.Count.ToString();
                    controlNumberText.Position = hudControlBox.Position + new Vector2f(0, 5);
                    controlNumberText.Scale = new Vector2f(.7f, .7f);
                    target.Draw(controlNumberText);
                }
                counter++;
            }

            if (myPlayer != null)
            {
                debugHPText.Origin = new Vector2f(0, 0);
                debugHPText.Scale = new Vector2f(.5f, .5f);
                debugHPText.Position = target.ConvertCoords(new Vector2i(0, 0));
                debugHPText.DisplayedString = "APL: " + myPlayer.Apples.ToString();
                target.Draw(debugHPText);

                debugHPText.Position += new Vector2f(100, 0);
                debugHPText.DisplayedString = "GLU: " + myPlayer.Glue.ToString();
                target.Draw(debugHPText);

                debugHPText.Position += new Vector2f(100, 0);
                debugHPText.DisplayedString = "WOD: " + myPlayer.Wood.ToString();
                target.Draw(debugHPText);

                debugHPText.Position += new Vector2f(100, 0);
                debugHPText.DisplayedString = "SUP: " + myPlayer.UsedSupply.ToString() + "/" + myPlayer.Supply;
                target.Draw(debugHPText);
            }

            if (CurrentStatus == StatusState.WaitingForPlayers)
            {
                var shape = new RectangleShape(new Vector2f(target.Size.X, target.Size.Y));
                shape.Position = target.ConvertCoords(new Vector2i(0, 0));
                shape.FillColor = new Color(0, 0, 0, 200);
                target.Draw(shape);

                var text = new Text("Waiting for Players...");
                text.Position = target.ConvertCoords(new Vector2i((int) target.Size.X/2, (int) target.Size.Y/2));
                text.Origin = new Vector2f(text.GetGlobalBounds().Width/2, text.GetGlobalBounds().Height/2);
                text.Color = new Color(255, 255, 255, 100);
                target.Draw(text);
            }

            if (CurrentStatus == StatusState.Completed)
            {
                var text = new Text("Game Completed...");
                text.Position = target.ConvertCoords(new Vector2i((int) target.Size.X/2, 10));
                text.Origin = new Vector2f(text.GetGlobalBounds().Width/2, 0);
                text.Color = new Color(255, 255, 255, 100);
                target.Draw(text);
            }

            viewBounds.Position = target.ConvertCoords(new Vector2i(0, 0));
            target.Draw(viewBounds);
        }
示例#10
0
        public override void Render(RenderTarget target)
        {
            var renderName = new Text(PlayerName);
            renderName.Position = target.ConvertCoords(new Vector2i(10, 10));
            renderName.Scale = new Vector2f(.6f, .6f);
            target.Draw(renderName);

            var gameName = new Text("MY LITTLE GLUE FACTORY");
            gameName.Scale = new Vector2f(1, 1);
            gameName.Origin = new Vector2f(gameName.GetGlobalBounds().Width/2, gameName.GetGlobalBounds().Height/2);
            gameName.Position = target.ConvertCoords(new Vector2i((int) target.Size.X/2, 10));
            target.Draw(gameName);

            for(var i = 0; i < options.Count; i++)
            {
                if(selectedOption == i)
                {
                    target.Draw(options[i][1]);
                }
                else
                {
                    target.Draw(options[i][0]);
                }
            }
        }
示例#11
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Draws the widget on the render target
        /// </summary>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public override void Draw(RenderTarget target, RenderStates states)
        {
            // Calculate the scale factor of the view
            float scaleViewX = target.Size.X / target.GetView().Size.X;
            float scaleViewY = target.Size.Y / target.GetView().Size.Y;

            // Get the global position
            Vector2f topLeftPosition;
            Vector2f bottomRightPosition;

            Vector2f viewPosition = (target.GetView().Size / 2.0f) - target.GetView().Center;

            if ((m_Scroll != null) && (m_Scroll.LowValue < m_Scroll.Maximum))
            {
                topLeftPosition = states.Transform.TransformPoint(Position + viewPosition);
                bottomRightPosition = states.Transform.TransformPoint(Position.X + m_Size.X - m_Scroll.Size.X + viewPosition.X, Position.Y + m_Size.Y + viewPosition.Y);
            }
            else
            {
                topLeftPosition = states.Transform.TransformPoint(Position + viewPosition);
                bottomRightPosition = states.Transform.TransformPoint(Position + m_Size + viewPosition);
            }

            // Adjust the transformation
            states.Transform *= Transform;

            // Remember the current transformation
            Transform oldTransform = states.Transform;

            // Draw the borders
            {
                // Draw left border
                RectangleShape border = new RectangleShape(new Vector2f(m_Borders.Left, m_Size.Y + m_Borders.Top));
                border.Position = new Vector2f(-(float)m_Borders.Left, -(float)m_Borders.Top);
                border.FillColor = BorderColor;
                target.Draw(border, states);

                // Draw top border
                border.Size = new Vector2f(Size.X + m_Borders.Right, m_Borders.Top);
                border.Position = new Vector2f(0, -(float)m_Borders.Top);
                target.Draw(border, states);

                // Draw right border
                border.Size = new Vector2f(m_Borders.Right, m_Size.Y + m_Borders.Bottom);
                border.Position = new Vector2f(Size.X, 0);
                target.Draw(border, states);

                // Draw bottom border
                border.Size = new Vector2f(Size.X + m_Borders.Left, m_Borders.Bottom);
                border.Position = new Vector2f(-(float)m_Borders.Left, m_Size.Y);
                target.Draw(border, states);
            }

            // Draw the background
            RectangleShape front = new RectangleShape (new Vector2f((float)m_Size.X, (float)m_Size.Y));
            front.FillColor = m_BackgroundColor;
            target.Draw(front, states);

            // Get the old clipping area
            int[] scissor = new int[4];
            Gl.glGetIntegerv(Gl.GL_SCISSOR_BOX, scissor);

            // Calculate the clipping area
            int scissorLeft = System.Math.Max((int)(topLeftPosition.X * scaleViewX), scissor[0]);
            int scissorTop = System.Math.Max((int)(topLeftPosition.Y * scaleViewY), (int)(target.Size.Y) - scissor[1] - scissor[3]);
            int scissorRight = System.Math.Min((int)(bottomRightPosition.X * scaleViewX), scissor[0] + scissor[2]);
            int scissorBottom = System.Math.Min((int)(bottomRightPosition.Y * scaleViewY), (int)(target.Size.Y) - scissor[1]);

            // If the widget outside the window then don't draw anything
            if (scissorRight < scissorLeft)
                scissorRight = scissorLeft;
            else if (scissorBottom < scissorTop)
                scissorTop = scissorBottom;

            // Create a text widget to draw the items
            Text text = new Text("", m_TextFont, m_TextSize);

            // Check if there is a scrollbar and whether it isn't hidden
            if ((m_Scroll != null) && (m_Scroll.LowValue < m_Scroll.Maximum))
            {
                // Store the transformation
                Transform storedTransform = states.Transform;

                // Find out which items should be drawn
                uint firstItem = (uint)(m_Scroll.Value / m_ItemHeight);
                uint lastItem = (uint)((m_Scroll.Value + m_Scroll.LowValue) / m_ItemHeight);

                // Show another item when the scrollbar is standing between two items
                if ((m_Scroll.Value + m_Scroll.LowValue) % m_ItemHeight != 0)
                    ++lastItem;

                // Set the clipping area
                Gl.glScissor(scissorLeft, (int)(target.Size.Y - scissorBottom), scissorRight - scissorLeft, scissorBottom - scissorTop);

                for (uint i = firstItem; i < lastItem; ++i)
                {
                    // Restore the transformations
                    states.Transform = storedTransform;

                    // Set the next item
                    text.DisplayedString = m_Items[(int)i];

                    // Get the global bounds
                    FloatRect bounds = text.GetGlobalBounds();

                    // Check if we are drawing the selected item
                    if (m_SelectedItem == (int)(i))
                    {
                        // Draw a background for the selected item
                        {
                            // Set a new transformation
                            states.Transform.Translate(0, ((float)(i * m_ItemHeight) - m_Scroll.Value));

                            // Create and draw the background
                            RectangleShape back = new RectangleShape(new Vector2f((float)m_Size.X, (float)m_ItemHeight));
                            back.FillColor = m_SelectedBackgroundColor;
                            target.Draw(back, states);

                            // Restore the transformation
                            states.Transform = storedTransform;
                        }

                        // Change the text color
                        text.Color = m_SelectedTextColor;
                    }
                    else // Set the normal text color
                        text.Color = m_TextColor;

                    // Set the translation for the text
                    states.Transform.Translate(2, (float)System.Math.Floor((float)(i * m_ItemHeight) - m_Scroll.Value + ((m_ItemHeight - bounds.Height) / 2.0f) - bounds.Top));

                    // Draw the text
                    target.Draw(text, states);
                }
            }
            else // There is no scrollbar or it is invisible
            {
                // Set the clipping area
                Gl.glScissor(scissorLeft, (int)(target.Size.Y - scissorBottom), scissorRight - scissorLeft, scissorBottom - scissorTop);

                // Store the current transformations
                Transform storedTransform = states.Transform;

                for (uint i = 0; i < m_Items.Count; ++i)
                {
                    // Restore the transformations
                    states.Transform = storedTransform;

                    // Set the next item
                    text.DisplayedString = m_Items[(int)i];

                    // Check if we are drawing the selected item
                    if (m_SelectedItem == (int)(i))
                    {
                        // Draw a background for the selected item
                        {
                            // Set a new transformation
                            states.Transform.Translate(0, (float)(i * m_ItemHeight));

                            // Create and draw the background
                            RectangleShape back = new RectangleShape(new Vector2f((float)m_Size.X, (float)m_ItemHeight));
                            back.FillColor = m_SelectedBackgroundColor;
                            target.Draw(back, states);

                            // Restore the transformation
                            states.Transform = storedTransform;
                        }

                        // Change the text color
                        text.Color = m_SelectedTextColor;
                    }
                    else // Set the normal text color
                        text.Color = m_TextColor;

                    // Get the global bounds
                    FloatRect bounds = text.GetGlobalBounds();

                    // Set the translation for the text
                    states.Transform.Translate(2, (float)System.Math.Floor((i * m_ItemHeight) + ((m_ItemHeight - bounds.Height) / 2.0f) - bounds.Top));

                    // Draw the text
                    target.Draw(text, states);
                }
            }

            // Reset the old clipping area
            Gl.glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);

            // Check if there is a scrollbar
            if (m_Scroll != null)
            {
                // Reset the transformation
                states.Transform = oldTransform;
                states.Transform.Translate((float)m_Size.X - m_Scroll.Size.X, 0);

                // Draw the scrollbar
                target.Draw(m_Scroll, states);
            }
        }
示例#12
0
        public override void Draw(RenderTarget rt)
        {
            if (!Visible)
                return;

            RectangleShape button = new RectangleShape(new Vector2f(Width, Height))
            {
                Position = Position,
                FillColor = Color.Black
            };

            rt.Draw(button);

            // Hover
            if (mouseIn)
            {
                RectangleShape buttonHover = new RectangleShape(new Vector2f(Width - 8, Height - 8))
                {
                    Position = Position + new Vector2f(4.0f, 4.0f),
                    FillColor = Color.Black,
                    OutlineColor = Color.White,
                    OutlineThickness = 2.0f
                };

                rt.Draw(buttonHover);
            }

            Text text = new Text(value, Assets.LoadFont(Program.DefaultFont))
            {
                Position = Position + Size / 2.0f,
                CharacterSize = 24,
                Style = Text.Styles.Bold
            };

            FloatRect bounds = text.GetGlobalBounds();
            text.Position -= new Vector2f(bounds.Width / 2.0f, bounds.Height / 2.0f + 4.0f);

            text.Round();
            rt.Draw(text);

            base.Draw(rt);
        }
示例#13
0
        //from the internets:
        internal static int GetWidth(Text Text){
		    //Make sure its not empty, because this would crash it later otherwise.
		    if( Text.ToString().Length == 0 )
			    return 0;

		    //Temp variables that use the same font and size as the original text.
		    //This is to get the width of one '#'
		    Text Temp1 = new Text( "#", Text.Font, Text.CharacterSize );
		    Text Temp2 = new Text( "# #", Text.Font, Text.CharacterSize );
    		
		    //Now we can get the width of the whitespace by subtracting the width of 2 '#' from "# #".
		    int Width = (int)(Temp2.GetGlobalBounds().Width - Temp1.GetGlobalBounds().Width*2);

		    //The width of the string without taking into consideration for spaces left at the beggining or end.
		    int TotalWidth = (int)Text.GetGlobalBounds().Width;

		    //Get the text from the sf::Text as an std::string.
		    string str = Text.ToString();

		    //Bool to see if we encounter a string consisting of only spaces.
		    bool OnlySpaces = false;

		    //Go through all characters in the string from the start.
		    for( int i = 0; i < str.Length; i++ )
		    {
			    if( str[i] == ' ' )
				    //Add each space's width to the sum of it all.
				    TotalWidth += Width;
			    else
				    break;

			    //Check if we have gone through the whole string.
			    if( i == str.Length -1 )
				    OnlySpaces = true;
		    }

		    //Go through all characters in the string from the end, as long as it wasn't only spaces.
		    if( !OnlySpaces )
		    {
                for (int i = str.Length - 1; i > 0; i--)
			    {
                    if (str[i] == ' ')
					    //Add each space's width to the sum of it all.
					    TotalWidth += Width;
				    else
					    break;
			    }
		    }

		    return TotalWidth;
	    }
示例#14
0
        public override void Draw(RenderTarget rt)
        {
            RectangleShape barArea = new RectangleShape(Size)
            {
                Position = Position,
                FillColor = Color.Black
            };

            rt.Draw(barArea);

            Text labelText = new Text(label, Assets.LoadFont(Program.DefaultFont))
            {
                Position = Position + new Vector2f(16.0f, -24.0f),
                CharacterSize = 18,
                Color = Color.Black
            };

            labelText.Round();
            rt.Draw(labelText);

            Text messageText = new Text(Value, Assets.LoadFont(Program.DefaultFont))
            {
                Position = Position + new Vector2f(8.0f, 8.0f),
                CharacterSize = 28,
                Color = Color.White
            };

            messageText.Round();
            rt.Draw(messageText);

            if (Selected && cursorVisible)
            {
                RectangleShape cursor = new RectangleShape(new Vector2f(2.0f, Size.Y - 16.0f))
                {
                    Position = Position + new Vector2f(messageText.GetGlobalBounds().Width + 8.0f + 4.0f, 8.0f),
                    FillColor = Color.White
                };

                cursor.Round();
                rt.Draw(cursor);
            }

            base.Draw(rt);
        }
示例#15
0
        public override void Draw(RenderTarget rt)
        {
            RectangleShape numberbox = new RectangleShape(Size)
            {
                Position = Position,
                FillColor = Color.Black,
            };

            rt.Draw(numberbox);

            if (mouseIn)
            {
                RectangleShape checkboxHover = new RectangleShape(new Vector2f(64.0f - 8.0f, 48.0f - 8.0f))
                {
                    Position = Position + new Vector2f(4f, 4f),
                    FillColor = Color.Black,
                    OutlineColor = Color.White,
                    OutlineThickness = 2f
                };

                rt.Draw(checkboxHover);
            }

            Text valueText = new Text(stringValue, Assets.LoadFont(Program.DefaultFont))
            {
                Position = Position + new Vector2f(8.0f, 8.0f),
                CharacterSize = 28,
                Color = Color.White
            };

            valueText.Round();
            rt.Draw(valueText);

            if (Selected && cursorVisible)
            {
                RectangleShape cursor = new RectangleShape(new Vector2f(2.0f, Size.Y - 16.0f))
                {
                    Position = Position + new Vector2f(valueText.GetGlobalBounds().Width + 8.0f + 4.0f, 8.0f),
                    FillColor = Color.White
                };

                cursor.Round();
                rt.Draw(cursor);
            }

            Text labelText = new Text(label, Assets.LoadFont(Program.DefaultFont))
            {
                Position = Position + new Vector2f(64.0f + 16.0f, 24.0f + 2.0f),
                CharacterSize = 32,
                Color = Color.Black
            };

            labelText.Center(false);
            labelText.Round();
            rt.Draw(labelText);
        }