Blade gun (Electroblaster PU)

Version:

1.0

Added on:

04 Feb 2013 00:34

Tags:

Description:
This will replace all powered-up electroblaster bullets with blades (discs), that can be controlled by the player. This works in multiplayer. Not tested in singleplayer.
  1. array<uint> canShootTick = {0, 0, 0, 0};
  2.  
  3. void onPlayer() {
  4.   if (canShootTick[p.localPlayerID] > jjGameTicks) {
  5.     p.noFire = true;
  6.   }
  7. }
  8.  
  9. void onMain() {
  10.   for (int i=0; i < jjObjectCount; i++) {
  11.  
  12.     if (jjObjects[i].isActive && jjObjects[i].eventID == OBJECT::ELECTROBULLETPU && jjObjects[i].creatorType == CREATOR::PLAYER) {
  13.      
  14.       jjOBJ@ bullet;
  15.       jjPLAYER@ player;
  16.       @player = jjPlayers[jjObjects[i].creator-32768]; // HAX!! nope just signed
  17.       @bullet = jjObjects[jjAddObject(OBJECT::LIGHTNINGSHIELDBULLET, jjObjects[i].xPos, jjObjects[i].yPos, jjObjects[i].creator, CREATOR::PLAYER)];
  18.      
  19.       bullet.creator = jjObjects[i].creator;
  20.       bullet.xSpeed = jjObjects[i].xSpeed+player.xSpeed*3.0f;
  21.       bullet.ySpeed = jjObjects[i].ySpeed+player.ySpeed/5.0f;
  22.       bullet.xAcc = 0;
  23.       bullet.determineCurAnim(ANIM::AMMO, 66); // Blade/ring sprite
  24.  
  25.       jjSample(bullet.xPos, bullet.yPos, SOUND::COMMON_RINGGUN);
  26.      
  27.      
  28.      
  29.       for (int j = 0; j < jjLocalPlayerCount; j++) {
  30.         jjPLAYER@ local;
  31.         @local = jjLocalPlayers[j];
  32.         if (local.playerID == player.playerID) {
  33.           //jjAlert("Player "+formatInt(j, "l")+" shot this");
  34.           canShootTick[j] = jjGameTicks + 1*70; // Can't fire, must wait 1 second
  35.           break;
  36.         }
  37.       }
  38.  
  39.       jjObjects[i].state = STATE::KILL; // Destroy the electroblaster bullet
  40.     }
  41.     // Steer the blade gun, play sound effects, keep it "alive"
  42.     else if (jjObjects[i].isActive && jjObjects[i].eventID == OBJECT::LIGHTNINGSHIELDBULLET && jjObjects[i].creatorType == CREATOR::PLAYER && jjObjects[i].state != STATE::KILL) {
  43.       jjObjects[i].counter = jjGameTicks % (jjObjects[i].counterEnd/2);
  44.  
  45.       if ((jjGameTicks + jjObjects[i].age) % 20 == 0) {
  46.         jjSample(jjObjects[i].xPos, jjObjects[i].yPos, SOUND::INTRO_SWISH2);
  47.       }
  48.      
  49.       // This is optional, lets the player control the blade/disc
  50.       jjObjects[i].xSpeed = jjObjects[i].xSpeed + jjPlayers[jjObjects[i].creator].xSpeed/2.0f;
  51.       jjObjects[i].ySpeed = jjObjects[i].ySpeed + jjPlayers[jjObjects[i].creator].ySpeed/24.0f;
  52.  
  53.       jjObjects[i].xSpeed = jjObjects[i].xSpeed*1.2f;
  54.       jjObjects[i].ySpeed = jjObjects[i].ySpeed*1.01f;
  55.      
  56.       // Max speed on the x-axiss
  57.       if (jjObjects[i].xSpeed > 40.0f) {
  58.         jjObjects[i].xSpeed = 40.0f;
  59.       } else if (jjObjects[i].xSpeed < -40.0f) {
  60.         jjObjects[i].xSpeed = -40.0f;
  61.       }
  62.     }
  63.   }
  64. }
  65.  
  66.     }