public static Vector2 ClosestPoint(this Rect rect, Vector2 point) { if (point.x < rect.xMin) { if (point.y < rect.yMin) { return(new Vector2(rect.xMin, rect.yMin)); } else if (point.y > rect.yMax) { return(new Vector2(rect.xMin, rect.yMax)); } else { return(point.AddX(rect.xMin - point.x)); } } else if (point.x > rect.xMax) { if (point.y < rect.yMin) { return(new Vector2(rect.xMax, rect.yMin)); } else if (point.y > rect.yMax) { return(new Vector2(rect.xMax, rect.yMax)); } else { return(point.AddX(point.x - rect.xMax)); } } else { if (point.y < rect.yMin) { return(point.AddY(rect.yMin - point.y)); } else if (point.y > rect.yMax) { return(point.AddY(point.y - rect.yMax)); } else { return(point); } } }
public BackgroundTilesLayer(SpriteBatch spriteBatch, Texture2D[] images, Rectangle[] spriteMap, List <int> map, Rotator rotator, float initialVelocity, Vector2 startingOffset, Rectangle ViewPort) { this.spriteBatch = spriteBatch; this.images = images; this.spriteMap = spriteMap; this.map = map; this.rotator = rotator; this.velocity = initialVelocity; this._currentPosition = startingOffset; this._previousPosition = _currentPosition.AddX(-3); this._destination = ViewPort; }
public void add_x_test() { //Arrange Vector2 input = Vector2.one; //Act input = input.AddX(1); //Assert Assert.AreEqual(2, input.x); Assert.AreEqual(1, input.y); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); _foregroundLayter2.Draw(); _foregroundLayter.Draw(); //_backgroundTiles.Draw(); // We've divided the screen top and main //spriteBatch.DrawFilledRect(new Vector2(0, 0), GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height/10, Color.White); spriteBatch.DrawString(arial, Math.Floor(this.rotator.CurrentAngle).ToString(), new Vector2(10, 10), Color.Plum); //// not an effective way of doing this. spriteBatch.DrawLine(_centrePoint.AddX(1), 99, this.rotator.CurrentAngle, Color.White); spriteBatch.DrawLine(_centrePoint, 100, this.rotator.CurrentAngle, Color.White); spriteBatch.DrawLine(_centrePoint.AddX(-1), 99, this.rotator.CurrentAngle, Color.White); spriteBatch.End(); }
public BackgroundTilesLayer(SpriteBatch spriteBatch, Texture2D[] images, Rectangle[] imageAtlas, List <int> map, Rotator rotator, float initialVelocity, Vector2 startingOffset, Rectangle ViewPort) { this.spriteBatch = spriteBatch; this.images = images; this.spiteMap = imageAtlas; this.map = map; this.rotator = rotator; this.velocity = initialVelocity; this._currentPosition = startingOffset; this._previousPosition = _currentPosition.AddX(-3); this._destination = ViewPort; frameDimensions = images.Length > 0 ? new Dimensions(images[0].Width, images[0].Height) : Dimensions.Zero; tileDimensions = new Dimensions(imageAtlas[0].Width, imageAtlas[0].Height); this.totalWidth = frameDimensions.Width; this.totalHeight = frameDimensions.Height; }
public BackgroundRectanglesLayer(SpriteBatch spriteBatch, Texture2D[] images, Rotator roation, float velocity, Vector2 startOffset, Rectangle ViewPort) { this.spriteBatch = spriteBatch; this.images = images; frameDimensions = images.Length > 0 ? new Dimensions(images[0].Width, images[0].Height) : Dimensions.Zero; this.currentRotation = roation; this._velocity = velocity; // Where we start in relation to our frames. so 0,0 means the top left of the first texture is at 0,0on the screen, // 50,50 would be: display background from position 50,50 at screen co-ords 0,0. // ie whats' the starting co-ordinate for the top-left of the screen. this._currentPosition = startOffset; // not perfect, ensures it DOES update. this._previousPosition = _currentPosition.AddX(-1); _destination = new Rectangle(Point.Zero, new Point(ViewPort.Width, ViewPort.Height)); this.totalWidth = frameDimensions.Width * images.Length; this.totalHeight = frameDimensions.Height; }
public Dictionary<Vector2, Tile> GetNeighbors(Vector2 center) { var toCheck = new Vector2[4]{ center.AddX(1f), center.AddX(-1f), center.AddY(1f), center.AddY(-1f) }; return CheckNeighbors(toCheck); }
public Dictionary<Vector2, Tile> GetKingNeighbors(Vector2 center) { var toCheck = new Vector2[8]{ center.AddX(1f), center.AddX(-1f), center.AddY(1f), center.AddY(-1f), center.Add(-1, -1), center.Add(-1, 1), center.Add(1, -1), center.Add(1, 1) }; return CheckNeighbors(toCheck); }
public Dictionary<Vector2, Tile> GetCrossTiles(Vector2 center, int distance) { var ret = new Dictionary<Vector2, Tile>() { { center, mapModel.tiles.Get(center) } }; Tile neighborTile = null; for (var d = 1; d <= distance; d++) { var toCheck = new Vector2[4] { center.AddX(d), center.AddX(-d), center.AddY(d), center.AddY(-d) }; foreach (var currentDirection in toCheck) { //check it's not off the map neighborTile = mapModel.tiles.Get(currentDirection); if (neighborTile != null) { ret[currentDirection] = neighborTile; } } } return ret; }