- Code: Select all
/*
//---------------//
//Balance numbers, finds the center value between 2 values.
// $Bal
//
//Toggle between 0 and 1
// $tog
*/
int $bal(int val, int val2)
{
int f_val=(val2+val)/2;
return f_val;
}
int $tog(int value)
{
return !(value);
}
//Place actor inbetween 2 other actors, requires $bal
void $center_objects(char *actor1, char*actor2)
{
Actor *a=getclone(actor1);
Actor *a2=getclone(actor2);
int Valuex;
int Valuey;
Valuex=$bal(a->x, a2->x)-width/2;
Valuey=$bal(a->y, a2->y)-height/2;
x=Valuex;
y=Valuey;
}
void $center_objects_x(char *actor1, char*actor2)
{
Actor *a=getclone(actor1);
Actor *a2=getclone(actor2);
int Valuex;
Valuex=$bal(a->x, a2->x)-width/2;
x=Valuex;
}
void $center_objects_y(char *actor1, char*actor2)
{
Actor *a=getclone(actor1);
Actor *a2=getclone(actor2);
int Valuey;
Valuey=$bal(a->y, a2->y)-height/2;
y=Valuey;
}
//defined a grid system, in case you want to align thins using a grid.
int $grid(int value, int grid_size)
{
return value*grid_size;
}
The $ is an insignia.
Example:
Using $center_objects("left", "right"); you can center objects between object 1, and object 2, like you see in the image. the + will always be in the middle of the two.
$bal(number1, number2) gets the half-mark between the two numbers, as you can see in the image.
Simple things but useful.