//Particles.zh //A header used to create particle effects based on Lweapons // //Unlike Grayswandir`s animation.zh it has more features regarding controlling particle movement. const int ANIMATION_ID = 31; //Animation Lweapon ID. Set it so it does not conflict with other scripts. const int ANIMATION_MISC_VX = 1; //"Vertical velocity" misc variable. const int ANIMATION_MISC_VY = 2; //"Horizontal velocity" misc variable. const int ANIMATION_MISC_AX = 3; //"Horizontal Acceleration" misc variable. const int ANIMATION_MISC_AY = 4; //"Vertical Acceleration" misc variable. const int ANIMATION_MISC_TIMEOUT = 5; //"Particle Lifespan" misc variable. const int ANIMATION_MISC_AFFECTED_BY_GRAVITY = 6; //"Gravity boolean" misc variable. Used in sideview areas. const int ANIMATION_MISC_XPOS = 7; //"Paeticle X position" misc variable. const int ANIMATION_MISC_YPOS = 8; //"Paeticle Y position" misc variable. global script Animations{ void run(){ while (true){ Waitdraw(); UpdateAnimations(); //Place this function between "Waitdraw" and "Waitframe" when combining with other global scripts. Waitframe(); } } } // Creates a particle. Setting lifespan to -2 sets it to one full animation cycle. lweapon CreateAnimation (int x, int y, int sprite, int ax, int ay, int vx, int vy, int lifespan, bool grav){ lweapon anim = Screen->CreateLWeapon(ANIMATION_ID); anim->X = x; anim->Y = y; anim->UseSprite(sprite); anim->CollDetection = false; //No one should want for any NPC do destroy particle by strpping on it`s spawn point. anim->Misc[ANIMATION_MISC_VX] = vx; anim->Misc[ANIMATION_MISC_VY] = vy; anim->Misc[ANIMATION_MISC_AX] = ax; anim->Misc[ANIMATION_MISC_AY] = ay; if (lifespan == -2){ anim->Misc[ANIMATION_MISC_TIMEOUT] = (anim->ASpeed)*(anim->NumFrames); } else anim->Misc[ANIMATION_MISC_TIMEOUT] = lifespan; if (grav) anim->Misc[ANIMATION_MISC_AFFECTED_BY_GRAVITY] = 1; anim->Misc[ANIMATION_MISC_XPOS] = anim->X; anim->Misc[ANIMATION_MISC_YPOS] = anim->Y; return anim; } //Andvanced version of animation creating. Use it if you are running out of sprite slots in Weapons/Misc animation data. lweapon CreateAnimationAdvanced( int x, int y, int numframes, int aspeed, int origtile, int cset, int flashcset, int ax, int ay, int vx, int vy, int lifespan, bool grav){ lweapon anim = Screen->CreateLWeapon(ANIMATION_ID); anim->DeadState = -1; anim->X = x; anim->Y = y; anim->CollDetection = false; anim->NumFrames = numframes; anim->ASpeed = aspeed; anim->OriginalTile = origtile; anim->OriginalCSet = cset; if (flashcset >= 0){ anim->Flash = true; anim->FlashCSet = flashcset; } anim->Misc[ANIMATION_MISC_VX] = vx; anim->Misc[ANIMATION_MISC_VY] = vy; anim->Misc[ANIMATION_MISC_AX] = ax; anim->Misc[ANIMATION_MISC_AY] = ay; if (lifespan == -2){ anim->Misc[ANIMATION_MISC_TIMEOUT] = (anim->ASpeed)*(anim->NumFrames); } else anim->Misc[ANIMATION_MISC_TIMEOUT] = lifespan; if (grav) anim->Misc[ANIMATION_MISC_AFFECTED_BY_GRAVITY] = 1; anim->Misc[ANIMATION_MISC_XPOS] = anim->X; anim->Misc[ANIMATION_MISC_YPOS] = anim->Y; return anim; } //Set angular motion of particle. Angle is measured in degrees. void SetAngularMovement(lweapon anim, int angle, int speed){ anim->Misc[ANIMATION_MISC_VX] = speed*Cos(angle); anim->Misc[ANIMATION_MISC_VY] = speed*Sin(angle); } //Expands particle size. void BigAnim (lweapon anim, int tilewidth, int tileheight){ anim->Extend = 3; anim->TileWidth = tilewidth; anim->TileHeight = tileheight; } //Main particle update function. Uses DrawOffset variables to actually display particle at it`s position so it does not disappear on touching screen edges void UpdateAnimations(){ lweapon anim; for (int i=1; i<= Screen->NumLWeapons(); i++){ anim = Screen->LoadLWeapon(i); if (anim->ID == ANIMATION_ID){ if (!(anim->CollDetection)){ if (((anim->Misc[ANIMATION_MISC_AFFECTED_BY_GRAVITY])>0)&&(IsSideview())){// Determine gravity movement. if ((anim->Misc[ANIMATION_MISC_VY]) < TERMINAL_VELOCITY) anim->Misc[ANIMATION_MISC_AY] = GRAVITY; else { anim->Misc[ANIMATION_MISC_AY] = 0; anim->Misc[ANIMATION_MISC_VY] = TERMINAL_VELOCITY; } } //Next update particle velocity depending on acceleration. anim->Misc[ANIMATION_MISC_VX] = (anim->Misc[ANIMATION_MISC_VX])+(anim->Misc[ANIMATION_MISC_AX]); anim->Misc[ANIMATION_MISC_VY] = (anim->Misc[ANIMATION_MISC_VY])+(anim->Misc[ANIMATION_MISC_AY]); //Then update pseudo-position of particle depending on velocity. anim->Misc[ANIMATION_MISC_XPOS] = (anim->Misc[ANIMATION_MISC_XPOS])+(anim->Misc[ANIMATION_MISC_VX]); anim->Misc[ANIMATION_MISC_YPOS] = (anim->Misc[ANIMATION_MISC_YPOS])+(anim->Misc[ANIMATION_MISC_VY]); //And finally calculate and apply DrawOffset values to Lweapons. anim->DrawXOffset = (anim->Misc[ANIMATION_MISC_XPOS]) - (anim->X); anim->DrawYOffset = (anim->Misc[ANIMATION_MISC_YPOS]) - (anim->Y); //Remove particle if it falls off bottom of the screen on sideview areas. if (((anim->Misc[ANIMATION_MISC_AFFECTED_BY_GRAVITY])>0)&&((anim->Misc[ANIMATION_MISC_YPOS])>176)){ Remove(anim); } //Update life timer and remove animation if it hits 0. if ((anim->Misc[ANIMATION_MISC_TIMEOUT])>0) anim->Misc[ANIMATION_MISC_TIMEOUT]--; if ((anim->Misc[ANIMATION_MISC_TIMEOUT])==0) Remove(anim); } } } }