00:00
00:00
Newgrounds Background Image Theme

markololohands just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Foss: Weather Script.

1,774 Views | 18 Replies
New Topic Respond to this Topic

Foss: Weather Script. 2005-07-27 13:53:06


FOSS: MAIN

If people want pretty weather scripts in their movies or games without coding a lot they can use this script. I placed this inside a .as file name 'elementScript.as' . Then uploaded it into a game/movie with

#include "elementScript.as" //PLACE IN FIRST FRAME MAKE SURE THIS IS IN THE SAME DIRECTORY AS THE GAME/MOVIE

to start the code all you have to do is.

_root.startWeather(EFFECT NAME, HEIGHT, WIDTH);

the effect name can be "snow", "rain", "blizzard", and "dust"

so for example if I wanted rain in my movie/game all I have to type is.

_root.startWeather("rain", 400, 550)

and to stop it

_root.stopWeather()

//PLACE ALL THIS CODE IN A .AS FILE
//FRAME RATE ONLY DETERMINES QUALITY NOT SPEED
//***************START WEATHER********************
function startWeather(effect, maxH, maxW) {
d = 10000;
i = 0;
runWeather = setInterval(generateLoop, 10, effect, maxH, maxW);
if (effect == "blizzard") {
_root.createEmptyMovieClip("blizzardBox", 9000);
_root.blizzardBox.lineStyle(1, 0xC8FFFF, 50);
_root.blizzardBox.beginFill(0xC8FFFF, 50);
_root.blizzardBox.moveTo(-10, -10);
_root.blizzardBox.lineTo(-10, 410);
_root.blizzardBox.lineTo(560, 410);
_root.blizzardBox.lineTo(560, -10);
_root.blizzardBox.lineTo(-10, -10);
_root.blizzardBox.endFill();
} else if (effect == "dust") {
_root.createEmptyMovieClip("dustBox", 9000);
_root.dustBox.lineStyle(1, 0xCC9437, 20);
_root.dustBox.beginFill(0xCC9437, 20);
_root.dustBox.moveTo(-10, -10);
_root.dustBox.lineTo(-10, 410);
_root.dustBox.lineTo(560, 410);
_root.dustBox.lineTo(560, -10);
_root.dustBox.lineTo(-10, -10);
_root.dustBox.endFill();
}
}
//***************STOP WEATHER********************
function stopWeather() {
for (j=10000; j<10045; j++) {
_root["rain"+j].removeMovieClip();
}
for (j=10000; j<10080; j++) {
_root["snow"+j].removeMovieClip();
}for (j=10000; j<10080; j++) {
_root["dust"+j].removeMovieClip();
}
_root.dustBox.removeMovieClip();
_root.blizzardBox.removeMovieClip();
clearInterval(runWeather);
}
//***************GENERATE LOOP********************
function generateLoop(effect, maxH, maxW) {
i++;
if (effect == "rain" && i>1) {
createRain();
i = 0;
} else if (i>7 && effect == "snow") {
createSnow(effect);
i = 0;
} else if (i>2 && effect == "blizzard") {
createSnow(effect);
i = 0;
}
if (effect == "dust") {
createDust();
}
if (effect == "rain") {
for (x=10000; x<10025; x++) {
if (_root["rain"+x]._y>maxH+10 || _root["rain"+x]._x>maxW+10) {
_root["rain"+x].removeMovieClip();
}
_root["rain"+x]._y += _root["rain"+x].speed;
_root["rain"+x]._x += _root["rain"+x].speed/2;
}
} else if (effect == "snow" || effect == "blizzard") {
for (x=10000; x<10040; x++) {
_root["snow"+x]._y += _root["snow"+x].y;
_root["snow"+x]._x += _root["snow"+x].x;
if (_root["snow"+x]._x>maxW+10 || _root["snow"+x]._y>maxH+10) {
_root["snow"+x].removeMovieClip();
}
}
} else if (effect == "dust") {
for (x=10000; x<10040; x++) {
_root["dust"+x]._y += _root["dust"+x].y;
_root["dust"+x]._x += _root["dust"+x].x;
if (_root["dust"+x]._x>maxW+10 || _root["dust"+x]._y>maxH+10) {
_root["dust"+x].removeMovieClip();
}
}
}
}
//***************RAIN********************
function createRain() {
d++;
_root.createEmptyMovieClip("rain"+d, d);
_root["rain"+d].lineStyle(1, 0x0033CC, 100);
_root["rain"+d].moveTo(0, 0);
_root["rain"+d].lineTo(5, 10);
_root["rain"+d].speed = Math.random()*25+10;
_root["rain"+d]._alpha = Math.random()*50+50;
_root["rain"+d]._xscale = Math.random()*100+50;
_root["rain"+d]._yscale = _root["rain"+d]._xscale;
_root["rain"+d]._y = -40;
_root["rain"+d]._x = Math.random()*700-150;
if (d>10022) {
d = 10000;
}
}
//***************CREATE SNOW********************
function createSnow(effect) {
d++;
_root.createEmptyMovieClip("snow"+d, d);
_root["snow"+d].lineStyle(0, 0xC8FFFF, 100);
_root["snow"+d].beginFill(0xC8FFFF);
_root["snow"+d].moveTo(500, 500);
_root["snow"+d].curveTo(600, 500, 600, 400);
_root["snow"+d].curveTo(600, 300, 500, 300);
_root["snow"+d].curveTo(400, 300, 400, 400);
_root["snow"+d].curveTo(400, 500, 500, 500);
_root["snow"+d].endFill();
_root["snow"+d]._xscale = Math.random()*2+2;
_root["snow"+d]._yscale = _root["snow"+d]._xscale;
_root["snow"+d]._alpha = Math.random()*40+60;
_root["snow"+d]._x = Math.random()*700-150;
_root["snow"+d].r = Math.random()*45;
if (effect == "snow") {
_root["snow"+d].r = Math.random()*45;
_root["snow"+d].x = Math.sin((_root["snow"+d].r)*(Math.PI/180)
)*2;
_root["snow"+d].y = Math.cos((_root["snow"+d].r)*(Math.PI/180)
)*2;
} else if (effect == "blizzard") {
_root["snow"+d].r = Math.random()*60;
_root["snow"+d].x = Math.sin((_root["snow"+d].r)*(Math.PI/180)
)*6;
_root["snow"+d].y = Math.cos((_root["snow"+d].r)*(Math.PI/180)
)*6;
}
_root["snow"+d]._y = -10;
if (d>10037) {
d = 10000;
}
}
//***************CREATE DUST***************
function createDust() {
d++;
_root.createEmptyMovieClip("dust"+d, d);
_root["dust"+d].lineStyle(0, 0xCC9437, 100);
_root["dust"+d].beginFill(0xCC9437);
_root["dust"+d].moveTo(500, 500);
_root["dust"+d].curveTo(600, 500, 600, 400);
_root["dust"+d].curveTo(600, 300, 500, 300);
_root["dust"+d].curveTo(400, 300, 400, 400);
_root["dust"+d].curveTo(400, 500, 500, 500);
_root["dust"+d].endFill();
_root["dust"+d]._xscale = Math.random()*1+.5;
_root["dust"+d]._yscale = _root["dust"+d]._xscale;
_root["dust"+d]._alpha = 100;
_root["dust"+d]._x = Math.random()*700-150;
_root["dust"+d].r = Math.random()*10+80;
_root["dust"+d].x = Math.sin((_root["dust"+d].r)*(Math.PI/180)
)*30;
_root["dust"+d].y = Math.cos((_root["dust"+d].r)*(Math.PI/180)
)*30;
_root["dust"+d]._x = -40;
_root["dust"+d]._y = Math.random()*450-50;
if (d>10037) {
d = 10000;
}
}

//END CODE

Response to Foss: Weather Script. 2005-07-27 13:55:21


nice complete code, but i suggest u post a demo.


website :: hugostonge.com

my job :: we+are

Response to Foss: Weather Script. 2005-07-27 13:59:43


Hawt.

The blizzard effect is the best, good job on those.


Sup, bitches :)

BBS Signature

Response to Foss: Weather Script. 2005-07-27 14:07:53


At 7/27/05 01:59 PM, -liam- wrote: Hawt.

Incredibly. Man, I just luv when stuff is really, really completed like this. <3
Myself, I'll code my own weather, but this is good for those who don't.


BBS Signature

Response to Foss: Weather Script. 2005-07-27 14:14:19


Response to Foss: Weather Script. 2005-07-27 23:44:37


could i use this in my game. it seems to work well

http://img50.imagesh..rapeanator2x47mn.swf

as you can see if you go towards the storm you go slower
and faster if you go with.
shoot with space

Response to Foss: Weather Script. 2005-07-27 23:57:01


Wow... this is really cool! *bookmarks page*


#include <stdio.h>

char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";

main() {printf(p,10,34,p,34,10);}

BBS Signature

Response to Foss: Weather Script. 2005-07-28 00:03:35


Is Flash MX 2004 the only version that can use .as files?


BBS Signature

Response to Foss: Weather Script. 2005-07-28 00:04:28


not at all, you can import them using include in flash mx, but it's kinda different,

Response to Foss: Weather Script. 2005-07-28 00:07:55


At 7/28/05 12:04 AM, Inglor wrote: not at all, you can import them using include in flash mx, but it's kinda different,

What's different about it? I've tried saving things in notebook as .as files but Flash (MX) does not read them. Is there something I have to do to get them imported?


BBS Signature

Response to Foss: Weather Script. 2005-07-28 00:13:35


you need to use the #include command explained in AS: Modular programming, and remove all the smart syntax like function return values and so on. (I think flash mx (the most updated one)) has AS 2 enabled (the most updated version) check it out.

Response to Foss: Weather Script. 2005-07-28 00:24:16


At 7/28/05 12:13 AM, Inglor wrote: you need to use the #include command explained in AS: Modular programming, and remove all the smart syntax like function return values and so on. (I think flash mx (the most updated one)) has AS 2 enabled (the most updated version) check it out.

Thanks. That definitely helps!


BBS Signature

Response to Foss: Weather Script. 2005-07-28 00:30:15


sorry to be unrelated, how soon will your zombie game be done ;)?

Response to Foss: Weather Script. 2005-07-28 00:35:22


At 7/28/05 12:30 AM, Inglor wrote: sorry to be unrelated, how soon will your zombie game be done ;)?

who are you talking to????

Response to Foss: Weather Script. 2005-07-28 00:47:08


to Atomic Sponge, isn't that a bit obvious

Response to Foss: Weather Script. 2005-07-28 00:49:39


That's great.


wtfbbqhax

Response to Foss: Weather Script. 2005-07-29 14:46:05


This weekend I will try to update this. I've been swamped with school work.

Response to Foss: Weather Script. 2005-07-29 14:51:53


You know what would be really cool for this? Being able to customise the strength of the precipitation from a user control. To create a light snowstorm or a heavy sandstorm, for example.

Might tinker with it in a while to see if I can get that effect...


...

BBS Signature

Response to Foss: Weather Script. 2005-12-17 16:43:05


i am trying to get a randomation effect where when the player walks off the scree there is a 50% chance of any wheather being played. here is my code.

onClipEvent (enterFrame) {
if (this.hitTest(_root.player)) {
_root.player._x=0
_root.oneinfour = random(7)+1;
if (_root.oneinfour == 1) {
_root.startWeather("snow", 400, 550);
} else if (_root.oneinfour == 2) {
_root.startWeather("dust", 400, 550);
} else if (_root.oneinfour == 3) {
_root.startWeather("rain", 400, 550);
} else if (_root.oneinfour == 4) {
_root.startWeather("blizzard", 400, 550);
} else {
_root.stopWeather();
}
}
}

but that doesnt work, sometimes i get multiple wheather effects!!!
here is an example if u want to see what i mean

PLEASE help me, i really need this cool wheather code for my game