Dusty's inspiration and comments added. Should be outwardly the same, but the code is much shorter in the color respect. I wonder if you can add a random function to an array and let it pass through so the value is random everytime, although my hack really didn't add even a single line.
Added:
I am wondering, I think I can assign one of TStaticVar's subvariables as a funciton pass it through to the moving updating and have it do some fancy processing that way. Maybe I'll try that later.
Now that that's out of the way, perhaps I'll work on that HSL, i'm curious how it will look.
PHP Code:
//NPC Created by Rogue Shadow(TCN)
//AIM: RogueTCN
//#CLIENTSIDE
function onCreated(){
this.rockets = new[0];
this.bursts = new[0];
this.trails = new[0];
this.grav = 0.1;
}
function onWeaponFired(){
AddRocket(random(0,64),64);
}
function onTimeout(){
for (temp.i=0;temp.i<this.rockets.size();temp.i++){
AddTrail(this.rockets[temp.i].x-.5,this.rockets[temp.i].y,this.rockets[temp.i].vx,this.rockets[temp.i].vy);
if (this.rockets[temp.i].t > this.rockets[temp.i].ttl){
AddBurst(this.rockets[temp.i].x,this.rockets[temp.i].y,160);
}
}
this.rockets = UpdateEverything(this.rockets);
this.bursts = UpdateEverything(this.bursts);
this.trails = UpdateEverything(this.trails);
temp.img = DrawParticle(200,this.rockets);
temp.img = DrawParticle(temp.img,this.bursts);
temp.img = DrawParticle(temp.img,this.trails);
if (temp.img < this.lastimg)hideimgs(temp.img,this.lastimg);
this.lastimg = temp.img;
settimer(0.05);
}
function UpdateEverything(temp.objs){
for (temp.i = 0;temp.i < temp.objs.size() ; temp.i++ ){
if (temp.objs[temp.i].t > temp.objs[temp.i].ttl){
temp.objs.delete(temp.i);
}
}
for (temp.r: temp.objs){
temp.r.vy += this.grav;
temp.r.x += temp.r.vx;
temp.r.y += temp.r.vy;
temp.r.t ++;
}
return temp.objs;
}
function DrawParticle(temp.img,temp.p){
for (temp.r: temp.p){
if (temp.r.alpha){
temp.a = 1-(temp.r.t/temp.r.ttl);
}else temp.a = 1;
temp.j = showimg(temp.img,r.image,temp.r.x,temp.r.y);
changeimgcolors(temp.img,r.rgb[0],r.rgb[1],r.rgb[2],temp.a);
changeimgzoom(temp.img,r.zoom);
if (r.rotation){
temp.rot = getangle(r.vx,r.vy)+pi/2;
with (temp.j)rotation = temp.rot;
}
if (r.spin){
with (temp.j)rotation += temp.r.spin_spd;
}
temp.img++;
}
return temp.img;
}
function AddBurst(nx,ny,num){
temp.rgb = {{0,1,0},{1,0,1},{0,0,1},{1,1,0},{0,1,1},{1,1,1}};
temp.kind = int(random(0,1)+.5);
temp.color = int(random(0,temp.rgb.size()+1)+.5);
for (temp.j=0;temp.j < num;temp.j++){
temp.i = new TStaticVar();
temp.i.image = "g4_particle_x.png";
if (temp.kind == 1)temp.spd = random(.1,.8);
else temp.spd = (temp.j%2=1) ? .2:.3;
temp.i.zoom = .6;
temp.i.vx = sin(temp.ang)*temp.spd;
temp.i.vy = cos(temp.ang)*temp.spd -.7;
temp.ang+=0.1;
temp.i.x = nx;
temp.i.y = ny;
temp.i.ttl = 30;
temp.i.t = 0;
temp.i.rgb = (temp.color < temp.rgb.size()) ? temp.rgb[temp.color]:{random(0,1),random(0,1),random(0,1)};
temp.i.alpha = true;
temp.i.i=this.bursts.size();
temp.i.spin = true;
temp.i.spin_spd = random(-.5,.5);
this.bursts.add(temp.i);
}
play("fireworks_explode.wav");
}
function AddRocket(nx,ny){
temp.r = new TStaticVar();
temp.r.image = "np_barrel.png";
temp.r.x = nx;
temp.r.zoom = .7;
temp.r.y = ny;
temp.r.vx = random(-.5,.5);
temp.r.vy = -random(2,3);
temp.r.ttl = 30;
temp.r.t = 0;
temp.r.rgb = {1,1,1};
temp.r.rotation = true;
temp.r.alpha = false;
temp.r.i = this.rockets.size();
this.rockets.add(temp.r);
play("fireworks_launch.wav");
settimer(0.05);
}
function AddTrail(nx,ny,vx,vy){
temp.r = new TStaticVar();
temp.r.x = nx;
temp.r.y = ny;
temp.r.vy = -random(.1,.5);
temp.r.vx = -random(.1,.5);
temp.r.ttl = 10;
temp.r.t = 0;
temp.r.rgb = {1,1,1};
temp.r.alpha = true;
temp.r.rotation = true;
temp.r.zoom = .7;
temp.r.image = "g4_particle_smoke.png";
temp.r.i = this.trails.size();
this.trails.add(temp.r);
}