public bool istouching(game_object otherobject) { float distance = (float)Math.Sqrt((otherobject.getx() - this.location.X) * (otherobject.getx() - this.location.X) + (otherobject.gety() - this.location.Y) * (otherobject.gety() - this.location.Y)); return(distance <= this.radius + otherobject.getradius()); }
public PointF pointnearestto(game_object dobject) { PointF nearestpoint = new PointF(); //gives closest x to guy on wall if (dobject.getx() < this.left) { nearestpoint.X = this.left; } else if (dobject.getx() > this.left + this.width) { nearestpoint.X = this.left + this.width; } else { nearestpoint.X = dobject.getx(); } //gives closest y point to guy on wall if (dobject.gety() < this.top) { nearestpoint.Y = this.top; } else if (dobject.gety() > this.top + this.height) { nearestpoint.Y = this.top + this.height; } else { nearestpoint.Y = dobject.gety(); } return(nearestpoint); }
public bool seeobject(game_object g) { PointF objloc = new PointF(); objloc.X = g.getx(); objloc.Y = g.gety(); float xdifference = objloc.X - this.location.X; float ydifference = objloc.Y - this.location.Y; float targetangle = (float)(180f / Math.PI * Math.Atan2((double)-ydifference, (double)xdifference)); if (targetangle < 0) { targetangle += 360; } float maxangle = (this.angle + visionangle); float minangle = (this.angle - visionangle); if (minangle < 0 && targetangle > 270) { minangle += 360; maxangle += 360; } else if (maxangle > 360 && targetangle < 90) { minangle -= 360; maxangle -= 360; } if (targetangle < minangle || targetangle > maxangle) { return(false); } foreach (wall w in MainForm.walllist) { if (game_object.checklineintersection(this.location.X, this.location.Y, objloc.X, objloc.Y, w.left, w.top, w.left + w.width, w.top)) { return(false); } if (game_object.checklineintersection(this.location.X, this.location.Y, objloc.X, objloc.Y, w.left, w.top, w.left, w.top + w.height)) { return(false); } if (game_object.checklineintersection(this.location.X, this.location.Y, objloc.X, objloc.Y, w.left + w.width, w.top + w.height, w.left, w.top + w.height)) { return(false); } if (game_object.checklineintersection(this.location.X, this.location.Y, objloc.X, objloc.Y, w.left + w.width, w.top, w.left + w.width, w.top + w.height)) { return(false); } } return(true); }