Change TNT to throwing bombs

Version:

2.0

Added on:

26 Feb 2013 17: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.
  1. /***Constants***/
  2. const float cBombSpeed = 8; //xSpeed of the bomb
  3. const float cBombPlayerSpeed = 6; //xSpeed the bomb can gain by player speed (if a player is running full speed it will add 6 xSpeed)
  4. const int cBombLifeTime = 70*2; //Time till the bomb explodes (run away! run away!!!1)
  5.  
  6. /***Other functions***/
  7. void CreateBomb(int objectID) {
  8.   int playerID = jjObjects[objectID].creator - 32768;
  9.   int bombID = jjAddObject(OBJECT::APPLE, jjPlayers[playerID].xPos, jjPlayers[playerID].yPos, jjPlayers[playerID].playerID, CREATOR::PLAYER);
  10.   jjObjects[bombID].objType = 3;
  11.   jjObjects[bombID].determineCurAnim(ANIM::AMMO, 1, true);
  12.   jjObjects[bombID].special = 11;
  13.   jjObjects[bombID].xSpeed = cBombSpeed*jjPlayers[playerID].direction + cBombPlayerSpeed*jjPlayers[playerID].xSpeed/16;
  14.   jjObjects[bombID].ySpeed = -3;
  15. }
  16.  
  17. void DestroyBomb(int bombID) {
  18.   int explosionID = jjAddObject(OBJECT::TNT, jjObjects[bombID].xPos, jjObjects[bombID].yPos, jjObjects[bombID].creator, CREATOR::PLAYER);
  19.   jjDeleteObject(bombID);
  20.   jjObjects[explosionID].determineCurAnim(ANIM::AMMO, 1, true);
  21.   jjObjects[explosionID].killAnim = ANIM::AMMO;
  22.   jjObjects[explosionID].state = STATE::EXPLODE;
  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.       //Create bomb
  30.       if (jjObjects[i].eventID == OBJECT::TNT && jjObjects[i].state != STATE::EXPLODE) {
  31.         jjDeleteObject(i);
  32.         CreateBomb(i);
  33.         continue;
  34.       }
  35.    
  36.       //Destroy bomb
  37.       if (jjObjects[i].eventID == OBJECT::APPLE && jjObjects[i].special == 11) {
  38.         jjObjects[i].age++;
  39.         if (jjObjects[i].age > cBombLifeTime)
  40.           DestroyBomb(i);
  41.         continue;
  42.       }
  43.     }
  44. }