ENIGMA Forums
Contributing to ENIGMA => Function Peer Review => Topic started by: RetroX on March 12, 2011, 10:59:21 am
-
Because he didn't post them in their own topic, and I can't move topics:
//bool place_snapped(double hsnap,double vsnap)
bool place_snapped(double hsnap,double vsnap) {
return (bool)(X == X%hsnap) && (Y == Y%vsnap);
}
//int move_random(double hsnap,double vsnap)
int move_random(double hsnap,double vsnap) {
X = floor(random(room_width)/hsnap)*hsnap;
Y = floor(random(room_height)/vsnap)*vsnap;
return (int)0;
}
//int move_snap(double hsnap,double vsnap)
int move_snap(double hsnap,double vsnap) {
X = floor(X/hsnap)*hsnap;
Y = floor(Y/vsnap)*vsnap;
return (int)0;
}
//int move_wrap(double hor,double vert,double margin)
int move_wrap(double hor,double vert,double margin) {
//not sure whether two IFs are faster than one big calculation in a single IF
if (hor) {
if (X < -margin || X > room_width+margin) {
X = -(X-room_width);
}
}
if (vert) {
if (Y < -margin || Y > room_height+margin) {
Y = -(Y-room_height);
}
}
return (int)0;
}
//int move_towards_point(double x,double y,double sp)
int move_towards_point(double x,double y,double sp) {
DIRECTION = point_direction(X,Y,x,y);
SPEED = sp;
return (int)0;
}
Note that these functions have already been committed (in working forms), but I'll post them anyways:
//double distance_to_point(double x,double y)
double distance_to_point(double x,double y) {
return (double)point_distance(median(BBOX_LEFT,x,BBOX_RIGHT),median(BBOX_TOP,y,BBOX_BOTTOM),x,y);
}
//double distance_to_object(int obj)
double distance_to_object(int obj) {
double _edgeX,_edgeY;
_edgeX = median(BBOX_LEFT,obj.X,BBOX_RIGHT);
_edgeY = median(BBOX_TOP,obj.Y,BBOX_BOTTOM);
if (_edgeX > obj.BBOX_LEFT && _edgeX < obj.BBOX_RIGHT && _edgeY > obj.BBOX_TOP && _edgeY < obj.BBOX_BOTTOM) {
return (double)0;
}
return (double)point_distance(_edgeX,_edgeY,median(obj.BBOX_LEFT,X,obj.BBOX_RIGHT),median(obj.BBOX_TOP,Y,obj.BBOX_BOTTOM));
}
-
Err, thanks for the topic... >_<
Also, I was already aware of the last two, but I posted them anyway.
-
Yeah, but I figured that I'd let everyone who was viewing the topic know. I felt like it would have been kind of rude to just omit them altogether.