User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 19

Thread: Snow!

  1. #1
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.54%

    Snow!

    To celebrate the fact that Winter is nearly done, I present the dynamic snow script!

    Code:
    const int screenHeight = 176;
    const int screenWidth = 256;
    
    ffc script Snow {
    	void run(int flakes, int wind) {
    		
    		//I do not know how big this can be safely increased.
    		//However, 200 flakes should be fine for most situations
    		int snow[200];
    		flakes = Floor(flakes);
    		wind = Floor(wind);
    		
    		if(flakes > 200) flakes = 200;
    		
    		//if the wind isn't very strong, let's thin out the snowfall
    		//a bit. It looks much better this way.
    		if(Abs(wind) < 4) {
    			flakes -= 45 - Abs(wind) * 15;
    		}
    		
    		//Calculating the size and position of a paralellogram of
    		//snow hurt my brain :(
    		int xmod = 0;
    		
    		//And, it took me an hour to determine this block
    		if(wind > 0) {
    			xmod = wind * -160;
    		} else {
    			xmod = 0;
    		}
    		
    		//Give each flake an initial position on screen, as
    		//though it's been snowing the whole time ;)
    		for(int i = 0; i < flakes; i++) {
    			snow[i] = Rand(screenWidth + Abs(wind) * 160) + xmod + 3000 + (Rand(screenHeight - 1) + 1) / 1000;
    		}
    		
    		int x; int y;
    		//main loop
    		while(true) {
    			
    			//for each snow flake...
    			for(int i = 0; i < flakes; i++) {
    				//I pack the snow flake like: x . y
    				x = Floor(snow[i]);
    				y = (snow[i] - x) * 1000;
    				
    				//the 3000 is simply to prevent negative values in the snow[] array
    				//3000 is insufficient for wind strengths > 18
    				//(but, that's already stronger than any wind on earth!)
    				x -= 3000;
    				
    				//move the snow
    				y += 1;
    				x += Rand(3) - 1;
    				x += wind;
    				
    				//if the snow goes off the bottom, remove it and regenerate it
    				//also, if there's wind, clip the snow that blows off the side
    				if(y > screenHeight || (wind > 0 && x > screenWidth + 5) || (wind < 0 && x < -5)) {
    					x = Rand(screenWidth + Abs(wind) * 160) + xmod;
    					
    					y = 1;
    				}
    				
    				//draw the on-screen flakes
    				if(x >= 0 && x < screenWidth) Screen->Circle(6, x, y, 1, 1, 1, 0, 0, 0, true, 128); //Screen->PutPixel(6, x, y, 1, 0, 0, 0, 128);
    				
    				//pack the snow again :P
    				snow[i] = x + 3000 + y / 1000;
    				
    			}
    			
    			Waitframe();
    		}
    	}
    }
    It's really easy: Just set the script to an invisible FFC, set D0 to the number of desired snowflakes on screen at once (current max is 200, but that's easily raised if necessary), and even add a bit of wind by setting D1 (max is +/-18, but the snow is almost horizontal at that speed!).

    Let me know what you think!
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  2. #2
    On top of the world ShadowTiger's Avatar
    Join Date
    Jun 2002
    Location
    Southeastern New York
    Posts
    12,231
    Mentioned
    31 Post(s)
    Tagged
    3 Thread(s)
    vBActivity - Stats
    Points
    29,579
    Level
    46
    vBActivity - Bars
    Lv. Percent
    60.35%
    Achievements It's over 9000!

    Re: Snow!

    I got three semi-identical errors when compiling the script, all related to the function "Floor" ... Line 10, 11, and 45. Error S10: Function Floor is undeclared.


    Still, thank you for the script. :)

  3. #3
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.73%

    Re: Snow!

    You need to
    Code:
    import "std.zh"
    ST =)

  4. #4
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.54%

    Re: Snow!

    Oh come on. Surely that's implied by now...
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  5. #5
    Octorok
    Join Date
    Oct 2006
    Age
    47
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    968
    Level
    10
    vBActivity - Bars
    Lv. Percent
    78.78%

    Re: Snow!

    The script looks interesting, it seems you can extend some of the ideas to make a full parametrized 2D particle system. Anyway I do have a question: why are you using Screen->Circle() instead of Screen->PutPixel()? It looks like you used the latter initially but changed your mind. At first I thought you wanted snow flakes larger then 1 pixel - but it looks like your circle has a radius of 1... I haven't actually used PutPixel or Circle so I could just be missing something :)

  6. #6
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.54%

    Re: Snow!

    It looks much better with the radius 1 circle.

    And, incidentally, a circle with a radius of 1 actually has a width of 2 (since, radius is the distance from the centre to the edge )

    And, also, it seems that a radius 1 circle is actually drawn like this:

    Code:
     #
    ###
     #
    Finally, perhaps you could make a full particle system, but I doubt it. As it currently stands, there's no room to store any other information about a particle other than its position. In my Starfield script, I used the same idea, but represented position in polar notation (since, the stars need to travel in a circle).

    In both of these scripts, I don't have to store speed or direction (since, snow always falls down, and stars always shoot outward).

    Plus, a more complicated system would be rather slow for anything more than a handful of particles.
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  7. #7
    Octorok
    Join Date
    Jan 2008
    Age
    32
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    939
    Level
    10
    vBActivity - Bars
    Lv. Percent
    63.67%

    Re: Snow!

    Nice script. :)

    But wouldn't it be simple to just draw falling snow combos on layer 5 instead?

  8. #8
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.54%

    Re: Snow!

    If you count finding and setting up a separate screen, and then setting it as layer 5, and oops, it's the wrong Palette/CSet as easier than plopping down an FFC, then yes.

    However, try getting dynamic looking snow out of a combo...
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  9. #9
    The Time-Loop Continues ZC Developer
    Gleeok's Avatar
    Join Date
    Apr 2007
    Posts
    4,826
    Mentioned
    259 Post(s)
    Tagged
    10 Thread(s)
    vBActivity - Stats
    Points
    12,959
    Level
    33
    vBActivity - Bars
    Lv. Percent
    26.2%

    Re: Snow!

    Cool. Hands down, the best snow particle ZScript in existence. Don't question it's usefulness or compare it to layers people, just try it.


    Quote Originally Posted by pkmnfrk View Post
    It looks much better with the radius 1 circle.

    And, incidentally, a circle with a radius of 1 actually has a width of 2 (since, radius is the distance from the centre to the edge )
    Due note that circles seem to be pretty damn slow in allegro. I'd bet drawing those five pixels using putpixel would be a whole lot faster, but then you wouldn't have the option of drawing different sized circles.

    Quote Originally Posted by pkmnfrk View Post
    Finally, perhaps you could make a full particle system, but I doubt it. As it currently stands, there's no room to store any other information about a particle other than its position.
    You might like to know that Grikarugun has had a dynamic particle system in it for a little while now. :) (I've just been busy guys, sorry)

    Quote Originally Posted by pkmnfrk View Post
    Plus, a more complicated system would be rather slow for anything more than a handful of particles.
    Actually I'm reasonably sure it's faster.
    This post contains the official Gleeok seal of approval. Look for these and other posts in an area near you.

  10. #10
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.54%

    Re: Snow!

    Quote Originally Posted by Gleeok View Post
    Due note that circles seem to be pretty damn slow in allegro. I'd bet drawing those five pixels using putpixel would be a whole lot faster, but then you wouldn't have the option of drawing different sized circles.
    Are you sure about that? I would think that the overhead of calling Screen->PutPixel() 5 times would offset any gain from not drawing a miniature circle.

    Remind me to profile this at some point.


    Quote Originally Posted by Gleeok View Post
    You might like to know that Grikarugun has had a dynamic particle system in it for a little while now. :) (I've just been busy guys, sorry)
    I'll have to check it out. Are the scripts available?

    Quote Originally Posted by Gleeok View Post
    Actually I'm reasonably sure it's faster.
    Perhaps, perhaps not. But, I would bet a million rupees that a general purpose particle system would be slower compared to one tailor made for, say, snow.

    Edit, RE PutPixel vs Circle:

    I just did some testing. Although I got slow down for flake quantities > 500 (or so), I discovered something else in favour of using Circle. Although I have absolutely no idea how the primitive drawing system works in ZC, I can make a guess based on this experiment.

    Essentially, I built in a way to switch between 5 PutPixels and 1 Circle. At 500 flakes (thats 500 circles vs 2500 PutPixels), half the PutPixel flakes didn't show up! I would switch between the two, and watch half the snow flakes blink in and out of existence. I am of the opinion that I used up all the Primitive drawing command buffer (or something to that effect).

    So. I'm sticking with Screen->Circle for now.
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social