public Bar(int width, int height, Color color1, Color color2, Color backgroundColor, int borderThickness = 0, float startValue = 0f) { Value = startValue; this.color1 = color1; this.color2 = color2; this.width = width; this.height = height; progress = DebugTextures.GenerateRectangle(width, height, Color.White); if (borderThickness > 0) { border = DebugTextures.GenerateHollowRectangele(width, height, borderThickness, Color.Black); origin = new Vector2(border.Width / 2f, border.Height / 2f); } if (backgroundColor != Color.Transparent) { this.backgroundColor = backgroundColor; background = DebugTextures.GenerateRectangle(progress.Width, progress.Height, Color.White); transparent = false; } else { transparent = true; } if (color2 == null) { color2 = color1; } }
public HealthBar() { Value = 1f; sprite = DebugTextures.GenerateHollowRectangele(10, 5, 1, Color.Black); progress = DebugTextures.GenerateRectangle(10, 5, Color.White); origin = new Vector2(sprite.Width / 2f, sprite.Height / 2f); }
public static void CreateGrid(Point startingPoint, int rows, int columns) { Cell.startingPoint = startingPoint; grid = new Cell[rows, columns]; for (int y = 0; y < columns; y++) { for (int x = 0; x < rows; x++) { grid[x, y] = new Cell(x * cellWidth + startingPoint.X, y * cellHeight + startingPoint.Y); } } CellSprite = DebugTextures.GenerateHollowRectangele(cellWidth, cellHeight, 1, Color.White); SpriteOrigin = new Vector2(cellWidth / 2f, cellHeight / 2f); }
public static Rectangle[] CollidingRectangle(Vector2 position, Cell[] cellCheck, int width, int height, out Collider[] colInfo) // need multiple collider objects!! { List <Rectangle> colliders = null; List <Collider> colInfos = null; Rectangle rect1 = new Rectangle((int)position.X - width / 2, (int)position.Y - height / 2, width, height); foreach (var cell in cellCheck) { if (cell.colliders.Count > 0) { foreach (var co in cell.colliders) { Rectangle rect2 = new Rectangle((int)co.position.X - co.width / 2, (int)co.position.Y - co.height / 2, co.width, co.height); if (rect1 == rect2) { continue; } if (Game1.instance.debugDrawing) { debugTexture = DebugTextures.GenerateHollowRectangele(rect1.Width, rect1.Height, 1, Color.White); colPosition = rect1.Center.ToVector2(); colOrigin = new Vector2(debugTexture.Width / 2f, debugTexture.Height / 2f); } Rectangle col = Rectangle.Intersect(rect1, rect2); if (!col.IsEmpty) { if (colliders == null) { colliders = new List <Rectangle>(); } if (co.owner != null) { if (colInfos == null) { colInfos = new List <Collider>(); } colInfos.Add(co); } colliders.Add(col); if (Game1.instance.debugDrawing) { debugTexture = DebugTextures.GenerateHollowRectangele(col.Width, col.Height, 1, Color.White); colPosition = col.Center.ToVector2(); colOrigin = new Vector2(debugTexture.Width / 2f, debugTexture.Height / 2f); } } } } } /*foreach (var co in Game1.instance.map.colliders) // loop through every possible collidable object (has to be more efficient in the fututre) * { * * #region debug * * if (Game1.instance.debugDrawing) * { * //debugTexture = DebugTextures.GenerateHollowRectangele(rect1.Width, rect1.Height, 2, Color.White); * //colPosition = rect1.Location.ToVector2(); * //colOrigin = new Vector2(debugTexture.Width / 2f, debugTexture.Height / 2f); * } * #endregion * }*/ if (colliders == null) { colInfo = null; return(null); } if (colInfos != null) { colInfo = colInfos.ToArray(); } else { colInfo = null; } return(colliders.ToArray()); }
/// <summary> /// is an object colliding with any of the scene objects? /// </summary> /// <param name="position">origin</param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public static Rectangle[] CollidingRectangle(Vector2 position, Cell[] cellCheck, int width, int height) // needs to return multiple tags if colliding with multiple objects (return collider instead of rectangle) { List <Rectangle> colliders = null; Rectangle rect1 = new Rectangle((int)position.X - width / 2, (int)position.Y - height / 2, width, height); foreach (var cell in cellCheck) { if (cell.colliders.Count > 0) { foreach (var co in cell.colliders) { Rectangle rect2 = new Rectangle((int)co.position.X - co.width / 2, (int)co.position.Y - co.height / 2, co.width, co.height); if (rect1 == rect2) // remember that this may be causing issues for different objects with the same size { continue; } if (Game1.instance.debugDrawing) { debugTexture = DebugTextures.GenerateHollowRectangele(rect1.Width, rect1.Height, 1, Color.White); colPosition = rect1.Center.ToVector2(); colOrigin = new Vector2(debugTexture.Width / 2f, debugTexture.Height / 2f); } Rectangle col = Rectangle.Intersect(rect1, rect2); if (!col.IsEmpty) { if (colliders == null) { colliders = new List <Rectangle>(); } colliders.Add(col); if (Game1.instance.debugDrawing) { debugTexture = DebugTextures.GenerateHollowRectangele(col.Width, col.Height, 1, Color.White); colPosition = col.Center.ToVector2(); colOrigin = new Vector2(debugTexture.Width / 2f, debugTexture.Height / 2f); } } } } } /*foreach (var co in Game1.instance.map.colliders) // loop through every possible collidable object (has to be more efficient in the fututre) * { * * #region debug * * if (Game1.instance.debugDrawing) * { * //debugTexture = DebugTextures.GenerateHollowRectangele(rect1.Width, rect1.Height, 2, Color.White); * //colPosition = rect1.Location.ToVector2(); * //colOrigin = new Vector2(debugTexture.Width / 2f, debugTexture.Height / 2f); * } * #endregion * }*/ if (colliders == null) { return(null); } return(colliders.ToArray()); }