Orbiting Cherries
Something I use myself for making stuff orbit around a point or an object.
Example Use
scrMakeCircle(x,y,random(360),4,0,objCherry,id)
with(objCherry) { if tag = other.id {
scrMakeOrbit(other.id,x,y,1,0,32,false,false,1,true);
sprite_index = sprCherry;
} }
Create objCherry
//Orbit Variables
orbit = false
orbit_obj = 0;
orbit_x = 0;
orbit_y = 0;
orbit_ang = 0; // not used in scrMakeOrbit
orbit_rad = 0; // not used in scrMakeOrbit
orbit_rad_dev = 0;
orbit_rad_min = 0;
orbit_rad_max = 0;
orbit_rad_increase = 0; // not used in scrMakeObject
orbit_flux = 0;
orbit_flux_smth = 0;
orbit_flux_smth_counter = 0; // not used in scrMakeOrbit
orbit_sp = 0;
orbit_clockwise = 0;
Script scrMakeOrbit
///scrMakeOrbit([-100;id],x,y,rad_dev,rad_min,rad_max,flux,flux_smooth,speed,clockwise)
/* argument Information
orbit_obj [-100,id]
This determines wether the objects will spin around a sepcific object, or at some point.
orbit_x [n]
The x posistion for orbiting.
orbit_y [n]
The y posistion for orbiting.
orbit_rad_dev [n]
The speed at which the orbiting objects will expand / contract. [Does not apply to smooth fluctuation.]
orbit_rad_min [n]
The minimum radius the orbiting objects can have.
orbit_rad_max [n]
The maximum radius the orbiting objects can have.
orbit_flux [true/false]
Whether or not the orbiting object's radius will fluctuate.
orbit_flux_smth [true/false]
Whether or not the orbiting object's radius fluctuation will be smooth or not.
orbit_speed [n]
The speed at which the orbiting objects rotate around the object or point.
orbit_clockwise [true/false]
Does it rotate clockwise, or counter clockwise?
*/
//Apply values to variables within objCherry
if (x = xstart && y = ystart) { // incriment out if at starting pos [doesn't work if at start pos]
speed = 1;
x += hspeed;
y += vspeed;
speed = 0;
}
orbit = true // enable orbit flag
// pass variables:
if argument0 != -100 { orbit_obj = argument0; } else { orbit_obj = -100 };
orbit_x = argument1
orbit_y = argument2
orbit_rad_dev = argument3
orbit_rad_min = argument4
orbit_rad_max = argument5
orbit_flux = argument6
orbit_flux_smth = argument7
orbit_sp = argument8
orbit_clockwise = argument9
// calculate ang and radius
if orbit_obj != -100 {
orbit_ang = point_direction(orbit_obj.x,orbit_obj.y,x,y)-180
orbit_rad = distance_to_point(orbit_obj.x,orbit_obj.y)
} else {
orbit_ang = point_direction(orbit_x,orbit_y,x,y)
orbit_rad = distance_to_point(orbit_x,orbit_y)
}
// check if increase or decrease
if orbit_rad > orbit_rad_max {
orbit_rad_inc = false
} else {
orbit_rad_inc = true
}
Script scrOrbit [Goes in Step Event of objCherry]
if (orbit == true) {
if (instance_exists(orbit_obj) && orbit_obj != -100) {
with(orbit_obj) { // grab orbitX & orbitY from orbit_obj
other.orbit_x = x; other.orbit_y = y;
}
} else if (orbit_obj != -100) {
orbit = false;
}
// rad calculation
if (orbit_flux) { // if flux enabled
if (orbit_flux_smth) { // smth
orbit_flux_smth_counter += orbit_rad_dev; // increase counter by script given val
var orbit_smth_limit = (orbit_rad_max - orbit_rad_min)/2; // define limits for smth
orbit_rad = (orbit_smth_limit)*cos(degtorad(orbit_flux_smth_counter))+orbit_smth_limit
} else { // not smth
if (orbit_rad_inc) { // If orbit_rad_inc flag is true
orbit_rad += orbit_rad_dev // Increase orbit_rad by fixed val
} else {
orbit_rad -= orbit_rad_dev // Decrease orbit_rad by fixed val
}
if (orbit_rad > orbit_rad_max) { orbit_rad = orbit_rad_max; orbit_rad_inc = false;} // set to limit + set flag
if (orbit_rad < orbit_rad_min) { orbit_rad = orbit_rad_min; orbit_rad_inc = true;} // set to limit + set flag
}
} else { // no fluctuation [go to orbit_rad_max]
if (orbit_rad < orbit_rad_max) { orbit_rad += orbit_rad_dev; } // you're not at max. keep going
if (orbit_rad > orbit_rad_max) { orbit_rad = orbit_rad_max; } // you're at max congrats
}
if (orbit_clockwise) { // clockwise
orbit_ang += orbit_sp; // incriment ang
} else { // counterclockwise
orbit_ang -= orbit_sp; // incriment ang
}
// make the shit spin yo
x = orbit_x + orbit_rad * cos(orbit_ang * pi / 180);
y = orbit_y - orbit_rad * sin(orbit_ang * pi / 180);
}