Fangames > Game Design
WetWookie's Avoidance Scripts
(1/1)
WetWookie:
I did the thing so you don't have to
All of the draw scripts allow you to 'tag' the objects you create. You can then submit those tags to the manipulation scripts so they only affect the objects you tagged with the same value. For example you can draw a star of cherries with tag of 1 and a circle of cherries with a tag of 2 and then explode all cherries with a tag of 1 while leaving the cherries with a tag of 2 untouched. Also I recommend using objects with the sprite origin set to the center. If you don't things will look weird when you start changing your image_angle.
Drawing Shapes
draw_object_line(x1,y1,x2,y2,NumberOfObjectsInLine,ObjectOrientation,ObjectType,Tag);
Draws a line of objects
ex. draw_object_line(room_width/2-200, room_height/2, room_width/2+200, room_height/2, 10, 0, cherry,1);
(click to show/hide)ObjectOrientation = 0 - Natural sprite angle
ObjectOrientation = 1 - Pointed 'up' along axis of line
ObjectOrientation = 2 - Pointed 'down' along axis of line
Minimum of 2 objects
--- Code: ---//WetWookie's Avoidance Scripts!
x1 = argument0;
y1 = argument1;
x2 = argument2;
y2 = argument3;
NumObjects = argument4;
ObjOrient = argument5; // 0 = up, 1 = out, 2 = in
Object = argument6
OTag = argument7
if NumObjects < 2 {NumObjects = 2;}
if x1 == x2
{
if y2 < y1
{
xt = x1;
yt = y1;
x1 = x2;
y1 = y2;
x2 = xt;
y2 = yt;
}
XStep = (x2 - x1)/(NumObjects-1);
YStep = (y2 - y1)/(NumObjects-1);
tx = x1;
for (ty = y1; ty <= y2; ty += YStep)
{
a = instance_create(tx,ty,Object);
a.tag = OTag;
tx += XStep;
if ObjOrient == 1
{
a.image_angle = point_direction(x1,y1,x2,y2)
} else if ObjOrient == 2
{
a.image_angle = point_direction(x2,y2,x1,y1)
}
}
} else {
if x2 < x1
{
xt = x1;
yt = y1;
x1 = x2;
y1 = y2;
x2 = xt;
y2 = yt;
}
XStep = (x2 - x1)/(NumObjects-1);
YStep = (y2 - y1)/(NumObjects-1);
ty = y1;
for (tx = x1; tx <= x2; tx += XStep)
{
a = instance_create(tx,ty,Object);
a.tag = OTag;
ty += YStep;
if ObjOrient == 1
{
a.image_angle = point_direction(x1,y1,x2,y2)
} else if ObjOrient == 2
{
a.image_angle = point_direction(x2,y2,x1,y1)
}
}
}
--- End code ---
draw_object_circle(CenterX, Centery, Radius, AngleOffset, NumberOfObjects,ObjOrientation,ObjectType,tag);
Draws a circle of objects
ex. draw_object_circle(room_width/2, room_height/2,50,0,10,1,cherry,0);
(click to show/hide)The script will draw the first object at angle 0. If you want to rotate the circle specify an angle in AngleOffset
ObjectOrientation = 0 - Natural sprite angle
ObjectOrientation = 1 - Pointed out of the circle
ObjectOrientation = 2 - Pointed into the circle
Minimum of 4 objects
--- Code: ---//WetWookie's Avoidance Scripts!
CenterX = argument0;
CenterY = argument1;
Radius = argument2;
AngleOffset = argument3;
NumObjects = argument4;
ObjOrient = argument5; // 0 = up, 1 = out, 2 = in
Object = argument6;
OTag = argument7;
if NumObjects < 4 { NumObjects = 4; }
AngleBetween = 360/NumObjects;
for (i = 0; i <= 360 - AngleBetween; i += AngleBetween;)
{
AAngle = i + AngleOffset;
ax = CenterX + cos(degtorad(AAngle)) * Radius;
ay = CenterY - sin(degtorad(AAngle)) * Radius;
a = instance_create(ax,ay,Object);
a.tag = OTag;
if ObjOrient == 1
{
a.image_angle = AAngle - 90;
} else if ObjOrient == 2
{
a.image_angle = AAngle + 90;
}
}
--- End code ---
draw_object_star(CenterX,Centery,Radius,NumArms,ArmLength,AngleOffset,NumObjectsPerArm,ObjOrientation,ObjectType,tag);
Draws a star of objects
ex. draw_object_star(room_width/2, room_height/2,75,5,70,0,7,0,cherry,1);
(click to show/hide)The script will draw the star with a 'crotch' down. If you want to rotate the star specify an angle in AngleOffset
ObjectOrientation = 0 - Natural sprite angle
ObjectOrientation = 1 - Pointed out of the star
ObjectOrientation = 2 - Pointed into the star
Minimum three objects per arm
--- Code: ---//WetWookie's Avoidance Scripts!
CenterX = argument0;
CenterY = argument1;
Radius = argument2;
NumArms = argument3;
ArmLength = argument4;
AngleOffset = argument5;
NumObjectsPerArm = argument6;
ObjOrient = argument7; // 0 = up, 1 = out, 2 = in
Object = argument8;
OTag = argument9;
if NumObjectsPerArm < 3 { NumObjectsPerArm = 3; }
if NumObjectsPerArm mod 2 == 0 { NumObjectsPerArm += 1; }
AngleBetweenArms = 360/NumArms;
AngleBetweenObjects = AngleBetweenArms/NumObjectsPerArm;
DistBetweenArmObjs = ArmLength / floor(NumObjectsPerArm /2);
AngleOffset -= 90 - AngleBetweenObjects / 2; // Naturally angle star 'crotch' down
for (i = 0; i < NumArms; i += 1;)
{
for (j = 0; j < floor(NumObjectsPerArm /2); j +=1)
{
AAngle = i * AngleBetweenArms + j * AngleBetweenObjects + AngleOffset;
ax = CenterX + cos(degtorad(AAngle)) * (Radius + j * DistBetweenArmObjs);
ay = CenterY - sin(degtorad(AAngle)) * (Radius + j * DistBetweenArmObjs);
a = instance_create(ax,ay,Object);
a.tag = OTag;
if ObjOrient == 1
{
a.image_angle = AAngle - 90;
} else if ObjOrient == 2
{
a.image_angle = AAngle + 90;
}
}
AAngle = i * AngleBetweenArms + floor(NumObjectsPerArm /2) * AngleBetweenObjects + AngleOffset;
ax = CenterX + cos(degtorad(AAngle)) * (Radius + ArmLength);
ay = CenterY - sin(degtorad(AAngle)) * (Radius + ArmLength);
a = instance_create(ax,ay,Object);
a.tag = OTag;
if ObjOrient == 1
{
a.image_angle = AAngle - 90;
} else if ObjOrient == 2
{
a.image_angle = AAngle + 90;
}
for (j = floor(NumObjectsPerArm /2) + 1; j < NumObjectsPerArm; j +=1)
{
AAngle = i * AngleBetweenArms + j * AngleBetweenObjects + AngleOffset;
ax = CenterX + cos(degtorad(AAngle)) * (Radius + (NumObjectsPerArm-1 - j) * DistBetweenArmObjs);
ay = CenterY - sin(degtorad(AAngle)) * (Radius + (NumObjectsPerArm-1 - j) * DistBetweenArmObjs);
a = instance_create(ax,ay,Object);
a.tag = OTag;
if ObjOrient == 1
{
a.image_angle = AAngle - 90;
} else if ObjOrient == 2
{
a.image_angle = AAngle + 90;
}
}
}
--- End code ---
draw_object_square(CenterX, CenterY ,SideLength,ObjectsPerSide,AngleOffset,ObjectOrientation,ObjectType,tag);
Draws a square
draw_object_square(room_width/2-150, room_height/2 ,250,10,0,0,cherry,0);
draw_object_square(room_width/2+150, room_height/2 ,200,10,0,0,cherry,1);
draw_object_square(room_width/2+150, room_height/2 ,200,10,45,0,cherry,1);
(click to show/hide)
--- Code: ---//WetWookie's Avoidance Scripts!
CenterX = argument0;
CenterY = argument1;
LengthOfSide = argument2;
NumObjectsPerSide = argument3;
AngleOffset = argument4;
ObjOrient = argument5; // 0 = up, 1 = out, 2 = in
Object = argument6;
OTag = argument7;
if NumObjectsPerSide < 3 { NumObjectsPerSide = 3; }
CenterToCorner = sqrt(2 * sqr(LengthOfSide)) / 2;
CenterToModifiedCorner = sqrt(sqr(LengthOfSide / 2) + sqr((LengthOfSide/2) - LengthOfSide / (NumObjectsPerSide-1)));
ModifiedAngle = radtodeg(arccos((LengthOfSide/2)/CenterToModifiedCorner)) + AngleOffset ;
x1 = CenterX + cos(degtorad(ModifiedAngle)) * CenterToModifiedCorner;
y1 = CenterY - sin(degtorad(ModifiedAngle)) * CenterToModifiedCorner;
x2 = CenterX + cos(degtorad(-45 + AngleOffset)) * CenterToCorner;
y2 = CenterY - sin(degtorad(-45 + AngleOffset)) * CenterToCorner;
draw_object_line(x1,y1,x2,y2,NumObjectsPerSide -1,ObjOrient,Object,OTag);
x1 = CenterX + cos(degtorad(ModifiedAngle + 90)) * CenterToModifiedCorner;
y1 = CenterY - sin(degtorad(ModifiedAngle + 90)) * CenterToModifiedCorner;
x2 = CenterX + cos(degtorad(-45 + AngleOffset + 90)) * CenterToCorner;
y2 = CenterY - sin(degtorad(-45 + AngleOffset + 90)) * CenterToCorner;
draw_object_line(x1,y1,x2,y2,NumObjectsPerSide - 1,ObjOrient,Object,OTag);
x1 = CenterX + cos(degtorad(ModifiedAngle + 180)) * CenterToModifiedCorner;
y1 = CenterY - sin(degtorad(ModifiedAngle + 180)) * CenterToModifiedCorner;
x2 = CenterX + cos(degtorad(-45 + AngleOffset + 180)) * CenterToCorner;
y2 = CenterY - sin(degtorad(-45 + AngleOffset + 180)) * CenterToCorner;
draw_object_line(x1,y1,x2,y2,NumObjectsPerSide - 1,ObjOrient,Object,OTag);
x1 = CenterX + cos(degtorad(ModifiedAngle + 270)) * CenterToModifiedCorner;
y1 = CenterY - sin(degtorad(ModifiedAngle + 270)) * CenterToModifiedCorner;
x2 = CenterX + cos(degtorad(-45 + AngleOffset + 270)) * CenterToCorner;
y2 = CenterY - sin(degtorad(-45 + AngleOffset + 270)) * CenterToCorner;
draw_object_line(x2,y2,x1,y1,NumObjectsPerSide - 1,ObjOrient,Object,OTag);
--- End code ---
Object Manipulation
explode_objects(CenterX, CenterY, ObjectSpeed, ObjectOrientation,ObjectType,tag);
Causes all matching objects to move away from CenterX,CenterY
ex. explode_objects(room_width/2,room_height/2,4,1,cherry,1);
(click to show/hide)ObjectOrientation = 0 - Unchanged sprite angle
ObjectOrientation = 1 - Pointed 'up' along direction of travel
--- Code: ---//WetWookie's Avoidance Scripts!
CenterX = argument0;
CenterY = argument1;
ObjSpeed = argument2;
ObjOrient = argument3; // 0 = unchanged, 1 = out
ObjectType = argument4;
OTag = argument5;
with ObjectType
{
if tag == other.OTag
{
direction = point_direction(other.CenterX, other.CenterY, x, y);
speed = other.ObjSpeed;
if other.ObjOrient == 1
{
image_angle = direction - 90;
}
}
}
--- End code ---
implode_objects(CenterX,CenterY,ObjectSpeed,ObjectOrientation,ObjectType,tag);
Causes all matching objects to move towards CenterX,CenterY
ex. implode_objects(room_width/2,room_height/2,4,1,cherry,1);
(click to show/hide)ObjectOrientation = 0 - Unchanged sprite angle
ObjectOrientation = 1 - Pointed 'up' along direction of travel
--- Code: ---//WetWookie's Avoidance Scripts!
CenterX = argument0;
CenterY = argument1;
ObjSpeed = argument2;
ObjOrient = argument3; // 0 = unchanged, 1 = out
ObjectType = argument4;
OTag = argument5;
with ObjectType
{
if tag == other.OTag
{
direction = point_direction(x,y,other.CenterX, other.CenterY);
speed = other.ObjSpeed;
if other.ObjOrient == 1
{
image_angle = direction - 90;
}
}
}
--- End code ---
group_move_objects(TargetX, TargetY, ObjectSpeed, ObjectOrient, ObjectType, tag)
Moves entire group of objects as one unit toward the target without breaking their shape
ex. group_move_objects(player.x,player.y,4,1,cherry,1);
(click to show/hide)ObjectOrientation = 0 - Unchanged sprite angle
ObjectOrientation = 1 - Pointed 'up' along direction of travel
--- Code: ---//WetWookie's Avoidance Scripts!
TargetX = argument0;
TargetY = argument1;
ObjSpeed = argument2;
ObjOrient = argument3; // 0 = unchanged, 1 = out
ObjectType = argument4;
OTag = argument5;
SumX = 0;
SumY = 0;
CountObj = 0;
with ObjectType
{
other.SumX += x;
other.SumY += y;
other.CountObj += 1;
}
CenterX = SumX / CountObj;
CenterY = SumY / CountObj;
with ObjectType
{
if tag == other.OTag
{
direction = point_direction(other.CenterX, other.CenterY, other.TargetX, other.TargetY);
speed = other.ObjSpeed;
if other.ObjOrient == 1
{
image_angle = direction - 90;
}
}
}
--- End code ---
apply_gravity(GravValue, ImageOrient, ObjectType,tag)
Gives matching objects gravity
apply_gravity(0.4,1,cherry,1);
(click to show/hide)
--- Code: ---//WetWookie's Avoidance Scripts!
ObjGravity = argument0;
ObjOrient = argument1; // 0 = unchanged, 1 = out
ObjectType = argument2;
OTag = argument3;
with ObjectType
{
if tag == other.OTag
{
gravity = other.ObjGravity
}
}
--- End code ---
Feel free to point out errors, request shapes and manipulations and submit your own scripts.
Sudnep:
the god
WetWookie:
added draw square and apply gravity
verveplay:
That's amazing :0 Maybe will use later if i'll need it.
Navigation
[0] Message Index
Go to full version