Been a long time since I've visited this place (or danmakufu, for that matter, so bear with me or don't, your choice).
I decided to start messing with danmakufu for the first time in months and still focusing on spell cards, so I am experimenting with object bullets some more. I had an idea after getting Yuyuko's graphic to function as a boss that involves setting up two different object bullets.
Idea: Fire a bunch of butterflies (obj/first object) randomly that soon come to a stop, have them change angle, then fire a ring of large bullets (obj2/second object). When collision detection is successfully performed between the two objects, the butterflies will begin to accelerate (like a wave [think of the Explosion[#, #, #, #] function] spreading outward and "reanimating" the butterflies).
Problem: The butterflies work fine, but I cannot figure out how to fire more than one obj2 bullet and have the code that permits the collision detection for obj1 at the same time.
E.X. 1:
script_enemy_main{
let count = 0;
let a = 0;
let s = 1;
let color = 223;
let reanimation = 0;
let obj2 = Obj_Create(OBJ_SHOT);
(then after @Finalize)
task reanimate(speed, angle) {
let obj = Obj_Create(OBJ_SHOT);
let a = rand(-5, 5);
let objreanimation = 0;
Obj_SetPosition(obj, GetX, GetY);
Obj_SetAngle(obj, angle);
Obj_SetSpeed(obj, speed);
ObjShot_SetGraphic(obj, 208);
ObjShot_SetDelay(obj, 5);
ObjShot_SetBombResist(obj, true);
Obj_SetCollisionToObject(obj, true);
Obj_SetCollisionToPlayer(obj, true);
Obj_SetAlpha(obj, 255);
while(Obj_BeDeleted(obj)==false){
let objspeed=Obj_GetSpeed(obj);
if(objspeed > 0){Obj_SetSpeed(obj, objspeed - 0.05);}
if(objspeed < 0){Obj_SetSpeed(obj, 0);}
if(reanimation == 1){
Obj_SetAngle(obj, Obj_GetAngle(obj) + a);
}
if(Collision_Obj_Obj(obj, obj2)){
objreanimation = 2;
}
if(objreanimation == 2 && objspeed < 2){
ObjShot_SetGraphic(obj, 209);
Obj_SetSpeed(obj, objspeed + 0.005);
}
yield;
}
}
task reanimateshot(speed, angle) {
let obj2 = Obj_Create(OBJ_SHOT);
Obj_SetPosition(obj2, GetX, GetY);
Obj_SetAngle(obj2, angle);
Obj_SetSpeed(obj2, speed);
ObjShot_SetGraphic(obj2, 236);
ObjShot_SetDelay(obj2, 5);
ObjShot_SetBombResist(obj2, true);
Obj_SetCollisionToObject(obj2, true);
Obj_SetCollisionToPlayer(obj2, false);
Obj_SetAlpha(obj2, 255);
while(Obj_BeDeleted(obj2)==false){
yield;
}
}
I have learned that adding let obj2 = Obj_Create(OBJ_SHOT); into the actual object's task (in this case, reanimateshot) just overwrites the original let obj2 = Obj_Create(OBJ_SHOT);. This lets the script continue normally, but the object collision between obj and obj2 does not happen because obj2 is redefined in its own task and no longer associated with obj1. This is fine, but then I try this:
E.X. 2:
let obj2 = Obj_Create(OBJ_SHOT);
(then after @Finalize)
task reanimateshot(speed, angle) {
Obj_SetPosition(obj2, GetX, GetY);
Obj_SetAngle(obj2, angle);
Obj_SetSpeed(obj2, speed);
ObjShot_SetGraphic(obj2, 236);
ObjShot_SetDelay(obj2, 5);
ObjShot_SetBombResist(obj2, true);
Obj_SetCollisionToObject(obj2, true);
Obj_SetCollisionToPlayer(obj2, false);
Obj_SetAlpha(obj2, 255);
while(Obj_BeDeleted(obj2)==false){
yield;
}
}
(then in the main task)
if(count == 360){
a = rand(0, 360);
loop(20){
reanimateshot(3, a);
a += 360/20;
}
}
So the task [reanimate] now recognizes obj2 properly which is half of what I want. The other half of the problem still unsolved is that obj2 does not loop more than once (the complete opposite of the previous example), so rather than having twenty bubbles moving and activating all of the butterflies, there is only one bubble that activates a single line of butterflies. How can I loop obj2 so that the twenty bubbles that I want all appear while retaining the collision detection with obj1? I do not want to end up having to create twenty separate object bullets (x20 more lines) just to complete that ring of bubbles and trigger the collision detection at the same time. It is probably right under my nose, but isn't there a simpler way to do it?