Realistic rain

Version:

4.0

Added on:

26 Apr 2017 00:23

Tags:

Description:
Makes rain look more realistic in comparison with the standard "bubble rain" that comes packaged with JJ2+.
  1. void onLevelLoad() {
  2.   jjPIXELMAP rain(32,32);
  3.   for (uint x = 0; x < rain.width; ++x) {
  4.     for (uint y = 0; y < rain.height; ++y) {
  5.       if (x == 16) { //draw in the middle of the tile, xPixel 16
  6.         if (y <= 24) rain[x,y] = 75; //if at yPixel 24 or less, use color 75
  7.         else rain[x,y] = 74; //use color 74 for yPixels 25-32
  8.       } else {
  9.         rain[x,y] = 0;
  10.       }
  11.     }
  12.   }
  13.  
  14.   jjANIMATION@ anim = jjAnimations[jjAnimSets[ANIM::COMMON].firstAnim + 2];
  15.   for (uint frameID = 0; frameID < anim.frameCount; ++frameID) {
  16.     jjANIMFRAME@ frame = jjAnimFrames[anim.firstFrame + frameID];
  17.     rain.save(frame);
  18.     frame.hotSpotX = -frame.width/2;
  19.     frame.hotSpotY = -frame.height;
  20.   }
  21. }
  22.  
  23. void onMain() {
  24.   for (int i = 0; i < 1024; i++) { //loop through the global array jjParticles[1024]
  25.     jjPARTICLE@ particle = jjParticles[i];
  26.     if (particle.type == PARTICLE::RAIN) {
  27.       particle.xSpeed = 0; //make rain fall straight down
  28.       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
  29.     }
  30.   }
  31. }