Blaster Trail

Version:

1.0

Added on:

23 Feb 2013 15:02

Tags:

Description:
Creates a green trail (barrel shards) for the normal blaster bullets and a blue trail (ice shards) for the power up blaster 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.
//Blaster Leave Trail Constants
const int cSpreadSpeed = 3; //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= 50; //How long the shards will exist
const int cDensityFactor = 6; //A lower factor gives more green shards
const int cDensityFactorPU = 4; //A lower factor gives more blue shards

//i is globally declared (if you use i in your own code you can put i in the main)
int i;

//A function that creates a trail shard
void CreateTrail(int bulletID, bool powerup) {
  int shardID = jjAddObject(OBJECT::SHARD, jjObjects[bulletID].xPos, jjObjects[bulletID].yPos, 0, CREATOR::PLAYER);
  jjObjects[shardID].special = 73;
  if (powerup)
    jjObjectPresets[OBJECT::SHARD].determineCurAnim(ANIM::PICKUPS, 44+jjRandom()%4, true);
  else
    jjObjectPresets[OBJECT::SHARD].determineCurAnim(ANIM::PICKUPS, 6+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;
  }
}

void onMain() {
  if (jjGameTicks%2 == 0)
    for (i = 1; i < jjObjectCount; i++) {
      if (jjObjects[i].isActive && jjObjects[i].creatorType == CREATOR::PLAYER) {
        if (((jjGameTicks%cDensityFactor == 0 && jjObjects[i].eventID == OBJECT::BLASTERBULLET) || (jjGameTicks%cDensityFactorPU == 0 && jjObjects[i].eventID == OBJECT::BLASTERBULLETPU)) && jjObjects[i].state != STATE::EXPLODE)
          CreateTrail(i, (jjObjects[i].eventID == OBJECT::BLASTERBULLETPU));
        if (jjObjects[i].eventID == OBJECT::SHARD && jjObjects[i].special == 73) {
          jjObjects[i].age++;
          if (jjObjects[i].age > cTrailLifeTime) 
            jjDeleteObject(i);
        }
      }
    }
}