GetLocalBounds() public method

Get the local bounding rectangle of the entity. The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the entity in the entity's coordinate system.
public GetLocalBounds ( ) : FloatRect
return FloatRect
Beispiel #1
0
        private Text CreateTextItem(string text, Font font, uint size, float xPos, float yPos)
        {
            var textItem = new Text(text, font, size);
            textItem.Origin = new Vector2f(
                textItem.GetLocalBounds().Left + textItem.GetLocalBounds().Width / 2,
                textItem.GetLocalBounds().Top + textItem.GetLocalBounds().Height / 2);
            textItem.Position = new Vector2f(xPos, yPos);

            return textItem;
        }
Beispiel #2
0
        public GameStateFinish(string message, bool won)
        {
            _won = won;
            Game.Instance.AudioManager.PauseAllBackground();
            Game.Instance.AudioManager.PlaySound("finish/" + (won ? "win" : "lose") + "_music");

            _background = new Sprite(ResourceManager.Instance["menu/background"] as Texture);

            _text = new Text(message, ResourceManager.Instance["fonts/bebas_neue"] as Font, 50);
            _text.Origin = new Vector2f(_text.GetLocalBounds().Width / 2, _text.GetLocalBounds().Height / 2);
            _text.Position = new Vector2f(Game.Instance.Width / 2, Game.Instance.Height / 2);

            Game.Instance.Window.KeyReleased += WindowOnKeyReleased;
        }
Beispiel #3
0
        public Button(string text, Font font, uint fontSize, Vector2f position, float scale = 1f)
        {
            _text = new Text(text, font, fontSize);
            _text.Origin = new Vector2f(
                _text.GetLocalBounds().Left + _text.GetLocalBounds().Width / 2,
                _text.GetLocalBounds().Top + _text.GetLocalBounds().Height);
            _text.Position = position;
            _text.Scale = new Vector2f(scale, scale);

            var increaseAnimation = new ScaleAnimation<Button>(scale, 1f);
            var decreaseAnimation = new ScaleAnimation<Button>(1f, scale);
            _animator.AddAnimation("increase", increaseAnimation, TimeSpan.FromMilliseconds(200));
            _animator.AddAnimation("decrease", decreaseAnimation, TimeSpan.FromMilliseconds(200));
        }
 public static int MeasureText_Width(string Text)
 {
     // Data do Text
     SFML.Graphics.Text TempText = new SFML.Graphics.Text(Text, Graphics.Fonte);
     TempText.CharacterSize = 10;
     return((int)TempText.GetLocalBounds().Width);
 }
        public BigLabeledButtonComponent(Screen screen, Texture buttonTexture, Vector2f position, string text, Color buttonColor, Action onClick)
            : base(screen)
        {
            _buttonTexture = buttonTexture;
            _position = position;
            _buttonColor = buttonColor;
            _selectedColor = new Color(
                (byte)Math.Min(255, (int)_buttonColor.R + 50),
                (byte)Math.Min(255, (int)_buttonColor.G + 50),
                (byte)Math.Min(255, (int)_buttonColor.B + 50),
                255);
            _onClick = onClick;
            _font = ResourceManager.getResource<Font>("immortal_font");

            // Initialize button shape
            _buttonShape = new RectangleShape();
            _buttonShape.Texture = _buttonTexture;
            _buttonShape.Position = position;
            _buttonShape.Size = new Vector2f(_buttonShape.Texture.Size.X, _buttonShape.Texture.Size.Y);
            _buttonShape.FillColor = _buttonColor;

            // Initialize text
            _firstLetter = new Text(text.Substring(0, 1), _font, 72);
            _firstLetter.Position = position + new Vector2f(30, 0);
            _firstLetter.Color = Color.White;
            _firstLetterShadow = new Text(_firstLetter.DisplayedString, _font, 72);
            _firstLetterShadow.Position = _firstLetter.Position + new Vector2f(3, 3);
            _firstLetterShadow.Color = Color.Black;
            _word = new Text(text.Substring(1, text.Length - 1), _font, 48);
            _word.Position = _firstLetter.Position + new Vector2f(_firstLetter.GetLocalBounds().Width + 4, 13);
            _word.Color = Color.White;
            _wordShadow = new Text(_word.DisplayedString, _font, 48);
            _wordShadow.Position = _word.Position + new Vector2f(3, 3);
            _wordShadow.Color = Color.Black;
        }
Beispiel #6
0
 public static short MeasureString(string Text)
 {
     // Dados do texto
     SFML.Graphics.Text TempText = new SFML.Graphics.Text(Text, Graphics.Font_Default);
     TempText.CharacterSize = 10;
     return((short)TempText.GetLocalBounds().Width);
 }
 protected override float getTextWidthImpl(char[] chars)
 {
     using (Text textObj = createText(new PVector(), chars))
     {
         return(textObj.GetLocalBounds().Width);
     }
 }
Beispiel #8
0
        public Vector2f MeasureString(TextString str)
        {
            Vector2f size = new Vector2f(0f,0f);
            Vector2f curLineSize = new Vector2f(0f, 0f);

            foreach (KeyValuePair<TextStyle, string> s in str.FormatedText)
            {
                if (s.Key == TextStyle.EndLine)
                {
                    size.Y += curLineSize.Y;
                    size.X = curLineSize.X > size.X ? curLineSize.X : size.X;
                    curLineSize = new Vector2f(0f, 0f);
                }
                else
                {
                    Text textSlope = new Text(s.Value, Font, str.CharacterSize);
                    Text.Styles textStyle = Text.Styles.Regular;
                    if ((s.Key & TextStyle.Bold) != 0)
                        textStyle |= Text.Styles.Bold;
                    if( (s.Key & TextStyle.Italic) != 0)
                        textStyle |= Text.Styles.Italic;
                    textSlope.Style = textStyle;
                    FloatRect localBounds = textSlope.GetLocalBounds();

                    Vector2f ssize = new Vector2f(localBounds.Width,localBounds.Height);
                    curLineSize.X += (int)ssize.X;
                    curLineSize.Y = (int)ssize.Y > curLineSize.Y ? (int)ssize.Y : curLineSize.Y;
                }
            }

            size.X = curLineSize.X > size.X ? curLineSize.X : size.X;
            size.Y += curLineSize.Y;
            return size;
        }
Beispiel #9
0
 void OnTextChange()
 {
     if (autoScale)
     {
         Size = new Vector2f(text.GetLocalBounds().Width + OUTLINE_WIDTH, Size.Y);
     }
 }
Beispiel #10
0
 /// <summary>
 /// Настройва текста да се вписва
 /// </summary>
 /// <param name="text"></param>
 private void CreateDrawables(string text)
 {
     drawText = new Text(text, font, 12);
     drawText.Color = foreground;
     FloatRect localBounds = drawText.GetLocalBounds();
     box.Width = (int)localBounds.Width + 10;
     box.Height = (int)localBounds.Height + 6;
 }
Beispiel #11
0
        public void Initialize()
        {
            //To override any of the following, change the variable after calling this function in the constructor
            goldfish = new Font("./assets/goldfish.ttf");
            goldfish.GetTexture(8).Smooth = false;
            nameText = new Text(name, goldfish, 9);
            nameText.Color = Color.Black;
            nameText.Position = new Vector2f(position.X - ((nameText.GetLocalBounds().Width / 4) + 8), position.Y + 17);
            nameText.Style = Text.Styles.Regular;
            healthbarOuter = new RectangleShape(new Vector2f(nameText.GetLocalBounds().Width + 5, nameText.GetLocalBounds().Height + 3));
            healthbar = new RectangleShape(healthbarOuter);
            healthbar.Size = new Vector2f(healthbarOuter.Size.X - 2, healthbarOuter.Size.Y - 2);
            fullHealthPixels = (int)healthbar.Size.X;
            healthbar.FillColor = new Color(153, 255, 153, 170);
            healthbarOuter.FillColor = new Color(0, 0, 0, 120);
            
            orientation = Direction.Down;
            isMoving = false;

            activeWeapon = new Weapon();

            walkingUp = new Animation();
            walkingUp.addFrame(new IntRect(0, 0, 16, 18));
            walkingUp.addFrame(new IntRect(16, 0, 16, 18));
            walkingUp.addFrame(new IntRect(32, 0, 16, 18));

            walkingRight = new Animation();
            walkingRight.addFrame(new IntRect(0, 18, 16, 18));
            walkingRight.addFrame(new IntRect(16, 18, 16, 18));
            walkingRight.addFrame(new IntRect(32, 18, 16, 18));

            walkingDown = new Animation();
            walkingDown.addFrame(new IntRect(0, 18 * 2, 16, 18));
            walkingDown.addFrame(new IntRect(16, 18 * 2, 16, 18));
            walkingDown.addFrame(new IntRect(32, 18 * 2, 16, 18));

            walkingLeft = new Animation();
            walkingLeft.addFrame(new IntRect(0, 18 * 3, 16, 18));
            walkingLeft.addFrame(new IntRect(16, 18 * 3, 16, 18));
            walkingLeft.addFrame(new IntRect(32, 18 * 3, 16, 18));

            boundingbox = new IntRect((int)position.X, (int)position.Y, 16, 16);
        }
Beispiel #12
0
        public UnitCell(Cell targetCell, Cell sourceCell, int units, PlayerInstance player)
        {
            TargetCell = targetCell;
            SourceCell = sourceCell;
            Units = UnitsLeft = units;
            _currentVelocity = Velocity;

            string colorName = null;
            if (SourceCell.Player.Color.R == 255 && SourceCell.Player.Color.G == 0 && SourceCell.Player.Color.B == 0)
            {
                colorName = "red";
            }
            else if (SourceCell.Player.Color.R == 0 && SourceCell.Player.Color.G == 255 && SourceCell.Player.Color.B == 0)
            {
                colorName = "green";
            }
            else if (SourceCell.Player.Color.R == 0 && SourceCell.Player.Color.G == 0
                     && SourceCell.Player.Color.B == 255)
            {
                colorName = "blue";
            }

            _sprite = new Sprite(ResourceManager.Instance["game/unit_cell_" + colorName] as Texture);

            _text = new Text(units.ToString(), ResourceManager.Instance["fonts/verdana"] as Font, FontSize);
            _text.Origin = new Vector2f(
                _text.GetLocalBounds().Left + _text.GetLocalBounds().Width / 2,
                _text.GetLocalBounds().Top);

            _particleSystem = new ParticleSystem(ResourceManager.Instance["game/particle"] as Texture);

            var scale = 0.5f + Units * 0.0125f;
            if (scale >= 1f)
            {
                scale = 1f;
            }

            Scale = _initialScale = new Vector2f(scale, scale);

            Radius = _sprite.GetGlobalBounds().Height / 2;
            _sprite.Origin = new Vector2f(_sprite.GetLocalBounds().Width / 2, _sprite.GetLocalBounds().Height / 2);
            SourcePlayer = player;
        }
        public SelectorButton(SelectorPannel parent, Types type, Vector2f offset, Vector2f dimensions, string name, Color c, Texture t = null)
        {
            this.parent = parent;
            this.Type = type;
            this.offset = offset;
            this.positionBox = new Rectangle(parent.PositionBox.x + offset.X, parent.PositionBox.y + offset.Y, dimensions.X, dimensions.Y);
            updateBlockParamers();
            this.text = new Text(name, Game1.plainFont);
            text.Color = Color.Black;
            text.CharacterSize = 24;
            text.Origin = new Vector2f(text.GetLocalBounds().Left, text.GetLocalBounds().Top);
            setTextPosition();

            this.outlineLight = new Color(255, 255, 255, 0);
            this.outlineDark = new Color(parent.Color.R, parent.Color.G, parent.Color.B, 220);
            this.currentOutline = outlineDark;
            this.drawColor = c;
            if (t != null)
                sprite = new Sprite(t);
        }
Beispiel #14
0
        public static void drawString(Font font, String message, Vector2f position, Color color, float scale, bool centered)
        {
            Text text = new Text(message, font);
            text.Scale = new Vector2f(scale, scale);
            text.Position = position;// clientPlayer.position;
            text.Color = color;
            if (centered)
                text.Position = new Vector2f(text.Position.X - ((text.GetLocalBounds().Width * scale) / 2), text.Position.Y);

            Game.window.Draw(text);
        }
Beispiel #15
0
        public SplashScreenState()
        {
            //Create the orb
            splashSprite = new Sprite(new Texture("Assets/Textures/splashOrb.png") { Smooth = true });
            splashSprite.Color = renderColor;
            splashSprite.Origin = splashSprite.Texture.Center();
            splashSprite.Position = new SFML.System.Vector2f(Program.Window.Size.X / 2, (Program.Window.Size.Y / 5) * 3);

            //Create the title label
            titleText = new Text("ORBS", new Font("Assets/Fonts/Base.ttf"), 140);
            titleText.Color = renderColor;
            titleText.Position = new Vector2f(Program.Window.Size.X / 2 - titleText.GetLocalBounds().Width / 2, 100);
        }
Beispiel #16
0
 protected override void SetupButtonAdditional(int i, DisplayObject button, RectangleShape button_back, bool pickable)
 {
     // current level
     Text currentLevel = new Text("", Game.TidyHand, 45);
     if (pickable)
         currentLevel.DisplayedString = Game.Player.GetUpgradeValue(i, Game.Player.UpgradeLevels[i]) + " -> " + Game.Player.GetUpgradeValue(i, Game.Player.UpgradeLevels[i] + 1);
     else
         currentLevel.DisplayedString = Game.Player.GetUpgradeValue(i, Game.Player.UpgradeLevels[i]) + " (MAX)";
     FloatRect currentLevelRect = currentLevel.GetLocalBounds();
     currentLevel.Origin = new Vector2f(currentLevelRect.Width / 2.0f, 0);
     currentLevel.Position = new Vector2f(button_back.Size.X / 2, 120);
     currentLevel.Color = new Color(255, 255, 255, (byte)(pickable ? 255 : 120));
     button.AddChild(currentLevel);
 }
Beispiel #17
0
        public MainMenuState()
        {
            Font menuFont = new Font("Assets/Fonts/Base.ttf");

            title = new Text("ORBS", menuFont, 140);
            title.Color = new Color(200, 200, 255);
            title.Position = new SFML.System.Vector2f(Program.Window.Size.X / 2 - title.GetLocalBounds().Width / 2, 100);

            List<Tuple<String,Action>> items = new List<Tuple<String, Action>>();
            items.Add(new Tuple<string, Action>("Play",     () => { Program.StateManager.EnterState(new ExploringState()); }    ));
            items.Add(new Tuple<string, Action>("Options",  () => { Program.IsFpsRendering = !Program.IsFpsRendering; }         ));
            items.Add(new Tuple<string, Action>("Help",     () => { }                                                           ));
            items.Add(new Tuple<string, Action>("Credits",  () => { Program.StateManager.LeaveCurrentState(); }                 ));
            items.Add(new Tuple<string, Action>("Exit",     () => { Program.Window.Close(); }                                   ));

            menu = new Menu(items, menuFont, 60, new Vector2f(Program.Window.Size.X / 2, 350),700);
        }
Beispiel #18
0
 public TextBox(WindowManager _WM, int _X, int _Y, int _SizeX,int _SizeY,bool _AllowInput)
     : base(_WM, _X, _Y, _SizeX, _SizeY)
 {
     localx = _X;
     localy = _Y;
     AllowInput = _AllowInput;
     BoxText = new Text("", _WM.font,15);
     BackPlate = new RectangleShape();
     Cursor = new RectangleShape();
     Cursor.Size = new Vector2f(1, BoxText.GetLocalBounds().Height*2);
     Cursor.FillColor = Color.Green;
     //BoxText.Position = new Vector2f(_X, _Y);
     SetSize(_SizeX, 15*_SizeY);
     BackPlate.Size = new Vector2f(BoundingBox.Width, BoundingBox.Height);
     //BackPlate.Position = new Vector2f(BoxText.GetLocalBounds().Left, BoxText.GetLocalBounds().Top);
     //BackPlate.Size = new Vector2f((int)BoxText.GetGlobalBounds().Width, (int)BoxText.GetGlobalBounds().Height * 2);
     BackPlate.FillColor = Color.Magenta;
 }
Beispiel #19
0
        public MessageFade(Game game, string msg, uint fontSize, Vector2f position, Action callBack = null, double showTime = 1500, bool center = true)
            : base(game)
        {
            Text = new Text(msg, Game.TidyHand, fontSize);
            Text.Color = new Color(255, 255, 255, 0);
            FloatRect textRect = Text.GetLocalBounds();
            if (center)
                Text.Origin = new Vector2f(textRect.Left + textRect.Width / 2.0f, textRect.Top + textRect.Height / 2.0f);

            AddChild(Text);
            Position = position;

            ShowTimer = new Timer(showTime);
            ShowTimer.AutoReset = false;
            ShowTimer.Elapsed += ShowTimerHandler;

            CallBack = callBack;
        }
        public TitleState(StateStack stack, Context context)
            : base(stack, context)
        {

            mTextEffectTime = Time.Zero;
            mShowText = true;

            mText = new Text();
            mText.Font = mContext.fonts.get(FontID.Main);
            mText.DisplayedString = "Press any key to start";
            //sets origin to center
            FloatRect bounds = mText.GetLocalBounds();
            mText.centerOrigin();
            mText.Position = mContext.window.getCenter();



            mBackgroundSprite = new Sprite(mContext.textures.get(ResourceID.TitleScreen));

        }
Beispiel #21
0
        public void Draw(RenderWindow win)
        {
            int k = 10;
            text = new Text(time, font);
            text.Color = new Color(Color.Red);
            text.Position = new Vector2f(view.Center.X - view.Size.X / 2 + k, view.Center.Y - view.Size.Y / 2 + k);
            win.Draw(text);

            text = new Text(score, font);
            text.Color = new Color(Color.Red);
            text.Position = new Vector2f(view.Center.X, view.Center.Y - view.Size.Y / 2 + k);
            win.Draw(text);

            text = new Text(position, font);

            text.Color = new Color(Color.Red);
            text.Position = new Vector2f(view.Center.X + view.Size.X / 2 - k - text.GetLocalBounds().Width , view.Center.Y - view.Size.Y / 2 + k);
            win.Draw(text);
               // Console.WriteLine(text.Position.ToString());
        }
        private Text createText(PVector position, char[] chars)
        {
            string text = new string(chars);

            Text textObj = new Text(text, defaultFont);

            textObj.Position         = toVector2f(position);
            textObj.OutlineColor     = toColor(strokeColor);
            textObj.OutlineThickness = strokeWeight;
            textObj.FillColor        = toColor(fillColor);
            textObj.CharacterSize    = (uint)textSize;
            textObj.LineSpacing      = textLeading / textSize;
            textObj.Rotation         = Helpers.ConvertionHelper.RadiansToDegrees(transformation.Angle);

            FloatRect textBox = textObj.GetLocalBounds();

            textObj.Origin = getTextOrigin(textBox);

            return(textObj);
        }
Beispiel #23
0
        public HowToPlay(Game game)
            : base(game)
        {
            // Background
            Sprite BluePrintBackground = Graphics.GetSprite("assets/sprites/background_blueprint_tile.png");
            BluePrintBackground.Texture.Repeated = true;
            BluePrintBackground.TextureRect = new IntRect(0, 0, (int)Game.Size.X, (int)Game.Size.Y);
            AddChild(BluePrintBackground);

            // help
            Text help = new Text("(tap to continue)", Game.TidyHand, 30);
            FloatRect textRect = help.GetLocalBounds();
            help.Origin = new Vector2f(textRect.Left + textRect.Width / 2.0f, textRect.Top + textRect.Height / 2.0f);
            help.Position = new Vector2f(Game.Size.X / 2, Game.Size.Y - 25);
            AddChild(help);

            Tutorial = Graphics.GetAnimatedSprite(Game, Graphics.ASSETS_SPRITES + "gui/HowToPlay.xml");
            Tutorial.Sprite.Texture.Smooth = false;
            Tutorial.Stop();
            Tutorial.SetFrame(0);
            AddChild(Tutorial);
        }
Beispiel #24
0
        public GameOverGUI(Game game)
            : base(game)
        {
            RectangleShape dim = new RectangleShape(new Vector2f(Game.Size.X, Game.Size.Y));
            dim.FillColor = new Color(0, 0, 0, 100);
            AddChild(dim);

            RectangleShape back = new RectangleShape(new Vector2f(Game.Size.X, 490));
            back.FillColor = new Color(0, 0, 0, 100);
            back.Position = new Vector2f(0, Game.Size.Y / 2 - (back.Size.Y/2));
            AddChild(back);

            FloatRect textRect;

            Text gameOver = new Text("Game Over", Game.TidyHand, 120);
            textRect = gameOver.GetLocalBounds();
            gameOver.Origin = new Vector2f(textRect.Left + textRect.Width / 2.0f, textRect.Top  + textRect.Height/2.0f);
            gameOver.Position = new Vector2f(Game.Size.X/2, Game.Size.Y/2 - 190);
            AddChild(gameOver);

            Text msg = new Text("Press any key to retry.", Game.TidyHand, 35);
            textRect = msg.GetLocalBounds();
            msg.Origin = new Vector2f(textRect.Left + textRect.Width / 2.0f, textRect.Top + textRect.Height / 2.0f);
            msg.Position = new Vector2f(Game.Size.X / 2, Game.Size.Y / 2 - 100);
            AddChild(msg);

            Text finalScore = new Text("Final Score", Game.TidyHand, 60);
            textRect = finalScore.GetLocalBounds();
            finalScore.Origin = new Vector2f(textRect.Left + textRect.Width / 2.0f, textRect.Top + textRect.Height / 2.0f);
            finalScore.Position = new Vector2f(Game.Size.X / 2, Game.Size.Y / 2 + 120);
            AddChild(finalScore);

            Text score = new Text(Game.Player.GetScore().ToString("00000000"), Game.TidyHand, 50);
            textRect = score.GetLocalBounds();
            score.Origin = new Vector2f(textRect.Left + textRect.Width / 2.0f, textRect.Top + textRect.Height / 2.0f);
            score.Position = new Vector2f(Game.Size.X / 2, Game.Size.Y / 2 + 180);
            AddChild(score);
        }
Beispiel #25
0
        /// <summary>
        /// Draws a string.
        /// </summary>
        public void DrawString(Text str, Color color )
        {
            Vector2f oldPos = str.Position;
            str.Position = oldPos +Translation;
            str.Position -= new Vector2f( str.GetLocalBounds().Left, str.GetLocalBounds().Top );

            Color oldCol = str.Color;
            str.Color = ActualColor(color);

            str.Draw(myTarget, RenderStates.Default);

            str.Color = oldCol;
            str.Position = oldPos;
        }
Beispiel #26
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Recalculates the position of the texts
        /// </summary>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void RecalculateTextPositions()
        {
            float textX = Position.X;
            float textY = Position.Y;

            // Calculate the scaling
            Vector2f scaling = new Vector2f(m_Size.X / m_TextureNormal_M.Size.X, m_Size.Y / m_TextureNormal_M.Size.Y);

            // Calculate the scale of the left and right border
            float borderScale;
            if (m_SplitImage)
                borderScale = scaling.Y;
            else
                borderScale = scaling.X;

            textX += m_Borders.Left * borderScale - m_TextCropPosition;
            textY += m_Borders.Top * scaling.Y;

            // Check if the layout wasn't left
            if (m_TextAlignment != Alignment.Left)
            {
                // Calculate the space inside the edit box
                float width = m_Size.X - ((m_Borders.Left + m_Borders.Right) * borderScale);

                // Calculate the text width
                float textWidth = m_TextFull.FindCharacterPos((uint)m_DisplayedText.Length).X;

                // Check if a layout would make sense
                if (textWidth < width)
                {
                    // Put the text on the correct position
                    if (m_TextAlignment == Alignment.Center)
                        textX += (width - textWidth) / 2.0f;
                    else // if (textAlignment == Alignment::Right)
                        textX += width - textWidth;
                }
            }

            float selectionPointLeft = textX;

            // Set the position of the text
            Text tempText = new Text(m_TextFull);
            tempText.DisplayedString = "kg";
            textY += (((m_Size.Y - ((m_Borders.Top + m_Borders.Bottom) * scaling.Y)) - tempText.GetLocalBounds().Height) * 0.5f) - tempText.GetLocalBounds().Top;

            // Set the text before the selection on the correct position
            m_TextBeforeSelection.Position = new Vector2f((float)System.Math.Floor(textX + 0.5), (float)System.Math.Floor(textY + 0.5));

            // Check if there is a selection
            if (m_SelChars != 0)
            {
                // Watch out for the kerning
                if (m_TextBeforeSelection.DisplayedString.Length > 0)
                    textX += m_TextBeforeSelection.Font.GetKerning(m_DisplayedText[m_TextBeforeSelection.DisplayedString.Length - 1], m_DisplayedText[m_TextBeforeSelection.DisplayedString.Length], m_TextBeforeSelection.CharacterSize);

                textX += m_TextBeforeSelection.FindCharacterPos((uint)m_TextBeforeSelection.DisplayedString.Length).X;

                // Set the position and size of the rectangle that gets drawn behind the selected text
                m_SelectedTextBackground.Size = new Vector2f(m_TextSelection.FindCharacterPos((uint)m_TextSelection.DisplayedString.Length).X,
                                                             (m_Size.Y - ((m_Borders.Top + m_Borders.Bottom) * scaling.Y)));
                m_SelectedTextBackground.Position = new Vector2f((float)System.Math.Floor(textX + 0.5f), (float)System.Math.Floor(Position.Y + (m_Borders.Top * scaling.Y) + 0.5f));

                // Set the text selected text on the correct position
                m_TextSelection.Position = new Vector2f((float)System.Math.Floor(textX + 0.5), (float)System.Math.Floor(textY + 0.5));

                // Watch out for kerning
                if (m_DisplayedText.Length > m_TextBeforeSelection.DisplayedString.Length + m_TextSelection.DisplayedString.Length)
                    textX += m_TextBeforeSelection.Font.GetKerning(m_DisplayedText[m_TextBeforeSelection.DisplayedString.Length + m_TextSelection.DisplayedString.Length - 1], m_DisplayedText[m_TextBeforeSelection.DisplayedString.Length + m_TextSelection.DisplayedString.Length], m_TextBeforeSelection.CharacterSize);

                // Set the text selected text on the correct position
                textX += m_TextSelection.FindCharacterPos((uint)m_TextSelection.DisplayedString.Length).X;
                m_TextAfterSelection.Position = new Vector2f((float)System.Math.Floor(textX + 0.5), (float)System.Math.Floor(textY + 0.5));
            }

            // Set the position of the selection point
            selectionPointLeft += m_TextFull.FindCharacterPos(m_SelEnd).X - (m_SelectionPoint.Size.X / 2.0f);
            m_SelectionPoint.Position = new Vector2f((float)System.Math.Floor(selectionPointLeft + 0.5), (float)System.Math.Floor((m_Borders.Top * scaling.Y) + Position.Y + 0.5));
        }
Beispiel #27
0
 public override void Init()
 {
     label = new Text(Text, Font);
     label.Scale = new SFML.Window.Vector2f(Scale, Scale);
     var bounds = label.GetLocalBounds();
     Height = (int)bounds.Height;
     Width = (int)bounds.Width;
     base.Init();
 }
Beispiel #28
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Adds a new menu item
        /// </summary>
        ///
        /// <param name="menuText">The name of the menu to which the menu item will be added</param>
        /// <param name="text">The text written on this menu item</param>
        ///
        /// <returns>True when the item was added, false when \a menu was not found</returns>
        ///
        /// Usage example:
        /// <code>
        /// menuBar.AddMenu("File");
        /// menuBar.AddMenuItem("File", "Load");
        /// menuBar.AddMenuItem("File", "Save");
        /// </code>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public bool AddMenuItem(string menuText, string text)
        {
            // Search for the menu
            foreach (Menu menu in m_Menus)
            {
                // If this is the menu then add the menu item to it
                if (menu.text.DisplayedString == menuText)
                {
                    Text menuItem = new Text (text, m_TextFont);
                    menuItem.Color = m_TextColor;
                    menuItem.CharacterSize = m_TextSize;
                    menuItem.CharacterSize = (uint)(menuItem.CharacterSize - menuItem.GetLocalBounds().Top);

                    menu.menuItems.Add (menuItem);
                    return true;
                }
            }

            // Couldn't find the menu
            return false;
        }
Beispiel #29
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Draws the widget on the render target
        /// </summary>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public override void Draw(RenderTarget target, RenderStates states)
        {
            // Get the old clipping area
            int[] scissor = new int[4];
            Gl.glGetIntegerv(Gl.GL_SCISSOR_BOX, scissor);

            // 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;

            // Apply the transformations
            states.Transform *= Transform;

            float scalingY = m_TabHeight / (float)(m_TextureNormal_M.Size.Y);
            bool clippingRequired = false;
            uint tabWidth;
            FloatRect realRect;
            FloatRect defaultRect;
            Text tempText = new Text(m_Text);

            // Calculate the height and top of all strings
            tempText.DisplayedString = "kg";
            defaultRect = tempText.GetLocalBounds();

            // Loop through all tabs
            for (int i = 0; i < m_TabNames.Count; ++i)
            {
                // Find the tab height
                if (m_MaximumTabWidth != 0)
                {
                    if (m_MaximumTabWidth < m_NameWidth[i] + (2 * m_DistanceToSide))
                    {
                        tabWidth = m_MaximumTabWidth;
                        clippingRequired = true;
                    }
                    else
                        tabWidth = (uint)(m_NameWidth[i] + (2 * m_DistanceToSide));
                }
                else
                    tabWidth = (uint)(m_NameWidth[i] + (2 * m_DistanceToSide));

                // There is a minimum tab width
                if (tabWidth < 2 * m_DistanceToSide)
                    tabWidth = 2 * m_DistanceToSide;

                // Check if the image is split
                if (m_SplitImage)
                {
                    // There is another minimum when using SplitImage
                    float minimumWidth = (m_TextureNormal_L.Size.X + m_TextureNormal_R.Size.X) * scalingY;
                    if (tabWidth < minimumWidth)
                        tabWidth = (uint)(minimumWidth);

                    // Set the scaling
                    states.Transform.Scale(scalingY, scalingY);

                    // Draw the left tab image
                    if (m_SeparateSelectedImage)
                    {
                        if ((m_SelectedTab == i) && ((m_WidgetPhase & (byte)WidgetPhase.Selected) != 0))
                            target.Draw(m_TextureSelected_L.sprite, states);
                        else
                            target.Draw(m_TextureNormal_L.sprite, states);
                    }
                    else // There is no separate selected image
                    {
                        target.Draw(m_TextureNormal_L.sprite, states);

                        if ((m_SelectedTab == i) && ((m_WidgetPhase & (byte)WidgetPhase.Selected) != 0))
                            target.Draw(m_TextureSelected_L.sprite, states);
                    }

                    // Check if the middle image may be drawn
                    if ((scalingY * (m_TextureNormal_L.Size.X + m_TextureNormal_R.Size.X)) < tabWidth)
                    {
                        // Calculate the scale for our middle image
                        float scaleX = (tabWidth / (float)(m_TextureNormal_M.Size.X)) - (((m_TextureNormal_L.Size.X + m_TextureNormal_R.Size.X) * scalingY) / m_TextureNormal_M.Size.X);

                        // Put the middle image on the correct position
                        states.Transform.Translate((float)(m_TextureNormal_L.Size.X), 0);

                        // Set the scale for the middle image
                        states.Transform.Scale(scaleX / scalingY, 1);

                        // Draw the middle tab image
                        if (m_SeparateSelectedImage)
                        {
                            if ((m_SelectedTab == i) && ((m_WidgetPhase & (byte)WidgetPhase.Selected) != 0))
                                target.Draw(m_TextureSelected_M.sprite, states);
                            else
                                target.Draw(m_TextureNormal_M.sprite, states);
                        }
                        else // There is no separate selected image
                        {
                            target.Draw(m_TextureNormal_M.sprite, states);

                            if ((m_SelectedTab == i) && ((m_WidgetPhase & (byte)WidgetPhase.Selected) != 0))
                                target.Draw(m_TextureSelected_M.sprite, states);
                        }

                        // Put the right image on the correct position
                        states.Transform.Translate((float)(m_TextureNormal_M.Size.X), 0);

                        // Set the scale for the right image
                        states.Transform.Scale(scalingY / scaleX, 1);

                        // Draw the right tab image
                        if (m_SeparateSelectedImage)
                        {
                            if ((m_SelectedTab == i) && ((m_WidgetPhase & (byte)WidgetPhase.Selected) != 0))
                                target.Draw(m_TextureSelected_R.sprite, states);
                            else
                                target.Draw(m_TextureNormal_R.sprite, states);
                        }
                        else // There is no separate selected image
                        {
                            target.Draw(m_TextureNormal_R.sprite, states);

                            if ((m_SelectedTab == i) && ((m_WidgetPhase & (byte)WidgetPhase.Selected) != 0))
                                target.Draw(m_TextureSelected_R.sprite, states);
                        }

                        // Undo the translation
                        states.Transform.Translate(-(m_TextureNormal_L.Size.X + (m_TextureNormal_M.Size.X * scaleX / scalingY)), 0);
                    }
                    else // The edit box isn't width enough, we will draw it at minimum size
                    {
                        // Put the right image on the correct position
                        states.Transform.Translate((float)(m_TextureNormal_L.Size.X), 0);

                        // Draw the right tab image
                        if (m_SeparateSelectedImage)
                        {
                            if ((m_SelectedTab == i) && ((m_WidgetPhase & (byte)WidgetPhase.Selected) != 0))
                                target.Draw(m_TextureSelected_R.sprite, states);
                            else
                                target.Draw(m_TextureNormal_R.sprite, states);
                        }
                        else // There is no separate selected image
                        {
                            target.Draw(m_TextureNormal_R.sprite, states);

                            if ((m_SelectedTab == i) && ((m_WidgetPhase & (byte)WidgetPhase.Selected) != 0))
                                target.Draw(m_TextureSelected_R.sprite, states);
                        }

                        // Undo the translation
                        states.Transform.Translate(-(float)(m_TextureNormal_L.Size.X), 0);
                    }

                    // Undo the scaling of the split images
                    states.Transform.Scale(1.0f / scalingY, 1.0f / scalingY);
                }
                else // The image isn't split
                {
                    // Set the scaling
                    states.Transform.Scale(tabWidth / (float)(m_TextureNormal_M.Size.X), scalingY);

                    // Draw the tab image
                    if (m_SeparateSelectedImage)
                    {
                        if ((m_SelectedTab == i) && ((m_WidgetPhase & (byte)WidgetPhase.Selected) != 0))
                            target.Draw(m_TextureSelected_M.sprite, states);
                        else
                            target.Draw(m_TextureNormal_M.sprite, states);
                    }
                    else // There is no separate selected image
                    {
                        target.Draw(m_TextureNormal_M.sprite, states);

                        if ((m_SelectedTab == i) && ((m_WidgetPhase & (byte)WidgetPhase.Selected) != 0))
                            target.Draw(m_TextureSelected_M.sprite, states);
                    }

                    // Undo the scaling
                    states.Transform.Scale((float)(m_TextureNormal_M.Size.X) / tabWidth, 1.0f / scalingY);
                }

                // Draw the text
                {
                    // Give the text the correct color
                    if (m_SelectedTab == i)
                        tempText.Color = m_SelectedTextColor;
                    else
                        tempText.Color = m_TextColor;

                    // Get the current size of the text, so that we can recalculate the position
                    tempText.DisplayedString = m_TabNames [i];
                    realRect = tempText.GetLocalBounds();

                    // Calculate the new position for the text
                    if ((m_SplitImage) && (tabWidth == (m_TextureNormal_L.Size.X + m_TextureNormal_R.Size.X) * scalingY))
                        realRect.Left = ((tabWidth - realRect.Width) / 2.0f) - realRect.Left;
                    else
                        realRect.Left = m_DistanceToSide - realRect.Left;
                    realRect.Top = ((m_TabHeight - defaultRect.Height) / 2.0f) - defaultRect.Top;

                    // Move the text to the correct position
                    states.Transform.Translate((float)System.Math.Floor(realRect.Left + 0.5), (float)System.Math.Floor(realRect.Top + 0.5));

                    // Check if clipping is required for this text
                    if (clippingRequired)
                    {
                        // Get the global position
                        Vector2f topLeftPosition = states.Transform.TransformPoint((target.GetView().Size / 2.0f) - target.GetView().Center);
                        Vector2f bottomRightPosition = states.Transform.TransformPoint(new Vector2f(tabWidth - (2 * m_DistanceToSide), (m_TabHeight + defaultRect.Height) / 2.0f) - target.GetView().Center + (target.GetView().Size / 2.0f));

                        // 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;

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

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

                    // Undo the translation of the text
                    states.Transform.Translate(-(float)System.Math.Floor(realRect.Left + 0.5f), -(float)System.Math.Floor(realRect.Top + 0.5f));

                    // Reset the old clipping area when needed
                    if (clippingRequired)
                    {
                        clippingRequired = false;
                        Gl.glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
                    }
                }

                // Set the next tab on the correct position
                states.Transform.Translate((float)(tabWidth), 0);
            }
        }
        public override void Draw(RenderTarget rt)
        {
            // Draw header
            rt.Draw(new RectangleShape(new Vector2f(GameOptions.Width, 350.0f)) { FillColor = Color.Black });

            // GameOptions.Width / 6.0f
            Sprite logoSprite = new Sprite(Assets.LoadTexture("Logo.png"))
            {
                Position = new Vector2f(128.0f, (350.0f - 256.0f) / 2.0f)
            };

            rt.Draw(logoSprite);

            Text sloganText = new Text("A free party game for\n" + personValue, Assets.LoadFont(Program.DefaultFont))
            {
                Position = new Vector2f(128.0f, (350 - 256) / 2.0f + 189.0f),
                Color = Color.White,
                CharacterSize = 26,
                Style = Text.Styles.Bold
            };

            sloganText.Round();
            rt.Draw(sloganText);

            // Draw version and anti-sue-hammer strings
            Text versionText = new Text("Version " + Program.Version, Assets.LoadFont(Program.DefaultFont))
            {
                Position = new Vector2f(GameOptions.Width - 16.0f, GameOptions.Height - 32.0f),
                CharacterSize = 16,
                Color = Color.Black
            };

            versionText.Position -= new Vector2f(versionText.GetLocalBounds().Width, 0.0f);

            versionText.Round();
            rt.Draw(versionText);

            Text originalText = new Text("A shameless rip-off of \"Cards Against Humanity\".", Assets.LoadFont(Program.DefaultFont))
            {
                Position = new Vector2f(16.0f, GameOptions.Height - 32.0f),
                CharacterSize = 16,
                Color = Color.Black
            };

            originalText.Round();
            rt.Draw(originalText);

            base.Draw(rt);
        }
Beispiel #31
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;

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

            // Get the global position
            Vector2f topLeftPosition = states.Transform.TransformPoint(Position + viewPosition);
            Vector2f bottomRightPosition = states.Transform.TransformPoint(Position.X + m_ListBox.Size.X - (m_TextureArrowDownNormal.Size.X * ((float)(m_ListBox.ItemHeight) / m_TextureArrowDownNormal.Size.Y)) + viewPosition.X,
                                                                           Position.Y + m_ListBox.Size.Y + viewPosition.Y);

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

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

            // Draw left border
            RectangleShape border = new RectangleShape(new Vector2f(m_Borders.Left, m_ListBox.ItemHeight + m_Borders.Top));
            border.Position = new Vector2f(-(float)m_Borders.Left, -(float)m_Borders.Top);
            border.FillColor = m_ListBox.BorderColor;
            target.Draw(border, states);

            // Draw top border
            border.Size = new Vector2f(m_ListBox.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_ListBox.ItemHeight + m_Borders.Bottom);
            border.Position = new Vector2f(m_ListBox.Size.X, 0);
            target.Draw(border, states);

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

            // Draw the combo box
            RectangleShape front = new RectangleShape (new Vector2f((float)(m_ListBox.Size.X), (float)(m_ListBox.ItemHeight)));
            front.FillColor = m_ListBox.BackgroundColor;
            target.Draw(front, states);

            // Create a text widget to draw it
            Text tempText = new Text("kg", m_ListBox.TextFont);
            tempText.CharacterSize = m_ListBox.ItemHeight;
            tempText.CharacterSize = (uint)(tempText.CharacterSize - tempText.GetLocalBounds().Top);
            tempText.Color = m_ListBox.TextColor;

            // 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;

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

            // Draw the selected item
            states.Transform.Translate(2, (float)System.Math.Floor((m_ListBox.ItemHeight - tempText.GetLocalBounds().Height) / 2.0f -  tempText.GetLocalBounds().Top));
            tempText.DisplayedString = m_ListBox.GetSelectedItem();
            target.Draw(tempText, states);

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

            // Reset the transformations
            states.Transform = oldTransform;

            // Set the arrow like it should (down when list box is invisible, up when it is visible)
            if (m_ListBox.Visible)
            {
                float scaleFactor =  (float)(m_ListBox.ItemHeight) / m_TextureArrowUpNormal.Size.Y;
                states.Transform.Translate(m_ListBox.Size.X - m_TextureArrowUpNormal.Size.X * scaleFactor, 0);
                states.Transform.Scale(scaleFactor, scaleFactor);

                // Draw the arrow
                if (m_SeparateHoverImage)
                {
                    if ((m_MouseHover) && ((m_WidgetPhase & (byte)WidgetPhase.Hover) != 0))
                        target.Draw(m_TextureArrowUpHover.sprite, states);
                    else
                        target.Draw(m_TextureArrowUpNormal.sprite, states);
                }
                else // There is no separate hover image
                {
                    target.Draw(m_TextureArrowUpNormal.sprite, states);

                    if ((m_MouseHover) && ((m_WidgetPhase & (byte)WidgetPhase.Focused) != 0))
                        target.Draw(m_TextureArrowUpHover.sprite, states);
                }
            }
            else
            {
                float scaleFactor =  (float)(m_ListBox.ItemHeight) / m_TextureArrowDownNormal.Size.Y;
                states.Transform.Translate(m_ListBox.Size.X - m_TextureArrowDownNormal.Size.X * scaleFactor, 0);
                states.Transform.Scale(scaleFactor, scaleFactor);

                // Draw the arrow
                if (m_SeparateHoverImage)
                {
                    if ((m_MouseHover) && ((m_WidgetPhase & (byte)WidgetPhase.Hover) != 0))
                        target.Draw(m_TextureArrowDownHover.sprite, states);
                    else
                        target.Draw(m_TextureArrowDownNormal.sprite, states);
                }
                else // There is no separate hover image
                {
                    target.Draw(m_TextureArrowDownNormal.sprite, states);

                    if ((m_MouseHover) && ((m_WidgetPhase & (byte)WidgetPhase.Hover) != 0))
                        target.Draw(m_TextureArrowDownHover.sprite, states);
                }
            }
        }
Beispiel #32
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();
            }
        }
Beispiel #33
0
        protected override void Setup()
        {
            Title = "";
            ButtonNames = new List<string>()
            {
                "Play",
                "How to Play",
                "Exit",
            };
            StripWidth = Game.Size.X;
            StartY = 800;
            ButtonDescriptions = new List<string>() { };
            ButtonHeight = 75;
            ButtonGap = 150;
            HelpY = 750;

            // Background
            if (Game.GraphicsMode == Game.GRAPHICSMODE_NORMAL)
            {
                Graphics.GetSprite("assets/sprites/background_blueprint_tile.png");
                RectangleShape Water = new RectangleShape(new Vector2f(Game.Size.X, Game.Size.Y));
                Water.FillColor = new Color(40, 118, 188);
                AddChild(Water);

                WaterRipples WaterRipplesBelow = new WaterRipples(Game, new Vector2f(Game.Size.X + 40, Game.Size.Y + 40), 120, 10, new Color(68, 131, 186));
                WaterRipplesBelow.Position = new Vector2f(-40, -40);
                AddChild(WaterRipplesBelow);

                WaterRipples WaterRipples = new WaterRipples(Game, new Vector2f(Game.Size.X, Game.Size.Y), 120, 10, new Color(80, 158, 228));
                AddChild(WaterRipples);

                //VoronoiDiagram WaterEffect = new VoronoiDiagram(this, new Vector2f(Size.X, Size.Y));
                //Layer_Background.AddChild(WaterEffect);
            }
            else if (Game.GraphicsMode == Game.GRAPHICSMODE_BLUEPRINT)
            {
                Sprite BluePrintBackground = Graphics.GetSprite("assets/sprites/background_blueprint_tile.png");
                BluePrintBackground.Texture.Repeated = true;
                BluePrintBackground.TextureRect = new IntRect(0, 0, (int)Game.Size.X, (int)Game.Size.Y);
                AddChild(BluePrintBackground);
            }
            Game.Resume();

            base.Setup();
            RemoveChild(Back);
            RemoveChild(Dim);

            // Title
            Sprite title = Graphics.GetSprite(Graphics.ASSETS_SPRITES + "gui/Title_Cannon_Island_Defence.png");
            FloatRect titleRect = title.GetLocalBounds();
            title.Position = new Vector2f((Game.Size.X - titleRect.Width) / 2, 100);
            AddChild(title);

            // Credits
            RectangleShape credits_back = new RectangleShape(new Vector2f(Game.Size.X, 40));
            credits_back.Position = new Vector2f(0, Game.Size.Y - 40);
            credits_back.FillColor = new Color(0, 0, 0, 60);
            AddChild(credits_back);

            Text credit_corey = new Text("created by Corey Zeke Womack (torrunt.net)", Game.TidyHand, 24);
            credit_corey.Position = new Vector2f(5, Game.Size.Y - 35);
            AddChild(credit_corey);

            Text credit_music = new Text("music by luigisounds.newgrounds.com", Game.TidyHand, 24);
            FloatRect textRect = credit_music.GetLocalBounds();
            credit_music.Origin = new Vector2f(textRect.Width, 0);
            credit_music.Position = new Vector2f(Game.Size.X - 5, Game.Size.Y - 35);
            AddChild(credit_music);
        }
Beispiel #34
0
        public void UpdatePlayerList()
        {
            var startY = _shape.Position.Y - _shape.GetLocalBounds().Height / 2 + 50;
            var startX = _shape.Position.X - _shape.GetLocalBounds().Width / 2 + 40;

            _players.ForEach(t => t.Dispose());
            _players.Clear();

            _readyMarks.ForEach(t => t.Dispose());
            _readyMarks.Clear();

            float maxLengthPlayer = 0;

            foreach (var player in Game.Instance.AllPlayers.Values)
            {
                var text = new Text(player.Name, ResourceManager.Instance["fonts/bebas_neue"] as Font, 30)
                               {
                                   Position
                                       =
                                       new Vector2f
                                       (
                                       startX,
                                       startY)
                               };

                if (player.Name == Game.Instance.Player.Name)
                {
                    text.Style = Text.Styles.Bold;
                }

                if (player.IsReady)
                {
                    var spriteMark = new Sprite(ResourceManager.Instance["multiplayer/ok"] as Texture)
                                         {
                                             Position =
                                                 new Vector2f
                                                 (
                                                 startX,
                                                 startY
                                                 + text
                                                       .GetLocalBounds
                                                       ()
                                                       .Height
                                                 / 2)
                                         };
                    _readyMarks.Add(spriteMark);
                }

                maxLengthPlayer = Math.Max(maxLengthPlayer, text.GetLocalBounds().Width + text.GetLocalBounds().Left);
                startY += text.GetLocalBounds().Top + text.GetLocalBounds().Height + 35;
                _players.Add(text);
            }

            _readyMarks.ForEach(t => t.Position = new Vector2f(t.Position.X + maxLengthPlayer + 35, t.Position.Y));
        }
        protected virtual void Setup()
        {
            // dim game
            Dim = new RectangleShape(new Vector2f(Game.Size.X, Game.Size.Y));
            Dim.FillColor = new Color(0, 0, 0, 100);
            AddChild(Dim);

            // title
            Text title = new Text(Title, Game.TidyHand, 100);
            FloatRect textRect = title.GetLocalBounds();
            title.Origin = new Vector2f(textRect.Left + textRect.Width / 2.0f, textRect.Top + textRect.Height / 2.0f);
            title.Position = new Vector2f(Game.Size.X / 2, TitleY);
            if (StartY == 0)
                StartY = title.Position.Y + 200;

            // back
            Back = new RectangleShape(new Vector2f(StripWidth == 0 ? textRect.Width + 300 : StripWidth, Game.Size.Y));
            Back.FillColor = new Color(0, 0, 0, 100);
            Back.Position = new Vector2f(title.Position.X - (Back.Size.X / 2), 0);
            AddChild(Back);

            AddChild(title);

            // help
            Text help = new Text("(tap to change selection, hold down to choose)", Game.TidyHand, 28);
            textRect = help.GetLocalBounds();
            help.Origin = new Vector2f(textRect.Left + textRect.Width / 2.0f, textRect.Top + textRect.Height / 2.0f);
            help.Position = new Vector2f(Game.Size.X / 2, HelpY);
            AddChild(help);

            // upgrades
            for (int i = 0; i < ButtonNames.Count; i++)
            {
                bool pickable = IsPickable(i);

                DisplayObject button = new DisplayObject();
                button.Position = new Vector2f(Back.Position.X, StartY + (ButtonGap * i));

                // back
                RectangleShape button_back = new RectangleShape(new Vector2f(Back.Size.X, ButtonHeight));
                button_back.FillColor = new Color(0, 0, 0, (byte)(pickable ? 150 : 50));
                button_back.OutlineThickness = 6;
                button_back.OutlineColor = new Color(0, 0, 0, 0);
                button.AddChild(button_back);

                // name
                Text button_name = new Text(ButtonNames[i], Game.TidyHand, 50);
                FloatRect button_nameRect = button_name.GetLocalBounds();
                button_name.Origin = new Vector2f(button_nameRect.Left + button_nameRect.Width / 2.0f, 0);
                button_name.Position = new Vector2f(button_back.Size.X / 2, 0);
                if (!pickable)
                    button_name.Color = new Color(255, 255, 255, 50);
                button.AddChild(button_name);

                // description
                if (ButtonDescriptions.Count > i)
                {
                    Text button_description = new Text(ButtonDescriptions[i], Game.TidyHand, 30);
                    FloatRect button_descriptionRect = button_description.GetLocalBounds();
                    button_description.Origin = new Vector2f(button_descriptionRect.Width / 2.0f, 0);
                    button_description.Position = new Vector2f(button_back.Size.X / 2, 60);
                    button_description.Color = new Color(180, 180, 180, (byte)(pickable ? 255 : 120));
                    button.AddChild(button_description);
                }

                SetupButtonAdditional(i, button, button_back, pickable);

                AddChild(button);
                if (pickable)
                    Buttons.Add(button);
                else
                    Buttons.Add(null);
            }
            SelectButton(CurrentSelection);
        }