Change TNT to throwing bombs

Version:

2.0

Added on:

26 Feb 2013 16:58

Tags:

Description:
Does what the title says. The bomb explosion is the same as a TNT explosion, so setting tntdamage or extended tnt range will also affect these bombs. You can change behaviour by changing the bomb constants at the top of the code. Bombs can only be thrown left and right.

EDIT: Improved efficiency of the code. Also this code will not destroy apple's anymore.
/***Constants***/
const float cBombSpeed = 8; //xSpeed of the bomb
const float cBombPlayerSpeed = 6; //xSpeed the bomb can gain by player speed (if a player is running full speed it will add 6 xSpeed)
const int cBombLifeTime = 70*2; //Time till the bomb explodes (run away! run away!!!1)

/***Other functions***/
void CreateBomb(int objectID) {
  int playerID = jjObjects[objectID].creator - 32768;
  int bombID = jjAddObject(OBJECT::APPLE, jjPlayers[playerID].xPos, jjPlayers[playerID].yPos, jjPlayers[playerID].playerID, CREATOR::PLAYER);
  jjObjects[bombID].objType = 3;
  jjObjects[bombID].determineCurAnim(ANIM::AMMO, 1, true);
  jjObjects[bombID].special = 11;
  jjObjects[bombID].xSpeed = cBombSpeed*jjPlayers[playerID].direction + cBombPlayerSpeed*jjPlayers[playerID].xSpeed/16;
  jjObjects[bombID].ySpeed = -3;
}

void DestroyBomb(int bombID) {
  int explosionID = jjAddObject(OBJECT::TNT, jjObjects[bombID].xPos, jjObjects[bombID].yPos, jjObjects[bombID].creator, CREATOR::PLAYER);
  jjDeleteObject(bombID);
  jjObjects[explosionID].determineCurAnim(ANIM::AMMO, 1, true);
  jjObjects[explosionID].killAnim = ANIM::AMMO;
  jjObjects[explosionID].state = STATE::EXPLODE;
}

/***Gameplay functions***/
void onMain() {
  for (int i = 0;  i < jjObjectCount; i++)
    if (jjObjects[i].isActive && jjObjects[i].creatorType == CREATOR::PLAYER) {
      //Create bomb
      if (jjObjects[i].eventID == OBJECT::TNT && jjObjects[i].state != STATE::EXPLODE) {
        jjDeleteObject(i);
        CreateBomb(i);
        continue;
      }
    
      //Destroy bomb
      if (jjObjects[i].eventID == OBJECT::APPLE && jjObjects[i].special == 11) {
        jjObjects[i].age++;
        if (jjObjects[i].age > cBombLifeTime)
          DestroyBomb(i);
        continue;
      }
    }
}