Blaster Trail

Version:

2.0

Added on:

26 Feb 2013 16: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.
/***Constants***/
const int cSpreadSpeed = 2; //The higher this value the more the shards will spread perpendicular to the blasterbullet
const float cSlowDownSpeed = 6; //How much the shards slow down compared to the bullet
const int cTrailLifeTime= 70*1.5; //How long the shards will exist
const int cGreenDensityFactor = 6; //A lower factor gives more green shards
const int cBlueDensityFactor = 4; //A lower factor gives more blue shards

/**Other functions**/
void CreateShardTrail(int bulletID, bool greentrail) {
  int shardID = jjAddObject(OBJECT::SHARD, jjObjects[bulletID].xPos, jjObjects[bulletID].yPos, 0, CREATOR::PLAYER);
  jjObjects[shardID].special = 12;
  if (greentrail)
    jjObjectPresets[OBJECT::SHARD].determineCurAnim(ANIM::PICKUPS, 6+jjRandom()%4, true);
  else
    jjObjectPresets[OBJECT::SHARD].determineCurAnim(ANIM::PICKUPS, 44+jjRandom()%4, true);
  if (jjObjects[bulletID].direction != 0) {
    jjObjects[shardID].xSpeed = jjObjects[bulletID].xSpeed - jjObjects[bulletID].direction*cSlowDownSpeed;
    jjObjects[shardID].ySpeed = -cSpreadSpeed*(jjRandom()%32 - 16)/16;
  } else {
    jjObjects[shardID].xSpeed = -cSpreadSpeed*(jjRandom()%32 - 16)/16;
    jjObjects[shardID].ySpeed = jjObjects[bulletID].ySpeed + cSlowDownSpeed;
  }
}

/**Gameplay functions**/
void onMain() {
  for (int i = 0;  i < jjObjectCount; i++)
    if (jjObjects[i].isActive && jjObjects[i].creatorType == CREATOR::PLAYER) {
      //Shard Trail
      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) {
        CreateShardTrail(i, (jjObjects[i].eventID == OBJECT::BLASTERBULLET));
        continue;
      }

      //Maintain shard lifetime
      if (jjObjects[i].eventID == OBJECT::SHARD && jjObjects[i].special == 12) {
        jjObjects[i].age++;
        if (jjObjects[i].age > cTrailLifeTime)
          jjDeleteObject(i); 
        continue;
      }
    }
}