Blaster Trail

Version:

2.0

Added on:

26 Feb 2013 17:53

Tags:

Description:
Creates a green trail (barrel shards) for the normal blaster bullets and a blue trail (ice shards) for normal and powered up ice bullets. Thanks to SE for telling me these where not green and blue leaves :P. Also i was a bit inspired by cooba's fireball trail.

EDIT: Improved the efficiency of the code and changed the trail to other guns. Also renamed some things.
  1. /***Constants***/
  2. const int cSpreadSpeed = 2; //The higher this value the more the shards will spread perpendicular to the blasterbullet
  3. const float cSlowDownSpeed = 6; //How much the shards slow down compared to the bullet
  4. const int cTrailLifeTime= 70*1.5; //How long the shards will exist
  5. const int cGreenDensityFactor = 6; //A lower factor gives more green shards
  6. const int cBlueDensityFactor = 4; //A lower factor gives more blue shards
  7.  
  8. /**Other functions**/
  9. void CreateShardTrail(int bulletID, bool greentrail) {
  10.   int shardID = jjAddObject(OBJECT::SHARD, jjObjects[bulletID].xPos, jjObjects[bulletID].yPos, 0, CREATOR::PLAYER);
  11.   jjObjects[shardID].special = 12;
  12.   if (greentrail)
  13.     jjObjectPresets[OBJECT::SHARD].determineCurAnim(ANIM::PICKUPS, 6+jjRandom()%4, true);
  14.   else
  15.     jjObjectPresets[OBJECT::SHARD].determineCurAnim(ANIM::PICKUPS, 44+jjRandom()%4, true);
  16.   if (jjObjects[bulletID].direction != 0) {
  17.     jjObjects[shardID].xSpeed = jjObjects[bulletID].xSpeed - jjObjects[bulletID].direction*cSlowDownSpeed;
  18.     jjObjects[shardID].ySpeed = -cSpreadSpeed*(jjRandom()%32 - 16)/16;
  19.   } else {
  20.     jjObjects[shardID].xSpeed = -cSpreadSpeed*(jjRandom()%32 - 16)/16;
  21.     jjObjects[shardID].ySpeed = jjObjects[bulletID].ySpeed + cSlowDownSpeed;
  22.   }
  23. }
  24.  
  25. /**Gameplay functions**/
  26. void onMain() {
  27.   for (int i = 0;  i < jjObjectCount; i++)
  28.     if (jjObjects[i].isActive && jjObjects[i].creatorType == CREATOR::PLAYER) {
  29.       //Shard Trail
  30.       if (((jjGameTicks%cBlueDensityFactor == 0 && (jjObjects[i].eventID == OBJECT::ICEBULLET || jjObjects[i].eventID == OBJECT::ICEBULLETPU)) || (jjGameTicks%cGreenDensityFactor == 0 && jjObjects[i].eventID == OBJECT::BLASTERBULLET)) && jjObjects[i].state != STATE::EXPLODE) {
  31.         CreateShardTrail(i, (jjObjects[i].eventID == OBJECT::BLASTERBULLET));
  32.         continue;
  33.       }
  34.  
  35.       //Maintain shard lifetime
  36.       if (jjObjects[i].eventID == OBJECT::SHARD && jjObjects[i].special == 12) {
  37.         jjObjects[i].age++;
  38.         if (jjObjects[i].age > cTrailLifeTime)
  39.           jjDeleteObject(i);
  40.         continue;
  41.       }
  42.     }
  43. }