public SongButton(Rectangle rect, String folder) { String[] songfiles = Directory.GetFiles(folder, "*.wav", SearchOption.TopDirectoryOnly); String[] dmlfiles = Directory.GetFiles(folder, "*.dml", SearchOption.TopDirectoryOnly); if (dmlfiles.Count() > 0) dmlfile = dmlfiles[0]; String[] pngs = Directory.GetFiles(folder, "*.png", SearchOption.TopDirectoryOnly);//gets images from folder String[] jpgs = Directory.GetFiles(folder, "*.jpg", SearchOption.TopDirectoryOnly); String[] images = new String[pngs.Length + jpgs.Length]; pngs.CopyTo(images, 0); jpgs.CopyTo(images, pngs.Length); if (images.Count() > 0) { String image = images[0]; texture = Texture2D.FromStream(Globals.graphics.GraphicsDevice, File.OpenRead(image));//reads images from stream(non content) } else { texture = new Texture2D(Globals.graphics.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); texture.SetData<Color>(new Color[] { Color.White }); } this.song = songfiles[0]; if (songfiles.Length>0) this.music = new Wave(songfiles[0]); this.title = songfiles[0]; this.rect = rect; CollisionMask = new RectCollider(rect); }
public static bool Collision(CircleCollider self, RectCollider other) { double cx = self.x, cy = self.y, r = self.radius; double x = other.x, y = other.y, w = other.width, h = other.height; double rx = x + w / 2, ry = y + h / 2; double x_offset = Math.Abs(cx - rx); double y_offset = Math.Abs(cy - ry); double half_width = w / 2; double half_height = h / 2; if (x_offset > (half_width + r)) { return(false); } else if (y_offset > (half_height + r)) { return(false); } if (x_offset <= half_width) { return(true); } else if (y_offset <= half_height) { return(true); } double deltax = x_offset - half_width; double deltay = y_offset - half_height; double dist = Math.Pow(deltax, 2) + Math.Pow(deltay, 2); return(dist <= r * r ? true : false); }
/// <summary> /// Check for a collision between a RectCollider and a RectCollider. /// </summary> /// <param name="self"></param> /// <param name="other"></param> public static bool Collision(RectCollider self, RectCollider other) { return( (self.x <= other.x + other.width) && (self.x + self.width >= other.x) && (self.y <= other.y + other.height) && (self.y + self.height >= other.y) ); }
public SceneButton(string n, string texture_name, Vector2 topleft, Rectangle rect) { name = n; locked = false; selected = false; texture = Globals.content.Load<Texture2D>(texture_name); CollisionMask = new RectCollider(rect); }
/// <summary> /// Check for a collision between a RectCollider and a RectCollider. /// </summary> /// <param name="self"></param> /// <param name="other"></param> public static bool Collision(RectCollider self, RectCollider other) { return ( (self.x <= other.x + other.width) && (self.x + self.width >= other.x) && (self.y <= other.y + other.height) && (self.y + self.height >= other.y) ); }
public SceneButton(string n,string texture_name, Vector2 topleft) { // Constructor edited by: Michael Ala name = n; locked = false; selected = false; // Initialize RectCollider texture = Globals.content.Load<Texture2D>(texture_name); CollisionMask = new RectCollider(topleft.X, topleft.Y, texture.Width, texture.Height); }
/// <summary> /// Check for a collision between a RectCollider and a RayCollider. /// </summary> /// <param name="self"></param> /// <param name="other"></param> public static bool Collision(RectCollider self, RayCollider other) { Vector2[] corners = self.Corners; Vector2 p1, p2; for (int i = 0; i < 4; i++) { p1 = corners[i]; p2 = corners[(i + 1) % 4]; if (GeometryUtils.RayToSegmentPOI( other.x1, other.y1, other.x2, other.y2, p1.X, p1.Y, p2.X, p2.Y).HasValue) return true; } return false; }
/// <summary> /// Check for a collision between a RectCollider and a RayCollider. /// </summary> /// <param name="self"></param> /// <param name="other"></param> public static bool Collision(RectCollider self, RayCollider other) { Vector2[] corners = self.Corners; Vector2 p1, p2; for (int i = 0; i < 4; i++) { p1 = corners[i]; p2 = corners[(i + 1) % 4]; if (GeometryUtils.RayToSegmentPOI( other.x1, other.y1, other.x2, other.y2, p1.X, p1.Y, p2.X, p2.Y).HasValue) { return(true); } } return(false); }
/// <summary> /// Check for a collision between a RectCollider and a LineSegmentCollider. /// </summary> /// <param name="self"></param> /// <param name="other"></param> public static bool Collision(RectCollider self, LineSegmentCollider other) { return(GeometryUtils.SeparatingAxisTheorem(self.Corners, new Vector2[] { other.Start, other.End })); }
/// <summary> /// Check for a collision between a RectCollider and a ParticleCollider. /// </summary> /// <param name="self"></param> /// <param name="other"></param> public static bool Collision(RectCollider self, ParticleCollider other) { return((self.x <= other.x && other.x <= self.x + self.width) && (self.y <= other.y && other.y <= self.y + self.height)); }
/// <summary> /// Check for a collision between a ParticleCollider and a RectCollider. /// </summary> /// <param name="self"></param> /// <param name="other"></param> public static bool Collision(ParticleCollider self, RectCollider other) { return Collision(other, self); }
/// <summary> /// Check for a collision between a RectCollider and a LineSegmentCollider. /// </summary> /// <param name="self"></param> /// <param name="other"></param> public static bool Collision(RectCollider self, LineSegmentCollider other) { return GeometryUtils.SeparatingAxisTheorem(self.Corners, new Vector2[] { other.Start, other.End }); }
/// <summary> /// Check for a collision between a RectCollider and a ParticleCollider. /// </summary> /// <param name="self"></param> /// <param name="other"></param> public static bool Collision(RectCollider self, ParticleCollider other) { return (self.x <= other.x && other.x <= self.x + self.width) && (self.y <= other.y && other.y <= self.y + self.height); }
public void Update() { CollisionMask = new RectCollider(rect); }
/// <summary> /// Check for a collision between a RayCollider and a RectCollider. /// </summary> /// <param name="self"></param> /// <param name="other"></param> public static bool Collision(RayCollider self, RectCollider other) { return(Collision(other, self)); }
/// <summary> /// Check for a collision between a LineSegmentCollider and a RectCollider. /// </summary> /// <param name="self"></param> /// <param name="other"></param> public static bool Collision(LineSegmentCollider self, RectCollider other) { return(Collision(other, self)); }
public static bool Collision(CircleCollider self, RectCollider other) { double cx = self.x, cy = self.y, r = self.radius; double x = other.x, y = other.y, w = other.width, h = other.height; double rx = x + w / 2, ry = y + h / 2; double x_offset = Math.Abs(cx - rx); double y_offset = Math.Abs(cy - ry); double half_width = w / 2; double half_height = h / 2; if (x_offset > (half_width + r)) return false; else if (y_offset > (half_height + r)) return false; if (x_offset <= half_width) return true; else if (y_offset <= half_height) return true; double deltax = x_offset - half_width; double deltay = y_offset - half_height; double dist = Math.Pow(deltax, 2) + Math.Pow(deltay, 2); return dist <= r * r ? true : false; }