Example #1
0
        public static Vector2 Clamp(this Vector2 rect, FloatRectangle clamp, bool leftClampOnly = false)
        {
            float tx = rect.X;
            float ty = rect.Y;


            if (tx < clamp.X)
            {
                tx = clamp.X;
            }
            if (ty < clamp.Y)
            {
                ty = clamp.Y;
            }
            if (!leftClampOnly)
            {
                if (tx > clamp.BottomRight.X)
                {
                    tx = clamp.BottomRight.X;
                }
                if (ty > clamp.BottomRight.Y)
                {
                    ty = clamp.BottomRight.Y;
                }
            }

            return(new Vector2(tx, ty));
        }
Example #2
0
 public DisplayRegion(FloatRectangle floatRectangle)
 {
     Top = floatRectangle.Top;
     Bottom = floatRectangle.Bottom;
     Left = floatRectangle.Left;
     Right = floatRectangle.Right;
 }
        /// <summary>
        /// Creates a new Living Entity
        /// </summary>
        /// <param name="rect">The rectangle that represents the location and width and height of the entity</param>
        /// <param name="fileName">the location of the sprite for this entity</param>
        public LivingEntity(FloatRectangle rect, Sprite sprite, int health, AI.AI ai = null, int cash = 0)
            : base(rect, sprite)
        {
            inventory = new Inventory();
            time = new GameTime();
            lastShot = 60000D;

            interactRange = 32;
            // the below depend on texture, this should not be needed ever but because of the player texture it is...
            //this.interactBoundsOffsetY = interactBoundsOffsetY;
            //this.interactBoundsOffsetX = interactBoundsOffsetX;

            this.cash = cash;
            this.health = health;
            this.ai = ai;

            maxHealth = health;

            color = Color.Red;

            healthBar = new ProgressBar(new Vector2(60, 20));
            healthBar.MaxValue = maxHealth;
            healthBar.CurrentValue = health;
            healthBar.IncludeText = Name;
            healthBar.LoadVisuals(Game1.Instance.Content, Game1.Instance.GraphicsDevice);
            controls.Add(healthBar);
        }
Example #4
0
        public static StaticButtonAsset CreateButton(FloatRectangle position, ButtonBasics bb, float fontMargin = 0)
        {
            var buttonAsset = new StaticButtonAsset(position, bb.Text, (args) => { Debug.WriteLine(bb.Text + " clicked"); }, fontMargin: fontMargin);

            if (bb.Symbol != null)
            {
                buttonAsset.Symbol.Value = bb.Symbol;
            }

            //if (bb.Text == "---")
            //{
            //    buttonAsset.
            //}

            if (bb.ClickAction != null)
            {
                buttonAsset.Clicked.Action = bb.ClickAction;
            }
            else
            {
                buttonAsset.Clicked.Action = (args) => { Debug.WriteLine(bb.Text + " autoclicked"); };
            }
            buttonAsset.Enabled.Value = bb.Enabled;

            if (bb.OverrideBgColor != null)
            {
                buttonAsset.Normal.Value.BackgroundColor = bb.OverrideBgColor.Value;
            }

            return(buttonAsset);
        }
Example #5
0
 public ImageAsset(Texture2D txture, FloatRectangle position, Color?color = null, float rotation = 0)
 {
     Texture2D.Value       = txture;
     Position.Value        = position;
     this.ImageColor.Value = color ?? Color.White;
     Rotation.Value        = rotation;
 }
 public void Clear(FloatRectangle Area)
 {
     for (int i = 0; i < Lists.Count; i++)
     {
         Lists[i].Clear(Area);
     }
 }
Example #7
0
        public Rectangle GetCharacterRect(char c, int lineNumber, ref Vector2 point, out FloatRectangle destinationRectangle,
                                          out int pageIndex, float fontScale = 1)
        {
            BitmapCharacterInfo characterInfo = GetCharacterInfo(c);

            int sourceLeft   = characterInfo.GetPixelLeft(Texture);
            int sourceTop    = characterInfo.GetPixelTop(Texture);
            int sourceWidth  = characterInfo.GetPixelRight(Texture) - sourceLeft;
            int sourceHeight = characterInfo.GetPixelBottom(Texture) - sourceTop;

            int distanceFromTop = characterInfo.GetPixelDistanceFromTop(LineHeightInPixels);

            // There could be some offset for this character
            int xOffset = characterInfo.GetPixelXOffset(LineHeightInPixels);

            point.X += xOffset * fontScale;

            point.Y = (lineNumber * LineHeightInPixels + distanceFromTop) * fontScale;

            var sourceRectangle = new Microsoft.Xna.Framework.Rectangle(
                sourceLeft, sourceTop, sourceWidth, sourceHeight);

            pageIndex = characterInfo.PageNumber;

            destinationRectangle = new FloatRectangle(point.X, point.Y, sourceWidth * fontScale, sourceHeight * fontScale);

            point.X -= xOffset * fontScale;
            point.X += characterInfo.GetXAdvanceInPixels(LineHeightInPixels) * fontScale;

            return(sourceRectangle);
        }
        protected virtual IList <Tile> GetIntersection(FloatRectangle bounds)
        {
            TileMatrix   matrix       = TileMatrix.Instance;
            IList <Tile> intersection = matrix.Intersect(bounds);

            return(intersection);
        }
Example #9
0
        public void DoBlur(Texture2D sprite, int blurAmount, Color color, Rectangle rect, Rectangle?scissorRect, FloatRectangle?clip, int noisePerc = 0)
        {
            if (Effect == null)
            {
                return;
            }
            if (sprite == null)
            {
                return;
            }

            rect = new FloatRectangle(rect).Clamp(clip).ToRectangle;

            if (Solids.Settings.EnableBlur)
            {
                ////      Solids.Instance.SpriteBatch.DoEnd();
                //Solids.Instance.SpriteBatch.Scissor = scissorRect;
                ////      Solids.Instance.SpriteBatch.DoEnd();

                Effect.CurrentTechnique = Effect.Techniques["AcrylicBlur"];
                Effect.Parameters["gfxWidth"].SetValue((float)sprite.Width);
                Effect.Parameters["gfxHeight"].SetValue((float)sprite.Height);
                Effect.Parameters["blurSize"].SetValue((int)(blurAmount));
                if (noisePerc > 0)
                {
                    Effect.Parameters["noisePerc"].SetValue(noisePerc);
                }

                //Solids.Instance.SpriteBatch.GraphicsDevice.Clear(Color.TransparentBlack);
                using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch, SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, Solids.Instance.SpriteBatch.RasterizerState, Effect, null))
                {
                    Solids.Instance.SpriteBatch.Draw(sprite, rect, rect, color);
                }
            }
        }
Example #10
0
 /// <summary>
 /// Creates a new view from a view rectangle, taking it as viewport and as view definition.
 /// </summary>
 /// <param name="rect">The view rectangle</param>
 /// <param name="rotation">The view rotation. Defaults to 0</param>
 public View(FloatRectangle rect, float rotation = 0f)
 {
     this.viewport = new Viewport((int)rect.Position.X, (int)rect.End.Y, (int)rect.End.X, (int)rect.Position.Y);
     this.position = rect.Position;
     this.size     = rect.Size;
     this.rotation = rotation;
 }
Example #11
0
        public IList <Tile> Intersect(FloatRectangle bounds)
        {
            IList <Tile> intersection = new List <Tile>();

            // calculate possible tile bounds to improve performance.
            int colStart  = Math.Max(0, (int)bounds.Left / Tile.Width - 1);
            int colItems  = (int)bounds.Width / Tile.Width + 2;
            int colLength = Math.Min(Tiles.GetLength(0), colStart + colItems + 1);

            int rowStart  = Math.Max(0, (int)bounds.Top / Tile.Height - 1);
            int rowItems  = (int)bounds.Height / Tile.Height + 2;
            int rowLength = Math.Min(Tiles.GetLength(1), rowStart + rowItems + 1);

            for (int x = colStart; x < colLength; x++)
            {
                for (int y = rowStart; y < rowLength; y++)
                {
                    Tile tile = Tiles[x, y];

                    var intersects = bounds.Intersects(tile.Bounds);
                    if (intersects)
                    {
                        intersection.Add(tile);
                    }
                }
            }

            return(intersection);
        }
 // size in
 public CollisionTile(int x, int y, CollisionTile[,] grid)
 {
     entities   = new List <Entity.Entity>();
     loc        = new FloatRectangle(x, y, SIDE_LENGTH, SIDE_LENGTH);
     isWalkable = true;
     this.grid  = grid;
 }
Example #13
0
        private Vector2 Think(GameTime gameTime, int thoughts = 3)
        {
            FloatRectangle aabb          = BoundingBox.Bounds;
            Vector2        interpolation = Movement.InterpolationCalculator.CalculateInterpolation(gameTime);

            if (interpolation == Vector2.Zero)
            {
                return(interpolation);
            }

            Vector2    movement  = AddMargin(interpolation) + MagicNumbers.GloopVertigoMargin;
            MoveResult predicted = Movement.CollisionDetection.CanMoveInterpolated(aabb, movement, DetectionType.Collision);

            if (!predicted.HasFlag(MoveResult.BlockedOnNegativeX) &&
                !predicted.HasFlag(MoveResult.BlockedOnPositiveX) &&
                predicted.HasFlag(MoveResult.BlockedOnPositiveY))
            {
                return(interpolation);
            }
            else if (thoughts > 0)
            {
                ToggleDirection();

                return(Think(gameTime, --thoughts));
            }
            else
            {
                return(Vector2.Zero);
            }
        }
Example #14
0
        static FloatRectangle ToFloatRectangle(System.Xml.Linq.XElement element)
        {
            FloatRectangle toReturn = new FloatRectangle();

            foreach (var subElement in element.Elements())
            {
                switch (subElement.Name.LocalName)
                {
                case "Bottom":
                    toReturn.Bottom = SceneSave.AsFloat(subElement);
                    break;

                case "Left":
                    toReturn.Left = SceneSave.AsFloat(subElement);
                    break;

                case "Right":
                    toReturn.Right = SceneSave.AsFloat(subElement);
                    break;

                case "Top":
                    toReturn.Top = SceneSave.AsFloat(subElement);
                    break;

                default:
                    throw new NotImplementedException(subElement.Name.LocalName);
                    //break;
                }
            }


            return(toReturn);
        }
Example #15
0
        static FloatRectangle[][] ToFloatRectangleArrayArray(System.Xml.Linq.XElement element)
        {
            List <List <FloatRectangle> > frReferenceListList = new List <List <FloatRectangle> >();

            foreach (var subElement in element.Elements())
            {
                List <FloatRectangle> newList = new List <FloatRectangle>();

                frReferenceListList.Add(newList);
                foreach (var subSubElement in subElement.Elements())
                {
                    FloatRectangle newRectangle = ToFloatRectangle(subSubElement);
                    newList.Add(newRectangle);
                }
            }

            FloatRectangle[][] toReturn = new FloatRectangle[frReferenceListList.Count][];

            for (int i = 0; i < frReferenceListList.Count; i++)
            {
                toReturn[i] = frReferenceListList[i].ToArray();
            }

            return(toReturn);
        }
Example #16
0
 public DisplayRegion(FloatRectangle floatRectangle)
 {
     Top    = floatRectangle.Top;
     Bottom = floatRectangle.Bottom;
     Left   = floatRectangle.Left;
     Right  = floatRectangle.Right;
 }
        /// <summary>
        /// Creates a new Living Entity
        /// </summary>
        /// <param name="rect">The rectangle that represents the location and width and height of the entity</param>
        /// <param name="fileName">the location of the sprite for this entity</param>
        public LivingEntity(FloatRectangle rect, Sprite sprite, int health, AI.AI ai = null, int cash = 0)
            : base(rect, sprite)
        {
            inventory = new Inventory();
            time      = new GameTime();
            lastShot  = 60000D;

            interactRange = 32;
            // the below depend on texture, this should not be needed ever but because of the player texture it is...
            //this.interactBoundsOffsetY = interactBoundsOffsetY;
            //this.interactBoundsOffsetX = interactBoundsOffsetX;

            this.cash   = cash;
            this.health = health;
            this.ai     = ai;

            maxHealth = health;

            color = Color.Red;

            healthBar              = new ProgressBar(new Vector2(60, 20));
            healthBar.MaxValue     = maxHealth;
            healthBar.CurrentValue = health;
            healthBar.IncludeText  = Name;
            healthBar.LoadVisuals(Game1.Instance.Content, Game1.Instance.GraphicsDevice);
            controls.Add(healthBar);
        }
 // size in
 public CollisionTile(int x, int y, CollisionTile[,] grid)
 {
     entities = new List<Entity.Entity>();
     loc = new FloatRectangle(x, y, SIDE_LENGTH, SIDE_LENGTH);
     isWalkable = true;
     this.grid = grid;
 }
 public virtual void Clear(FloatRectangle Area)
 {
     if (MyCollection != null)
     {
         MyCollection.Clear(Area);
     }
 }
        public void Clear()
        {
            FloatRectangle rect = new FloatRectangle();

            rect.TR = TR + new Vector2(10000, 10000);
            rect.BL = BL - new Vector2(10000, 10000);
            Clear(rect);
        }
        public virtual MoveResult CanMove(FloatRectangle bounds, Vector2 interpolation, DetectionType detectionType)
        {
            FloatRectangle xTarget = bounds.Displace(interpolation * Direction.Right);
            FloatRectangle yTarget = bounds.Displace(interpolation * Direction.Down);
            FloatRectangle target  = bounds.Displace(interpolation);

            return(CanMove(bounds, interpolation, detectionType, xTarget, yTarget, target));
        }
        public MoveResult CanMoveInterpolated(FloatRectangle bounds, Vector2 interpolation, DetectionType detectionType)
        {
            FloatRectangle xTarget = new FloatRectangle(bounds).Offset(interpolation.X, 0);
            FloatRectangle yTarget = new FloatRectangle(bounds).Offset(0, interpolation.Y);
            FloatRectangle target  = new FloatRectangle(bounds).Offset(interpolation.X, interpolation.Y);

            return(CanMove(bounds, interpolation, detectionType, xTarget, yTarget, target));
        }
 public CentredImageAsset(string txture, FloatRectangle position, ScaleMode scalemode = ScaleMode.Fill, float rotation = 0f)
 {
     texture = Solids.Instance.AssetLibrary.GetTexture(txture, true);
     //texture = txture;
     Position.Value    = position;
     ScalingMode.Value = scalemode;
     aspectRatio       = texture.Width / (float)texture.Height;
     Rotation.Value    = rotation;
 }
Example #24
0
 public RectangleAsset(Color color, int brushSize, FloatRectangle position, Color?backgroundColor = null, int blurAmout = 0, int noisePerc = 7)
 {
     NoisePerc.Value       = noisePerc;
     BorderColor.Value     = color;
     BrushSize.Value       = brushSize;
     Position.Value        = position;
     BackgroundColor.Value = backgroundColor;
     BlurAmount.Value      = blurAmout;
 }
Example #25
0
        public static FloatRectangle Clamp(this FloatRectangle rect, Rectangle?clamp, bool leftClampOnly = false)
        {
            if (!clamp.HasValue)
            {
                return(rect);
            }

            return(Clamp(rect, new FloatRectangle(clamp.Value), leftClampOnly));
        }
Example #26
0
        private void pnlDisplays_Paint(object sender, PaintEventArgs e)
        {
            var g           = e.Graphics;
            var pen         = new Pen(Color.Black, 1);
            var selectedPen = new Pen(Color.Black, 5);
            var dimensions  = new Rectangle(5, 5, pnlDisplays.Width - 15, pnlDisplays.Height - 15);

            g.DrawRectangle(pen, dimensions);

            //Set default display if we don't have one
            bool found = false;

            foreach (var screen in Screen.AllScreens)
            {
                if (GetDeviceName(screen.DeviceName) == _currentDisplay)
                {
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                _currentDisplay = GetDeviceName(Screen.PrimaryScreen.DeviceName);
            }

            var v      = SystemInformation.VirtualScreen;
            var colors = new Color[] { Color.LightBlue, Color.LightGreen, Color.Pink,
                                       Color.LightYellow, Color.PowderBlue, Color.LightSalmon };
            FloatRectangle?selected = null;

            for (int i = 0; i < Screen.AllScreens.Length; i++)
            {
                float x = (float)dimensions.X + ((((float)Screen.AllScreens[i].Bounds.X -
                                                   (float)v.X) / (float)v.Width) * (float)dimensions.Width);
                float y = (float)dimensions.Y + ((((float)Screen.AllScreens[i].Bounds.Y -
                                                   (float)v.Y) / (float)v.Height) * (float)dimensions.Height);
                float width = (float)Math.Round((float)((float)Screen.AllScreens[i].Bounds.Width /
                                                        (float)v.Width) * (float)dimensions.Width, 0);
                float height = (float)Math.Round((float)((float)Screen.AllScreens[i].Bounds.Height /
                                                         (float)v.Height) * (float)dimensions.Height, 0);

                g.FillRectangle(new SolidBrush(colors[i % colors.Length]), x, y, width, height);

                if (_currentDisplay == GetDeviceName(Screen.AllScreens[i].DeviceName))
                {
                    selected = new FloatRectangle(x, y, width, height);
                }
                g.DrawRectangle(pen, x, y, width, height);
            }

            if (selected != null)
            {
                g.DrawRectangle(selectedPen, selected.Value.X, selected.Value.Y,
                                selected.Value.Width, selected.Value.Height);
            }
        }
Example #27
0
            public override bool Equals(object obj)
            {
                if (obj is FloatRectangle)
                {
                    FloatRectangle rect = (FloatRectangle)obj;
                    return(float.Equals(this.x, rect.x) && float.Equals(this.y, rect.y) && float.Equals(this.width, rect.width) && float.Equals(this.height, rect.height));
                }

                return(false);
            }
Example #28
0
 public static void DrawBorder(this SmartSpriteBatch spriteBatch, FloatRectangle rect, Color color, int brushSize, FloatRectangle?clip)
 {
     for (int x = 0; x < brushSize; x++)
     {
         for (int y = 0; y < brushSize; y++)
         {
             FloatRectangle r = new FloatRectangle(rect.X + x, rect.Y + y, rect.Width - x - x, rect.Height - y - y);
             spriteBatch.DrawRectangle(r, color, clip: clip);
         }
     }
 }
Example #29
0
 public static bool Intersects(FloatRectangle a, FloatRectangle b)
 {
     if (a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height)
     {
         return(b.y < a.y + a.height);
     }
     else
     {
         return(false);
     }
 }
Example #30
0
        /// <summary>
        /// Creates a new Player
        /// </summary>
        /// <param name="location">A rectangle representing the location of the player</param>
        /// <param name="fileName">The location of the sprite in the files</param>
        public Player(FloatRectangle location, Sprite sprite) : base(location, sprite, 10, null, 40)
        {
            //cash = 40;
            questPoints = 0;
            health      = 10;
            direction   = Direction.Up;
            rand        = new Random();
            log         = new Quests.QuestLog();

            color = Color.White;
        }
Example #31
0
 public void SetChildrenOriginToMyOrigin(FloatRectangle actualPosition)
 {
     if (Children.Value != null)
     {
         foreach (var child in Children.Value)
         {
             child.ParentPosition = actualPosition;
             //child.Position.Value = new FloatRectangle(this.Position.Value.X,this.Position.Value.Y,child.Position.Value.Width,child.Position.Value.Height);
         }
     }
 }
Example #32
0
 public RectangleAsset(Color color, int brushSize, FloatRectangle position, string fillTexture, Color?backgroundColor = null, TileMode tileMode = TileMode.JustStretch, int blurAmout = 0, int noisePerc = 7)
 {
     NoisePerc.Value       = noisePerc;
     BorderColor.Value     = color;
     BrushSize.Value       = brushSize;
     Position.Value        = position;
     FillTexture.Value     = fillTexture;
     BackgroundColor.Value = backgroundColor ?? Color.White;
     TilingMode.Value      = tileMode;
     BlurAmount.Value      = blurAmout;
 }
        private static void UseCustomRectangleClick(object sender, EventArgs e)
        {
            FloatRectangle rectangle = new FloatRectangle(0, 0,
                                                          ProjectManager.GlueProjectSave.ResolutionWidth,
                                                          ProjectManager.GlueProjectSave.ResolutionHeight);

            EditorLogic.CurrentNamedObject.DestinationRectangle = rectangle;

            ElementViewWindow.GenerateSelectedElementCode();
            GluxCommands.Self.SaveGlux();
            MainGlueWindow.Self.PropertyGrid.Refresh();
        }
        public RotatedRectangle(FloatRectangle theRectangle, float theInitialRotation, Vector2? theOrigin = null)
        {
            collisionRectangle = theRectangle;
            rotation = theInitialRotation;

            //Calculate the Rectangles origin. We assume the center of the Rectangle will
            //be the point that we will be rotating around and we use that for the origin
            if (theOrigin == null)
                origin = new Vector2(theRectangle.Width / 2, theRectangle.Height / 2);
            else
                origin = (Vector2)theOrigin;
        }
Example #35
0
        /// <summary>
        /// Creates a new Player
        /// </summary>
        /// <param name="location">A rectangle representing the location of the player</param>
        /// <param name="fileName">The location of the sprite in the files</param>
        public Player(FloatRectangle location, Sprite sprite)
            : base(location, sprite, 10, null, 40)
        {
            //cash = 40;
            questPoints = 0;
            health = 10;
            direction = Direction.Up;
            rand = new Random();
            log = new Quests.QuestLog();

            color = Color.White;
        }
Example #36
0
        /// <summary>
        /// The constructor for the base entity.
        /// </summary>
        /// <param name="fileName">The texture filename for the entity.</param>
        /// <param name="location">The height, width, and X and Y location.</param>
        public Entity(FloatRectangle location, Sprite sprite)
        {
            this.location = location;

            /*
             * We would need a custom file format in order to take in a sprite
             * and properly parse it for animation and what not.
             *
             * AS OF NOW, all entities have a "simple" sprite which is
             * basically a static image (Can be rotated within the draw params.) (IWGTI)
             *
             *
             * TO RESIZE A SPRITE, EITHER DO SPRITE.RESIZE OR INSTANTIATE VIA
             * THE HEIGHT AND WIDTH FROM LOCATION RECTANGLE?????
             */
            //sprite = new Sprite(location.IntHeight, location.IntWidth, 0, fileName);
            this.sprite = sprite;
            controls = new List<Control>();
            collisionReactionVector = Vector2.Zero;
            movement = Vector2.Zero;
            color = Color.White;
            collidingEntites = new List<Entity>();
        }
        private static void PaintTextureCoordinatesOnCurrentSpriteInGrid()
        {
            if (GameData.EditorLogic.CurrentSprites.Count != 0)
            {
                Sprite sprite = GameData.EditorLogic.CurrentSprites[0];

                FloatRectangle floatRectangle = new FloatRectangle(
                        sprite.TopTextureCoordinate,
                        sprite.BottomTextureCoordinate,
                        sprite.LeftTextureCoordinate,
                        sprite.RightTextureCoordinate);

                CurrentSpriteGrid.PaintSpriteDisplayRegion(sprite.X, sprite.Y, sprite.Z,
                    ref floatRectangle);

            }
        }
        static FloatRectangle ToFloatRectangle(System.Xml.Linq.XElement element)
        {
            FloatRectangle toReturn = new FloatRectangle();

            foreach (var subElement in element.Elements())
            {
                switch (subElement.Name.LocalName)
                {
                    case "Bottom":
                        toReturn.Bottom = SceneSave.AsFloat(subElement);
                        break;
                    case "Left":
                        toReturn.Left = SceneSave.AsFloat(subElement);
                        break;
                    case "Right":
                        toReturn.Right = SceneSave.AsFloat(subElement);
                        break;
                    case "Top":
                        toReturn.Top = SceneSave.AsFloat(subElement);
                        break;

                    default:
                        throw new NotImplementedException(subElement.Name.LocalName);
                        //break;
                }


            }


            return toReturn;

        }
        private void PaintGridAt(float x, float y, float z)
        {
            #region Paint Texture
            Texture2D newTexture = GuiData.ListWindow.HighlightedTexture;
            if (newTexture != null)
            {
                Texture2D lastTexture = CurrentSpriteGrid.PaintSprite(x, y, z, newTexture);

                if (lastTexture != newTexture)
                    tla.Add(new TextureLocation<Texture2D>(lastTexture, x, y));
            }
            #endregion

            #region Paint Display Region (FloatRectangle)
            DisplayRegion newDisplayRegion = GuiData.ListWindow.HighlightedDisplayRegion;
            FloatRectangle newAsFloatRectangle = null;



            if (newDisplayRegion != null)
            {
                newAsFloatRectangle = newDisplayRegion.ToFloatRectangle();
            }
            else
            {

                // If the newDisplayRegion is null, then there's not a DisplayRegion selected in the
                // list box.  Therefore, just use the TextureDisplayWindow's coordinates.
                newAsFloatRectangle = new FloatRectangle(
                    GuiData.TextureCoordinatesSelectionWindow.TopTV,
                    GuiData.TextureCoordinatesSelectionWindow.BottomTV,
                    GuiData.TextureCoordinatesSelectionWindow.LeftTU,
                    GuiData.TextureCoordinatesSelectionWindow.RightTU);
            }

            FloatRectangle lastFloatRectangle = CurrentSpriteGrid.PaintSpriteDisplayRegion(
                x, y, z, ref newAsFloatRectangle);

            #endregion

            #region Paint AnimationChainList
            AnimationChain newAnimationChain = GuiData.ListWindow.HighlightedAnimationChain;

            if (newAnimationChain != null)
            {
                CurrentSpriteGrid.PaintSpriteAnimationChain(x, y, z, newAnimationChain);
                // Paint AnimationChainList here
            }
            #endregion

        }
        private static void UseCustomRectangleClick(object sender, EventArgs e)
        {

            FloatRectangle rectangle = new FloatRectangle(0, 0,
                ProjectManager.GlueProjectSave.ResolutionWidth,
                ProjectManager.GlueProjectSave.ResolutionHeight);

            EditorLogic.CurrentNamedObject.DestinationRectangle = rectangle;

            ElementViewWindow.GenerateSelectedElementCode();
            GluxCommands.Self.SaveGlux();
            MainGlueWindow.Self.PropertyGrid.Refresh();
        }
Example #41
0
 public NPC(FloatRectangle rect, Sprite sprite, int health)
     : base(rect, sprite, health, null)
 {
 }
Example #42
0
 public FloatRectangle WorldCameraBounds()
 {
     FloatRectangle pixelCamera = Camera.Bounds;
     FloatRectangle worldCoords = new FloatRectangle(PixelToWorldCoordinates(pixelCamera.X),
         PixelToWorldCoordinates(pixelCamera.Y), PixelToWorldCoordinates(pixelCamera.Width),
         PixelToWorldCoordinates(pixelCamera.Height));
     return worldCoords;
 }
Example #43
0
 public EntityItem(FloatRectangle rect, Item.Item item)
     : base(rect, item.previewSprite)
 {
     this.item = item;
 }
Example #44
0
        private void pnlDisplays_Paint(object sender, PaintEventArgs e)
        {
            var g = e.Graphics;
              var pen = new Pen(Color.Black, 1);
              var selectedPen = new Pen(Color.Black, 5);
              var dimensions = new Rectangle(5, 5, pnlDisplays.Width - 15, pnlDisplays.Height - 15);

              g.DrawRectangle(pen, dimensions);

              //Set default display if we don't have one
              bool found = false;
              foreach (var screen in Screen.AllScreens)
              {
            if (GetDeviceName(screen.DeviceName) == _currentDisplay)
            {
              found = true;
              break;
            }
              }
              if (!found) _currentDisplay = GetDeviceName(Screen.PrimaryScreen.DeviceName);

              var v = SystemInformation.VirtualScreen;
              var colors = new Color[] { Color.LightBlue, Color.LightGreen, Color.Pink,
            Color.LightYellow, Color.PowderBlue, Color.LightSalmon };
              FloatRectangle? selected = null;
              for (int i = 0; i < Screen.AllScreens.Length; i++)
              {
            float x = (float)dimensions.X + ((((float)Screen.AllScreens[i].Bounds.X -
              (float)v.X) / (float)v.Width) * (float)dimensions.Width);
            float y = (float)dimensions.Y + ((((float)Screen.AllScreens[i].Bounds.Y -
              (float)v.Y) / (float)v.Height) * (float)dimensions.Height);
            float width = (float)Math.Round((float)((float)Screen.AllScreens[i].Bounds.Width /
              (float)v.Width) * (float)dimensions.Width, 0);
            float height = (float)Math.Round((float)((float)Screen.AllScreens[i].Bounds.Height /
              (float)v.Height) * (float)dimensions.Height, 0);

            g.FillRectangle(new SolidBrush(colors[i % colors.Length]), x, y, width, height);

            if (_currentDisplay == GetDeviceName(Screen.AllScreens[i].DeviceName))
              selected = new FloatRectangle(x, y, width, height);
            g.DrawRectangle(pen, x, y, width, height);
              }

              if (selected != null)
            g.DrawRectangle(selectedPen, selected.Value.X, selected.Value.Y,
              selected.Value.Width, selected.Value.Height);
        }
 /// <summary>
 /// This intersects method can be used to check a standard XNA framework Rectangle
 /// object and see if it collides with a Rotated Rectangle object
 /// </summary>
 /// <param name="theRectangle"></param>
 /// <returns></returns>
 public bool Intersects(FloatRectangle theRectangle)
 {
     return Intersects(new RotatedRectangle(theRectangle, 0.0f));
 }
        /// <summary>
        /// Takes a path to a quest file and parses it to a quest object
        /// </summary>
        /// <param name="filename">the file path</param>
        /// <returns>A quest</returns>
        public static Quest ParseQuest(string filename)
        {
            Quest quest = null;
            Console.WriteLine("Quest file name: \n\t" + filename);
            using (StreamReader input = new StreamReader(filename))
            {

                string data = input.ReadToEnd();
                if (data.Substring(5, 12).Contains("Storyline"))
                {
                    /*
                    //load individual quests
                    int index, end;
                    index = data.IndexOf("Folder") + 8;
                    end = data.IndexOf('"', index);
                    string folder = data.Substring(index, end - index);
                    storylineFolder = QUEST_DIRECTORY + folder;

                    Storyline newStoryline;

                    string[] files = Directory.GetFiles(storylineFolder);
                    Quest loaded;

                    //loop through all of the files in the directory
                    foreach (string path in files)
                    {
                        //try and parse the quest from each file
                        loaded = ParseQuest(path);

                        //if the parse was successfull, add it to the log
                        if (loaded != null)
                        {
                            newStoryline.Add(loaded);
                        }
                    }
                     */
                }
                else
                {
                    int index, end;
                    string attribute;
                    //get name
                    index = data.IndexOf("Name:") + 6;
                    end = data.IndexOf('"', index);
                    string name = data.Substring(index, end - index);

                    //get world key
                    index = data.IndexOf("World:") + 7;
                    end = data.IndexOf('"', index);
                    string key = data.Substring(index, end - index);

                    //get the description
                    index = data.IndexOf("Description:") + 13;
                    end = data.IndexOf('"', index);
                    string description = data.Substring(index, end - index);

                    //get objective
                    index = data.IndexOf("Objective:") + 11;
                    end = data.IndexOf('"', index);
                    string objective = data.Substring(index, end - index);

                    //get reward
                    index = data.IndexOf("Reward:");
                    index = data.IndexOf("Cash:", index) + 5;
                    end = data.IndexOf("\n", index);
                    attribute = data.Substring(index, end - index);
                    int cash;
                    if (!int.TryParse(attribute, out cash))
                        cash = 0;
                    index = data.IndexOf("Q-Points:", index) + 9;
                    end = data.IndexOf("\n", index);
                    attribute = data.Substring(index, end - index);
                    int qPoints;
                    if (!int.TryParse(attribute, out qPoints))
                        qPoints = 0;

                    //get start point
                    index = data.IndexOf("Start:");
                    index = data.IndexOf("X:", index) + 2;
                    end = data.IndexOf("\n", index);
                    attribute = data.Substring(index, end - index);
                    int X;
                    if (!int.TryParse(attribute, out X))
                        X = 10;
                    index = data.IndexOf("Y:", index) + 2;
                    end = data.IndexOf("\r", index);
                    attribute = data.Substring(index, end - index);
                    int Y;
                    if (!int.TryParse(attribute, out Y))
                        Y = 10;
                    Vector2 start = new Vector2(X, Y);

                    //get the win condition
                    index = data.IndexOf("Condition:") + 10;
                    end = data.IndexOf("\r", index);
                    attribute = data.Substring(index, end - index);
                    WinCondition condition; //win state
                    switch (attribute)
                    {
                        case "EnemyDies":
                            condition = WinCondition.EnemyDies;
                            break;
                        case "ObtainItem":
                            condition = WinCondition.ObtainItem;
                            break;
                        case "DeliverItem":
                            condition = WinCondition.DeliverItem;
                            break;
                        case "AllEnemiesDead":
                        default:
                            condition = WinCondition.AllEnemiesDead;
                            break;
                    }

                    //get the id of the entity or item that satisfies the quest condition
                    string target = "";
                    string recipient = "";
                    switch (condition)
                    {
                        case WinCondition.EnemyDies:
                        case WinCondition.ObtainItem:
                            //get the name of the entity
                            index = data.IndexOf("Target:") + 7;
                            string test = data.Substring(index);
                            end = data.IndexOf('\n', index) - 1;
                            target = data.Substring(index, end - index);
                            break;
                        case WinCondition.DeliverItem:
                            //get the target item
                            index = data.IndexOf("Target:") + 7;
                            target = data.Substring(index);

                            //get destination
                            index = data.IndexOf("Recipient:") + 10;
                            end = data.IndexOf('\n');
                            recipient = data.Substring(index, index - end);
                            break;
                    }
            #region Read Enemies
                    //read all of the living entities
                    Dictionary<string, Entity.LivingEntity> livingEntities = new Dictionary<string, Entity.LivingEntity>();
                    int endEntity = data.Length;
                    FloatRectangle EntityRect;
                    AI.AI ai;
                    //string test = data.Substring(index, 10);
                    index = 1;
                    while((index = data.IndexOf("Living Entity:", index)) > 0)
                    {
                        ai = null;
                        endEntity = data.IndexOf("End Living Enity", index);

                        //get the id
                        index = data.IndexOf("ID:", index) + 3;
                        end = data.IndexOf('\r', index);
                        string id = data.Substring(index, end - index);

                        //get the start position
                        //get start point
                        index = data.IndexOf("Start:", index);
                        index = data.IndexOf("X:", index) + 2;
                        end = data.IndexOf("\n", index);
                        attribute = data.Substring(index, end - index);
                        int sX;
                        if (!int.TryParse(attribute, out sX))
                            sX = 10;
                        index = data.IndexOf("Y:", index) + 2;
                        end = data.IndexOf("\r", index);
                        attribute = data.Substring(index, end - index);
                        int sY;
                        if (!int.TryParse(attribute, out sY))
                            sY = 10;

                        //get texture
                        index = data.IndexOf("Texture:", index) + 9;
                        end = data.IndexOf('"', index);
                        string texturePath = data.Substring(index, end - index);
                        GUI.Sprite sprite = GUI.Sprites.spritesDictionary[texturePath];

                        //create rectangle
                        EntityRect = new FloatRectangle(sX, sY, sprite.Width, sprite.Height);

                        //get the health
                        index = data.IndexOf("Health:", index) + 7;
                        end = data.IndexOf('\n', index);
                        attribute = data.Substring(index, end - index);
                        int health;
                        if(!int.TryParse(attribute, out health))
                        {
                            health = 0;
                        }

                        livingEntities[id] = new Entity.LivingEntity(EntityRect, sprite, health, null);
                        livingEntities[id].Name = id;

                        //get the ai
                        index = data.IndexOf("AI:", index) + 3;
                        end = data.IndexOf('\n', index) - 1;
                        if (index >= 0)
                        {
                            attribute = data.Substring(index, end - index);

                            switch (attribute)
                            {
                                case "Low":
                                    ai = new AI.LowAI(livingEntities[id]);
                                    break;
                                case "Mid":
                                    ai = new AI.HighAI(livingEntities[id]);
                                    break;
                                case "High":
                                    ai = new AI.HighAI(livingEntities[id]);
                                    break;
                                default:
                                    ai = null;
                                    break;
                            }

                            livingEntities[id].ai = ai;
                            livingEntities[id].inventory.Add(new Item.Weapon(50, 1, 10, "Bam", 100, 0.5));
                            livingEntities[id].inventory.ActiveWeapon = 0;

                        }

                    }

            #endregion

            #region Read Items
                    Dictionary<string, QuestItem> items = new Dictionary<string,QuestItem>();
                    index = 0;
                    int endItem = data.Length;
                    while((index = data.IndexOf("Item:", index)) > 0)
                    {
                        endItem = data.IndexOf("End Item", index);

                        //get the id
                        index = data.IndexOf("ID:", index) + 3;
                        end = data.IndexOf('\n', index);
                        string id = data.Substring(index, end - index);

                        //get the texture
                        index = data.IndexOf("Texture:", index) + 9;
                        end = data.IndexOf('"', index);
                        string texturePath = data.Substring(index, end - index);
                        GUI.Sprite sprite = GUI.Sprites.spritesDictionary[texturePath];

                        //create item
                        items[id] = new QuestItem(id);
                        items[id].Item = new Item.Item();
                        items[id].Item.previewSprite = sprite;

                    }
            #endregion

                    //Create the quest
                    quest = new Quest(name, objective, description, start, null, condition, qPoints, cash);
                    quest.worldKey = key;
                    quest.Status = 1;
                    //add the entities to the quests entitiy list
                    foreach (Entity.LivingEntity entity in livingEntities.Values.ToList())
                    {
                        quest.entitites.Add(entity);
                    }

                    //items too
                    /* Quest needs to be updated
                    foreach(Item.Item item in items.Values.ToArray())
                    {
                        quest.
                    }
                     */

                    switch (condition)
                    {
                        case WinCondition.EnemyDies:
                            quest.EnemyToKill = livingEntities[target];
                            break;
                        case WinCondition.AllEnemiesDead:
                            break;
                        case WinCondition.ObtainItem:
                            quest.FindThis = items[target].Item;
                            break;
                        case WinCondition.DeliverItem:
                            quest.Delivery = items[target].Item;
                            quest.Recipient = livingEntities[recipient];
                            break;
                        default:
                            break;
                    }
                }

            }
            return quest;
        }
Example #47
0
        private void CollisionReaction(FloatRectangle toCheck, int cornerCollisionCase = 0)
        {
            // http://www.metanetsoftware.com/technique/tutorialA.html#section0
            // pretty much learned this in a class im taking right now but im
            // too dumb to realize the application :*(...
            Vector2 xAxis = new Vector2(1.0f, 0); // these would have to change for rotating objects...
            Vector2 yAxis = new Vector2(0, 1.0f); // these would have to change for rotating objects...

            float xThisCenter = this.location.Center.X;
            float yThisCenter = this.location.Center.Y;

            //float xToTestCenter = e.location.Center.X;
            //float yToTestCenter = e.location.Center.Y;
            float xToTestCenter = toCheck.Center.X;
            float yToTestCenter = toCheck.Center.Y;

            Vector2 centers = new Vector2(xThisCenter - xToTestCenter, yThisCenter - yToTestCenter);

            Vector2 thisHalfWidth = new Vector2(this.location.Width / 2, 0);
            Vector2 thisHalfHeight = new Vector2(0, this.location.Height / 2);

            Vector2 toTestHalfWidth = new Vector2(toCheck.Width / 2, 0);
            Vector2 toTestHalfHeight = new Vector2(0, toCheck.Height / 2);

            // x axis collision check
            Vector2 projXCenters = Utils.Project(centers, xAxis);

            Vector2 projXThisWidth = Utils.Project(thisHalfWidth, xAxis);

            Vector2 projXToTestWidth = Utils.Project(toTestHalfWidth, xAxis);

            // y axis collision check
            Vector2 projYCenters = Utils.Project(centers, yAxis);

            Vector2 projYThisHeight = Utils.Project(thisHalfHeight, yAxis);

            Vector2 projYToTestHeight = Utils.Project(toTestHalfHeight, yAxis);

            // Collision Times
            //http://gamedev.stackexchange.com/questions/17502/how-to-deal-with-corner-collisions-in-2d
            // check for which dir to go in opp direction of...
            float xScalarFinal = (projXThisWidth.Length() + projXToTestWidth.Length()) - projXCenters.Length();
            float yScalarFinal = (projYThisHeight.Length() + projYToTestHeight.Length()) - projYCenters.Length();

            // DEBUG
            //Console.WriteLine("FLOAT X SCALAR: {0:0.00}", (projXThisWidth.Length() + projXToTestWidth.Length()) - projXCenters.Length());
            //Console.WriteLine("FLOAT Y SCALAR: {0:0.00}", (projYThisHeight.Length() + projYToTestHeight.Length()) - projYCenters.Length());

            if (xScalarFinal > yScalarFinal) {
                // DEBUG
                //Console.WriteLine("INT Y SCALAR: {0}", yScalarFinal * Math.Sign(DeltaY));
                collisionReactionVector = new Vector2(0, yScalarFinal * Math.Sign(movement.Y));
                //location.Y -= yScalarFinal * Math.Sign(movement.Y);
            } else {
                if (xScalarFinal == yScalarFinal) // corner collision
                {
                    float diff = 0;
                    switch (cornerCollisionCase) {
                        // y dummy reaction
                        case 0:
                            if (this.location.Center.Y < toCheck.Center.Y) {
                                // on top
                                diff = (this.location.Y + this.location.Height) - toCheck.Location.Y;
                                collisionReactionVector = new Vector2(0, diff);
                                //location.Y -= diff;
                                //Console.WriteLine("GOING UP");

                            } else {
                                // on bottom
                                diff = (toCheck.Location.Y + toCheck.Height) - this.location.Y;
                                collisionReactionVector = new Vector2(0, diff * -1);
                                //location.Y += diff;
                                //Console.WriteLine("GOING DOWN");
                            }
                            break;

                        // x dummy reaction
                        case 1:
                            if (this.location.Center.X < toCheck.Center.X) {
                                // on top
                                diff = (this.location.X + this.location.Width) - toCheck.Location.X;
                                collisionReactionVector = new Vector2(diff, 0);
                                //location.X -= diff;
                                //Console.WriteLine("GOING LEFT");

                            } else {
                                // on bottom
                                diff = (toCheck.Location.X + toCheck.Width) - this.location.X;
                                collisionReactionVector = new Vector2(diff * -1, 0);
                                //location.X += diff;
                                //Console.WriteLine("GOING RIGHT");
                            }
                            break;
                    }

                    //Console.WriteLine("CORNER {0}", new Random().NextDouble());
                } else {
                    //Console.WriteLine("INT X SCALAR: {0}", xScalarFinal * Math.Sign(DeltaY));
                    collisionReactionVector = new Vector2(xScalarFinal * Math.Sign(movement.X), 0);
                    //location.X -= xScalarFinal * Math.Sign(movement.X);
                }
            }

            location.Location -= collisionReactionVector;
        }
        static FloatRectangle[][] ToFloatRectangleArrayArray(System.Xml.Linq.XElement element)
        {
            List<List<FloatRectangle>> frReferenceListList = new List<List<FloatRectangle>>();

            foreach (var subElement in element.Elements())
            {
                List<FloatRectangle> newList = new List<FloatRectangle>();

                frReferenceListList.Add(newList);
                foreach (var subSubElement in subElement.Elements())
                {
                    FloatRectangle newRectangle = ToFloatRectangle(subSubElement);
                    newList.Add(newRectangle);
                }


            }

            FloatRectangle[][] toReturn = new FloatRectangle[frReferenceListList.Count][];

            for (int i = 0; i < frReferenceListList.Count; i++)
            {
                toReturn[i] = frReferenceListList[i].ToArray();

            }

            return toReturn;
        }