2007-6-18 14:20
karryngai
在空中僵硬飞扬的米粒们......
此东西是skyrotateflying的简化版,不能变形,不能旋转,因此大量地节省了速度和空间
粒子数上百个都没有关系,此东西的存在有很大价值
@lflying storage=leaf num=10 angle=30 angleoffset=30 speedoffset=20 speed=5 accel=0.05 pspeedoffset=20 pspeed=15 paccel=5 totaltime=10000 interval=50 appearprob=0.01 index=3000000
storage 图像名,如storage=leaf,指的是leaf_0.png,leaf_1.png,leaf2.png.....一组的图像,程序会随机抽取它们中的一个作为粒子
num 出现的粒子数目,其实粒子数目是2*num,因为里面设置了两组粒子,用来解决角度的问题,预设是10,设置20个电脑已经开始卡了= =
angle 粒子飞出来的角度,angle=30就是指粒子从右上角向下走30度的位置飞出,预设是0
angleoffset 这个东西能打乱各个粒子飞出来的角度,是原来角度上的偏移值,如angleoffset=30,就是指粒子有可能从30-30=0的角度或30+30=60的角度飞出来,设置得很大的话,粒子的混乱性越明显,个人觉得这是个好东西,预设是0
speedoffset 速度的偏移值,和angleoffset的道理一样,让粒子出现速度上的不同,预设是0
speed 粒子的飞行速度,预设是20
accel 加速度,预设是0.01
pspeedoffset 透明度的偏移值,预设是0
pspeed 透明度,预设是255
paccel 透明度变化的加速度,预设是0
totaltime 总飞行的时间,预设是12000,单位是毫秒
interval 变换的单位时间,预设是50,最好不要改动
appearprob 出现的概率,指粒子不会全部同时出现,而是按照一定的概率出现,1的话就是必然出现,预设是0.1
index 粒子所在层的absolute,预设是2000000
@stoprflying
强制停止飞行,事实设定了totaltime后,粒子就会在那时间后消失在看不见的地方,绝对不会有停滞的画面出现
所以如果没有什么必要,可以不使用stopflying,占用内存会自动清除
@leaflflying
直接贴封装方式
@macro name=leaflflying
@lflying 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 totaltime=%totaltime|20000 appearprob=%appearprob
@endmacro
模拟的是树叶从30度角的地方飞出来旋转的情形
@starlflying
直接贴封装方式
@macro name=starlflying
@lflying 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
模拟的是星星一闪一闪地移动的情形,用这个方法最好了,如果不需要旋转效果,不要用skyrotateflying里的
@ljump
直接贴封装方式
@macro name=ljump
@lflying storage=%storage|ball num=%num angle=%angle|-90 speedoffset=%speedoffset|30.0 speed=%speed|10.0 accel=%accel|-1 totaltime=%totaltime|20000 appearprob=%appearprob
@endmacro
摸拟的是球从屏幕下部拥出来,减速跳出最高处后又加速落下来的情形
如果把球改成水珠的话,就会变成涌泉一样的壮观情景
2007-6-18 14:21
karryngai
@if exp="typeof(global.skylinearflying_object)=='undefined'"
@iscript
class LinearFlyingGrain{
var window,owner;
var cx,cy;
var sx,sy;
var dx,dy;
var p;
var speed,pspeed;
var accel,paccel;
var targetlayer;
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;
function LinearFlyingGrain(window,owner){
this.window=window;
this.owner=owner;
}
function setOption(elm){
piccount=0;
appear=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;
}
}
targetlayer=new Layer(window,window.primaryLayer);
if(elm.storage!==void)
targetlayer.loadImages(elm.storage+"_"+intrandom(0,piccount-1)+".png");
else
targetlayerlayer.loadImages("flying_object_"+intrandom(0,piccount-1)+".png");
targetlayer.setSizeToImageSize();
if(elm.index!==void)
targetlayer.absolute=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=-targetlayer.imageWidth;
sy=window.primaryLayer.height*Math.random();
}
if(north){
sx=window.primaryLayer.width*Math.random();
sy=-targetlayer.imageHeight;
}
speed=+elm.speed+elm.speedoffset*Math.random();
accel=+elm.accel;
p=+elm.p;
movedp=p;
pspeed=+elm.pspeed+elm.pspeedoffset*Math.random();
paccel=+elm.paccel;
angle=+elm.angle;
targetlayer.setPos(sx,sy);
targetlayer.visible=true;
targetlayer.face = dfAlpha;
targetlayer.type = ltAlpha;
}
function setPosition(){
var sc=scale*(scale-1)/2;
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<-targetlayer.imageWidth) || (movedy>window.primaryLayer.height) || (movedy<-targetlayer.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;
}
else
scale++;
sscale++;
targetlayer.setPos(movedx,movedy);
}
function setOpacity(){
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 targetlayer if targetlayer!==void;
targetlayer=void;
}
}
class SkyLinearFlying extends KAGPlugin{
var window;
var num;
var flyinggrainx=[];
var flyinggrainy=[];
var dic=%[];
var angleoffset;
var interval;
var timer,totaltime;
var appearprob;
function SkyLinearFlying(window){
super.KAGPlugin();
this.window=window;
}
function setOption(elm){
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.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.totaltime!==void)
totaltime=+elm.totaltime;
else
totaltime=12000;
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 LinearFlyingGrain(window,this);
flyinggrainy[i]=new LinearFlyingGrain(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();
}
}
totaltime-=interval;
}
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.skylinearflying_object=new SkyLinearFlying(kag));
@endscript
@macro name=lflying
@eval exp="global.skylinearflying_object.startFlying(mp)"
@endmacro
@macro name=stoplflying
@eval exp="global.skylinearflying_object.stopFlying()"
@endmacro
@macro name=leaflflying
@lflying 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 totaltime=%totaltime|20000 appearprob=%appearprob
@endmacro
@macro name=starlflying
@lflying 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=ljump
@lflying storage=%storage|ball num=%num angle=%angle|-90 speedoffset=%speedoffset|30.0 speed=%speed|10.0 accel=%accel|-1 totaltime=%totaltime|20000 appearprob=%appearprob
@endmacro
@return