Realistic rain

Version:

3.0

Added on:

25 Apr 2017 22:10

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 rain(1,32);
    for (uint y = 0; y < rain.height; ++y) {
      if (y <= 24) {
        rain[0,y] = 75;
      }
      else {
        rain[0,y] = 74;
      }
    }
    rain.save(frame);
    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
    }
  }
}