It took me long enough, but I got something that does what I want it to do, it's still got one problem though, framerate. Essentially I'd like this code to run at least 400% faster than it does now. Any tips on how?;
This code is in a separate file loaded using #include_script.
In addition, in @MainLoop, there is one statement of RedAimingShots(f).
There's also an f++ in MainLoop, of course.
Currently, the code works perfectly as far as the bullet pattern is concerned.
Currently, the code slows down even a decent computer to a crawl.
task CreateShotRed(let x, let y, let speed, let angle)
{
let counter =0;
let objr = Obj_Create(OBJ_SHOT);
ArrayShotRed = ArrayShotRed ~ [objr];
Obj_SetX(objr, x);
Obj_SetY(objr, y);
Obj_SetSpeed(objr, speed);
Obj_SetAngle(objr, angle);
ObjShot_SetGraphic(objr, RED02);
while( !Obj_BeDeleted(objr))
{
if(counter > (GetCenterX()*speed*cos((angle))-x*speed*cos
((angle))+GetCenterY()*speed*sin((angle))-y*speed*sin((angle))+0.5*
(speed^2*(8*GetCenterX()*x-4*(x^2+y*(-2* GetCenterY()+y))+4*((GetCenterX()-
x)*cos((angle))+(GetCenterY()-y)*sin((angle)))^2))^0.5)/speed^2) {
ObjShot_Delete(objr);
break;
}
counter++;
yield;
}
let iterator = 0;
loop(length(ArrayShotRed))
{
if(ArrayShotRed[iterator] == objr)
{
ArrayShotRed = erase(ArrayShotRed, iterator);
break;
}
iterator++;
}
}
task CollisionShotsBlue(let x, let y, let speed, let angle)
{
let count=0;
let objb = Obj_Create(OBJ_SHOT);
Obj_SetX(objb, x);
Obj_SetY(objb, y);
Obj_SetSpeed(objb, speed);
Obj_SetAngle(objb, angle);
ObjShot_SetGraphic(objb, BLUE01);
ObjShot_SetDelay(objb, 0);
while( !Obj_BeDeleted(objb))
{
let iteratortwo=0;
loop(length(ArrayShotRed))
{
if(Collision_Obj_Obj(ArrayShotRed[iteratortwo],
objb) == true)
{
CreateShotA(100, x + cos(angle) * speed * count, y +
sin(angle) * speed * count, 0);
SetShotDataA(100, 0, speed * 2, -angle, 0, 0, 20,
RED01);
FireShot(100);
Obj_Delete(objb);
}
iteratortwo++;
}
if(count == 300)
{
ObjShot_FadeDelete(objb);
break;
}
count++;
yield;
}
}
task RedAimingShots(let ftwo) {
ascent(i in 0..36)
{
if(ftwo == 7860 + 60 * i)
{
CreateShotA(2, 224, 30, 0);
SetShotDataA(2, 0, 3.1415 * 210 / 52.5, 0, 180 / 52.5, 0, 20,
RED03);
SetShotDataA(2, 60, NULL, NULL, 0, 0, 20, RED03);
FireShot(2);
CreateShotA(2, 224, 30, 0);
SetShotDataA(2, 0, 3.1415 * 210 / 52.5, 180, -180 / 52.5, 0, 20,
RED03);
SetShotDataA(2, 60, NULL, NULL, 0, 0, 20, RED03);
FireShot(2);
}
ascent(k in 1..4) {
if(ftwo == 7860 + 60 * i + 15 * k) {
let Rthree = ((GetPlayerX - GetCenterX - 210 * sin(51.428 * k))^2 +
(GetPlayerY - GetCenterY + 210 * cos(51.428 * k))^2)^0.5;
let angthree = atan2((GetPlayerY - GetCenterY + 210 * cos(51.428 *
k)),(GetPlayerX - GetCenterX - 210 * sin(51.428 * k)));
CreateShotRed(224 + 210 * cos(51.428 * k - 90), 240 + 210 * sin
(51.428 * k - 90), Rthree / 90, angthree);
let Rthree = ((GetPlayerX - GetCenterX + 210 * sin(51.428 * k))^2 +
(GetPlayerY - GetCenterY + 210 * cos(51.428 * k))^2)^0.5;
let angthree = atan2((GetPlayerY - GetCenterY + 210 * cos(51.428 *
k)),(GetPlayerX - GetCenterX + 210 * sin(51.428 * k)));
CreateShotRed(224 - 210 * cos(51.428 * k - 90), 240 + 210 * sin
(51.428 * k - 90), Rthree / 90, angthree);
ascent(j in 0..90) {
CollisionShotsBlue(GetCenterX, GetCenterY, 1, 4 * j + k + atan2
((GetPlayerY - GetCenterY),(GetPlayerX - GetCenterX)))
}
}
}
}
}
Essentially, it uses up two arrays. Had a third array but I scrapped that idea (which was giving the angle of the blue bullets turned red the angle of the bullet that had caused that +- rand10), and simply changed it to reverse angle. The latter didn't make much of a visual diffrence but it saved me one array.
anyways, I went with larger bullets (90) and had the whole thing erase unneeded spaces from both two object bullet groups. (I.e. all bullets going outside of a circle with radius 300 or so from the centerX, centerY space are checked for deletion each frame).
As for the large formulae, here's an idea of what they do.
" if(count == 300)"
300: The speed is 1, so that puts it outside of the circle.
((GetPlayerX - GetCenterX - 210 * sin(51.428 * k))^2 + (GetPlayerY - GetCenterY + 210 * cos(51.428 * k))^2)^0.5
Basically gives the distance between each k-th spawn point for the reds and the player.
atan2((GetPlayerY - GetCenterY + 210 * cos(51.428 * k)),(GetPlayerX - GetCenterX - 210 * sin(51.428 * k)));
Same, Angle.
if(counter > (GetCenterX()*speed*cos((angle))-x*speed*cos((angle))+GetCenterY()*speed*sin((angle))-y*speed*sin((angle))+0.5*(speed^2*(8*GetCenterX()*x-4*(x^2+y*(-2* GetCenterY()+y))+4*((GetCenterX()-x)*cos((angle))+(GetCenterY()-y)*sin((angle)))^2))^0.5)/speed^2)
Well, um... this basically calculates how long a red bullet will at most need to stay in the array. I mean, it calculates the time it would take for a red bullet to move outside of the boundary set by my circle. It's a result from a quadratic polynomial in 't'.
As for a potential hint to the solution, it seems that the speed of this script is directly proportional to:
- The amount of blue bullets onscreen ==> This is a good sign, it means that the evaluations whether or not a bullet needs to be removed to save processor power are not hogging said processor power.
- The amount of Red Bullets onscreen ==> once again, same reason.
I'm still a bit stuck here what else I can do to make it run at 60fps flat without having to change the pattern in any way.