@if exp="typeof(global.skyrotateflying_object)=='undefined'"
@iscript
class RotateFlyingGrain{
var window,owner;
var cx,cy;
var sx,sy;
var dx,dy;
var p,s;
var speed,rspeed,pspeed,sspeed;
var accel,raccel,paccel,saccel;
var templayer;
var targetlayer;
var a00,a01,a10,a11,ax,ay;
var piccount;
var angle;
var scale=0,pscale=0,sscale=0;
var appear;
var k=1;
var east=false,south=false,west=false,north=false;
var movedp;
var angle;
var vanishing,hasbeencounted;
function RotateFlyingGrain(window,owner){
this.window=window;
this.owner=owner;
}
function setOption(elm){
piccount=0;
appear=false;
vanishing=false;
hasbeencounted=false;
if(elm.storage!==void){
for(var i=0;;i++){
if(Storages.isExistentStorage(elm.storage+"_"+i+".png"))
piccount++;
else
break;
}
}
else{
for(var i=0;;i++){
if(Storages.isExistentStorage("flying_object_"+i+".png"))
piccount++;
else
break;
}
}
templayer=new Layer(window,window.primaryLayer);
if(elm.storage!==void)
templayer.loadImages(elm.storage+"_"+intrandom(0,piccount-1)+".png");
else
templayer.loadImages("flying_object_"+intrandom(0,piccount-1)+".png");
targetlayer=new Layer(window,window.primaryLayer);
targetlayer.setPos(0,0,window.primaryLayer.width,window.primaryLayer.height);
if(elm.index!==void)
targetlayer.absolute=elm.index;
else
targetlayer.absolute=2000000-1;
if(east){
sx=window.primaryLayer.width;
sy=window.primaryLayer.height*Math.random();
}
if(south){
sx=window.primaryLayer.width*Math.random();
sy=window.primaryLayer.height;
}
if(west){
sx=-templayer.imageWidth;
sy=window.primaryLayer.height*Math.random();
}
if(north){
sx=window.primaryLayer.width*Math.random();
sy=-templayer.imageHeight;
}
cx=templayer.imageWidth/2;
cy=templayer.imageHeight/2;
speed=+elm.speed+elm.speedoffset*Math.random();
accel=+elm.accel;
rspeed=+elm.rspeed+elm.rspeedoffset*Math.random();
raccel=+elm.raccel;
p=+elm.p;
movedp=p;
pspeed=+elm.pspeed+elm.pspeedoffset*Math.random();
paccel=+elm.paccel;
s=+elm.s;
sspeed=+elm.sspeed+elm.sspeedoffset*Math.random();
saccel=+elm.saccel;
angle=+elm.angle;
targetlayer.visible=true;
targetlayer.face = dfAlpha;
targetlayer.type = ltAlpha;
}
function setPosition(){
if(vanishing && scale==0){
targetlayer.opacity=0;
if(!hasbeencounted) owner.vanishcount++,hasbeencounted=true;
return;
}
var sc=scale*(scale-1)/2;
var moveds=s+sspeed*sscale+sscale*(sscale-1)/2.0*saccel;
var movedr=(rspeed*scale+sc*raccel)/180.0*Math.PI;
var movedx=sx+(speed*scale+sc*accel)*Math.cos(angle/180*Math.PI);
var movedy=sy+(speed*scale+sc*accel)*Math.sin(angle/180*Math.PI);
if(owner.totaltime<0 && scale==0){
stopMove();
return;
}
if((movedx>window.primaryLayer.width) || (movedx<-templayer.imageWidth) || (movedy>window.primaryLayer.height) || (movedy<-templayer.imageHeight)){
if(east)
sy=window.primaryLayer.height*Math.random();
if(south)
sx=window.primaryLayer.width*Math.random();
if(west)
sy=window.primaryLayer.height*Math.random();
if(north)
sx=window.primaryLayer.width*Math.random();
scale=0 if !owner.keepaccel;
sscale=0 if !owner.keepsaccel;
}
else{
scale++ if !owner.keepaccel;
sscale++ if !owner.keepsaccel;
}
if(owner.keepaccel) scale++;
if(owner.keepsaccel) sscale++;
a00=moveds*Math.cos(movedr);
a01=moveds*Math.sin(movedr);
a10=-moveds*Math.sin(movedr);
a11=moveds*Math.cos(movedr);
ax=a00*-cx+a01*-cy+movedx+cx;
ay=a10*-cx+a11*-cy+movedy+cy;
targetlayer.fillRect(0,0,targetlayer.imageWidth,targetlayer.imageHeight,0);
targetlayer.affineCopy(templayer,0,0,templayer.imageWidth,templayer.imageHeight,true,a00,a10,a01,a11,ax,ay,stNearest);
}
function setOpacity(){
if(vanishing && scale==0){
targetlayer.opacity=0;
return;
}
if(owner.totaltime<0 && scale==0){
return;
}
movedp+=int(k*pspeed+k*pscale*paccel);
if(movedp>255){
movedp=255-movedp%256;
k=-1;
}
if(movedp<0){
movedp=-movedp%256;
k=1;
}
targetlayer.opacity=movedp;
pscale++;
}
function stopMove(){
invalidate templayer if templayer!==void;
invalidate targetlayer if targetlayer!==void;
templayer=targetlayer=void;
}
}
class SkyRotateFlying extends KAGPlugin{
var window;
var num;
var flyinggrainx=[];
var flyinggrainy=[];
var dic=%[];
var angleoffset;
var interval;
var timer,totaltime;
var appearprob;
var vanishcount;
var keepaccel,keepsaccel;
function SkyRotateFlying(window){
super.KAGPlugin();
this.window=window;
}
function setOption(elm){
vanishcount=0;
if(elm.keepaccel!==void)
keepaccel=elm.keepaccel;
else
keepaccel=false;
if(elm.keepsaccel!==void)
keepsaccel=elm.keepsaccel;
else
keepsaccel=false;
if(elm.storage!==void)
dic.storage=elm.storage;
if(elm.index!==void)
dic.index=elm.index;
if(elm.appearprob!==void)
appearprob=+elm.appearprob;
else
appearprob=0.1;
if(elm.interval!==void)
interval=+elm.interval;
else
interval=50;
if(elm.speed!==void)
dic.speed=+elm.speed;
else
dic.speed=20;
if(elm.speedoffset!==void)
dic.speedoffset=+elm.speedoffset;
else
dic.speedoffset=0;
if(elm.accel!==void)
dic.accel=+elm.accel;
else
dic.accel=0.01;
if(elm.rspeed!==void)
dic.rspeed=+elm.rspeed;
else
dic.rspeed=0;
if(elm.rspeedoffset!==void)
dic.rspeedoffset=+elm.rspeedoffset;
else
dic.rspeedoffset=0;
if(elm.raccel!==void)
dic.raccel=+elm.raccel;
else
dic.raccel=0;
if(elm.p!==void)
dic.p=+elm.p;
else
dic.p=255;
if(elm.pspeedoffset!==void)
dic.pspeedoffset=+elm.pspeedoffset;
else
dic.pspeedoffset=0;
if(elm.pspeed!==void)
dic.pspeed=+elm.pspeed;
else
dic.pspeed=0;
if(elm.paccel!==void)
dic.paccel=+elm.paccel;
else
dic.paccel=0;
if(elm.s!==void)
dic.s=+elm.s;
else
dic.s=1;
if(elm.sspeed!==void)
dic.sspeed=+elm.sspeed;
else
dic.sspeed=0;
if(elm.sspeedoffset!==void)
dic.sspeedoffset=+elm.sspeedoffset;
else
dic.sspeedoffset=0;
if(elm.totaltime!==void)
totaltime=+elm.totaltime;
else
totaltime=void;
if(elm.angleoffset!==void)
angleoffset=+elm.angleoffset;
else
angleoffset=0;
}
function startFlying(elm){
var angle;
if(elm.num!==void)
num=+elm.num;
else
num=10;
for(var i=0;i<num;i++){
flyinggrainx[i]=new RotateFlyingGrain(window,this);
flyinggrainy[i]=new RotateFlyingGrain(window,this);
setOption(elm);
if(elm.angle!==void)
angle=int(+elm.angle+(Math.random()-0.5)*2*angleoffset)%360;
else
angle=int((Math.random()-0.5)*2*angleoffset)%360;
if(angle<0)
angle+=360;
dic.angle=angle;
if(angle==0){
flyinggrainx[i].west=true;
flyinggrainy[i].west=true;
}
if(angle>0 && angle<90){
flyinggrainx[i].west=true;
flyinggrainy[i].north=true;
}
if(angle==90){
flyinggrainx[i].north=true;
flyinggrainy[i].north=true;
}
if(angle>90 && angle<180){
flyinggrainx[i].east=true;
flyinggrainy[i].north=true;
}
if(angle==180){
flyinggrainx[i].east=true;
flyinggrainy[i].east=true;
}
if(angle>180 && angle<270){
flyinggrainx[i].east=true;
flyinggrainy[i].south=true;
}
if(angle==270){
flyinggrainx[i].south=true;
flyinggrainy[i].south=true;
}
if(angle>270 && angle<360){
flyinggrainx[i].west=true;
flyinggrainy[i].south=true;
}
flyinggrainx[i].setOption(dic);
flyinggrainy[i].setOption(dic);
}
timer=new Timer(timeevent,"");
timer.enabled=true;
timer.interval=interval;
}
function timeevent(){
for(var i=0;i<num;i++){
if(!flyinggrainx[i].appear)
flyinggrainx[i].appear=true if Math.random()<appearprob;
else{
flyinggrainx[i].setPosition();
flyinggrainx[i].setOpacity();
}
if(!flyinggrainy[i].appear)
flyinggrainy[i].appear=true if Math.random()<appearprob;
else{
flyinggrainy[i].setPosition();
flyinggrainy[i].setOpacity();
}
}
if(vanishcount>=num*2){
timer.enabled=false;
stopFlying();
}
totaltime-=interval if totaltime!==void;
}
function setVanish(){
for(var i=0;i<num;i++){
flyinggrainx[i].vanishing=true;
flyinggrainy[i].vanishing=true;
}
}
function stopFlying(){
for(var i=0;i<num;i++){
flyinggrainx[i].stopMove();
invalidate flyinggrainx[i] if flyinggrainx[i]!==void;
flyinggrainy[i].stopMove();
invalidate flyinggrainy[i] if flyinggrainy[i]!==void;
}
invalidate flyinggrainx if flyinggrainx!==void;
invalidate flyinggrainy if flyinggrainy!==void;
flyinggrainx=void;
flyinggrainy=void;
flyinggrainx=[];
flyinggrainy=[];
invalidate timer;
timer=void;
invalidate dic if dic!==void;
dic=void;
dic=%[];
}
}
kag.addPlugin(global.skyrotateflying_object=new SkyRotateFlying(kag));
@endscript
@macro name=rflying
@eval exp="global.skyrotateflying_object.startFlying(mp)"
@endmacro
@macro name=stoprflying
@eval exp="global.skyrotateflying_object.stopFlying()"
@endmacro
@macro name=vanishrflying
@eval exp="global.skyrotateflying_object.setVanish()"
@endmacro
@macro name=leafrflying
@rflying storage=%storage|leaf num=%num angle=%angle|30.0 angleoffset=%angleoffset|20.0 speedoffset=%speedoffset|20.0 speed=%speed|5.0 accel=%accel|0.05 rspeedoffset=%rspeedoffset|12.0 rspeed=%rspeed|1.0 raccel=%raccel totaltime=%totaltime|20000 appearprob=%appearprob
@endmacro
@macro name=starrflying
@rflying storage=%storage|star num=%num angle=%angle|30.0 angleoffset=%angleoffset|20.0 speedoffset=%speedoffset|20.0 speed=%speed|5.0 accel=%accel|0.05 pspeedoffset=%pspeedoffset|60.0 pspeed=%pspeed|40.0 paccel=%paccel totaltime=%totaltime|20000 appearprob=%appearprob
@endmacro
@macro name=rjump
@rflying storage=%storage|ball num=%num angle=%angle|-90 speedoffset=%speedoffset|30.0 speed=%speed|10.0 accel=%accel|-1 rspeedoffset=%rspeedoffset|12.0 rspeed=%rspeed|1.0 paccel=%paccel totaltime=%totaltime|20000 appearprob=%appearprob
@endmacro
@return