Realistic rain

Version:

1.0

Added on:

25 Apr 2017 21:54

Tags:

Description:
Makes rain look more realistic in comparison with the standard "bubble rain" that comes packaged with JJ2+.
void onLevelLoad() {
  jjANIMATION@ anim = jjAnimations[jjAnimSets[ANIM::COMMON] + 2]; //the rain "bubble"
  for (uint i = 0; i < anim.frameCount; ++i) {
    jjANIMFRAME@ frame = jjAnimFrames[anim + i];
    jjPIXELMAP sprite(frame);
    for (uint x = 0; x < sprite.width; ++x)
      for (uint y = 0; y < sprite.height; ++y)
      if (sprite[x,y] != 0) sprite[x,y] = 0; //erase every pixel in the original rain sprite
    sprite.save(frame);
  }
}

void onLevelBegin() {
  jjPIXELMAP rain(32,32); //since we're replacing a tileID, this needs to be 32x32
  for (uint x = 0; x < rain.width; ++x) {
    for (uint y = 0; y < rain.height; ++y) {
      if (x == 16) { //draw in the middle of the tile, xPixel 16
        if (y <= 24) rain[x,y] = 75; //if at yPixel 24 or less, use color 75
        else rain[x,y] = 74; //use color 74 for yPixels 25-32
      } else {
        rain[x,y] = 0; //we only want to draw a line one pixel in width
      }
    }
  }
  rain.save(9999); //no tileset could use such a high tileID reference, but we sure can!
 
  jjANIMATION@ anim = jjAnimations[jjAnimSets[ANIM::COMMON].firstAnim + 2];
  for (uint frameID = 0; frameID < anim.frameCount; ++frameID) {
    jjANIMFRAME@ frame = jjAnimFrames[anim.firstFrame + frameID];
    jjPIXELMAP rain2(9999); //use the ridiculous tileID we just wrote to 
    rain2.save(frame); //replace each frame with this tile
    frame.hotSpotX = -frame.width/2;
    frame.hotSpotY = -frame.height;
  }
}

void onMain() {
  for (int i = 0; i < 1024; i++) { //loop through the global array jjParticles[1024]
    jjPARTICLE@ particle = jjParticles[i];
    if (particle.type == PARTICLE::RAIN) {
      particle.xSpeed = 0; //make rain fall straight down
      particle.ySpeed = jjLocalPlayers[0].ySpeed < 0? 10 : int(10 + jjLocalPlayers[0].ySpeed); //the rain speed accounts for differences in the player speed, and so won't appear to fall more slowly when the player is falling
    }
  }
}