MODULE: Weather Effects

Started by Akumayo, Sun 12/02/2006 19:14:00

Previous topic - Next topic

Akumayo

This was an entry in the last coding competition.  I thout I'd share with any who didn't see it (it won!)

Here's a copy of the entry post, which includes documentation and download links (the update script includes docs on the lightning functions):

Akumayo's Weather Module sports functions that have literally no limit on their usage!  The possibilities are endless I tell you!  Now, allow me to clarify each function (This module uses functions from the Advanced Randoms Module, which is included in the download):

Code: ags

BeginEnvironmentalEffect(int slota, int slotb, int slotc, int slotd, int slote, int slotf, int slotg, int sloth, int envfallingspeed, int envwindspeed)


"slota" through "sloth" are the integers representing the sprite slot number of each weather piece.  This means you can have eight different designs of snowflake/raindrop/leaf, etc.  envfallingspeed is the integer representing how fast and what direction the weather pieces will fall.  Passing a positive direction will result in weather from the sky.  Passing a negative one will result in weather from the ground up (like bubbles).  The higher the absolute value of the integer, the faster the effect happens.  envwindspeed is the integer which controls how fast and what direction the weather pieces will move.  Passing a positive integer will result in movement to the right.  Passing a negative integer will result in movement to the left.

Code: ags
ChangeEnvironmentSpeeds(int newenvfallingspeed, int newenvwindspeed)


This function allows you to reset the speeds of an enviornmental effect, withough resetting it.  (Like for changing the direction of the wind.)  newenvfallingspeed allows you to redefine how fast and what direction weather piecies fall.  newenvwindspeed lets you redefine how fast and what direction weather piecies move left or right.

Now for examples:

Code: ags

  BeginEnvironmentalEffect(8, 9, 10, 8, 9, 10, 9, 8, 3, -2); 


Assuming 8, 9, and 10 are spriteslots of snowflakes, the above function would make slow falling snow moving slightly to the left as it falls.

Code: ags

  BeginEnvironmentalEffect(8, 9, 10, 8, 9, 10, 9, 8, 5, -4);  


This, however, would make snow falling pretty fast and moving pretty sharply to the left as it falls.

Now, if you were to integrate the other function in, then through repeatedly_execute you could make something more complex.  After creating a variable called weathergoing and setting it to one after calling BeginEnviornmentalEffect from elsewhere in the script, and making another integer called "w" and setting it to 0 by default:

Code: ags

  if (weathergoing == 1) {
    if (w == 5) {
      w --;
    }
    else if (w == -5) {
      w ++;
    }
    else if (w != -5 && w != 5) {
      w += RandomWeightedDice(-1, 10, 1, 10, 0, 80, 0, 0);
    }
    ChangeEnvironmentSpeeds(2, w);
}


This would end in weather that was moved left and right by gusts of wind, rather than having a constant windspeed.

IMPORTANT:  To end weather effects, pass BeginEnvironmentalEffect with all the "slot" integer values as 0, or a spriteslot that is blank.  Don't worry, the game runs at a normal speed still.

The demo game included in the download has the following effects to preview:
Rain
Snow
Heavy Rain
Heavy Snow
Sea Bubbles
Sandstorm
Meteor Shower (more like an apocalyptic doom of a meteor shower...)
Option to switch on code for varying windspeeds

A note on the side, and the only downside I've noticed so far, effects look sort of clumped together their first time across the screen, but they get better and more realistic quickly after that.

This module would also be ideal for leaves falling slowly, or something of that nature.

User Experience Recommended:
-Basic knowledge of the sprite manager

UPDATE:

Akumayo's Weather Module now contains, the CastLightningBolt!!! function!!!  Now... who wants to get fried?  Here's the specs on the CastLightningBolt function and it's affiliate.

Code: ags

function CastLightningBolt(int boltseed_x, int boltseed_y, int boltstop_y, int boltstrike_speed, int boltstrike_xoffset, int bolt_color)


This is CastLightningBolt.  CastLightningBolt does just what it says, but works off Raw functions instead of overlays, meaning you can Cast lightning bolts when it is raining, snowing, etc.
-boltseed_x:  The x position of where the lightning bolt will begin
-boltseed_y:  The y position of where the lightning bolt will begin
-boltstop_y:  The y position of where the lightning bolt will end
-boltstrike_speed:  How fast the lightningbolt will fall (must be > 0)
-boltstrike_xoffset:  How much the lightning bolt will waver as it grows (must be >= 0)
-bolt_color:  The color of the lightning bolt

*NOTE:  Never, Never, Never call a CastLightningBolt function while one is already running, doing so will result in the bolt that was running sticking to the background, and a new one starting.  That's where this function comes in:

Code: ags
function IsLightningGoing()


This returns 1 or 0.  1 means a lightning bolt is playing, so DON'T call CastLightningBolt.  0 means no lightning bolts are playing, so you can CastLightningBolt if you want to.

Now, by merging these together, we can create a Lightning Storm!!!  (Demonstrated in the demo game):

To start up the storm, place this in any interaction:

Code: ags

  Display("Let the reign of lightning begin!");
  lightninggoing = 1;
  hlight.Enabled = false;
  CastLightningBolt(Random(319) + 1, 0, 200, RandomBoundries(5, 15), RandomBoundries(1, 5), 65472);  


Then place this under repeatedly_excecute:

Code: ags

  if (lightninggoing == 1) {
    if (IsLightningGoing() == 0) {
      if (timerone == 0) {
        SetTimer(1, Random(40) + 1);
        timerone = 1;
      }
    }
  }
  if (IsTimerExpired(1) == 1) {
    timerone = 0;
    CastLightningBolt(Random(319) + 1, 0, 200, RandomBoundries(5, 15), RandomBoundries(1, 5), 65472);
  }


And BOOM!!!  A lightning storm is born!!!  Check it out in the demo!!!  And remember, don't get caught in the lightning!

Download Akumayo's Weather Module Plus the Lightning Function (Advanced Randoms Module included) and the demo game previewing some of the possibilities:

HERE!

Download the README which contains all the stuff in this post here (before Lightning update):
http://www.2dadventure.com/ags/AkumayosWeatherModuleREADME.zip


Well... there it is, enjoy.

-Regards, Glacies Akumayo

Edit by strazer:

Quote from: Akumayo (Will return by July 20th) on Thu 22/06/2006 23:15:18I don't plan on going back to the Weather Effects module.

Try his Lighting module.

Edit by Dualnames:

-Replaced all links that didn't work. Unfortunately I have not been able to retrieve the readme, if in any case someone has it, let me know and I shall update this topic.
"Power is not a means - it is an end."

monkey0506

Just a thought...if you shouldn't call CastLightningBolt if the lightning is running, why not just prevent it internally?

Code: ags
function CastLightningBolt(int boltseed_x, int boltseed_y, int boltstop_y, int boltstrike_speed, int boltstrike_xoffset, int bolt_color) {
  if (IsLightningGoing()) return;
  // blah
  }


The function would terminate if there was a lightning bolt drawn on the screen, otherwise it would draw the new one.  That way the user wouldn't have to worry about it.  And unless you return some value from the function you could even define it like:

Code: ags
bool CastLightningBolt(int boltseed_x, int boltseed_y, int boltstop_y, int boltstrike_speed, int boltstrike_xoffset, int bolt_color) {
  if (IsLightningGoing()) return false;
  // blah
  return true;
  }


That way the user could determine whether the new lightning was drawn or not at the same time as they tell it to draw it.

Okay, maybe more than just a thought...

Akumayo

Hrm... I suppose that would be rather easier, on the user's part.  I may change it later, when I'm not so busy.  Thanks for pointing it out though.
"Power is not a means - it is an end."

pixg

Lightningmodule.asc(61): Error (line 61): Undefined token 'RawSetColor'

not sure if this error is due to AGS being updated since this module was written.4

also the link to the read-me file (http://www.2dadventure.com/ags/AkumayosWeatherModuleREADME.zip
)is broken.

Dualnames

Quote from: pixg on Sun 27/01/2013 10:54:31
Lightningmodule.asc(61): Error (line 61): Undefined token 'RawSetColor'

not sure if this error is due to AGS being updated since this module was written.

Yeah, the module uses old drawing functions, I'm sure an advanced coder would have no trouble replacing them with the new ones.

Quotealso the link to the read-me file (http://www.2dadventure.com/ags/AkumayosWeatherModuleREADME.zip
)is broken.

Unfortunately, I don't have the readme file, but I made sure to cross the link to avoid further inconveniences.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk