Author Topic: MODULE: Underwater v1.1  (Read 11126 times)

Kweepa

  • Mutated Guano Deviser
    • Best Innovation Award Winner 2009, for his modules and plugins
    •  
  • Kweepa worked on a game that was nominated for an AGS Award!
Re: MODULE: Underwater v1.1
« Reply #20 on: 22 Aug 2009, 19:33 »
Have you tried calling SetBackgroundFrame(0) in the player_enters_room event (unless the module already does this)?

It does. :=
See the repeatedly_execute function below:
Code: Adventure Game Studio
  1. // Underwater module script
  2.  
  3. __Underwater Underwater;
  4. export Underwater;
  5.  
  6. bool gEnabled = false;
  7.  
  8. float tt = 0.0;
  9. float t = 0.0;
  10.  
  11. float a[5], b[5], c[5];
  12.  
  13. function __Underwater::Enable()
  14. {
  15.   float scalar = 2000.0;
  16.   int i = 0;
  17.   while (i < 5)
  18.   {
  19.     a[i] = IntToFloat(Random(2000)*(2*Random(1)-1))/scalar;
  20.     b[i] = IntToFloat(Random(2000)*(2*Random(1)-1))/scalar;
  21.     c[i] = IntToFloat(Random(2000)*(2*Random(1)-1))/2000.0;
  22.     i++;
  23.   }
  24.   gEnabled = true;
  25. }
  26.  
  27. function __Underwater::Disable()
  28. {
  29.   gEnabled = false;
  30. }
  31.  
  32. float get_gradient_x(int xi, int yi)
  33. {
  34.   float x = IntToFloat(xi)/160.0 - 1.0;
  35.   float y = IntToFloat(yi)/160.0 - 1.0;
  36.  
  37.   float dx = 0.0;
  38.   int i = 0;
  39.   while (i < 5)
  40.   {
  41.     dx += a[i]*t*Maths.Cos(a[i]*t*x + b[i]*t*y + c[i]);
  42.     i++;
  43.   }
  44.  
  45.   return dx;
  46. }
  47.  
  48. float get_gradient_y(int xi, int yi)
  49. {
  50.   float x = IntToFloat(xi)/160.0 - 1.0;
  51.   float y = IntToFloat(yi)/160.0 - 1.0;
  52.  
  53.   float dy = 0.0;
  54.   int i = 0;
  55.   while (i < 5)
  56.   {
  57.     dy += b[i]*t*Maths.Cos(a[i]*t*x + b[i]*t*y + c[i]);
  58.     i++;
  59.   }
  60.  
  61.   return dy;
  62. }
  63.  
  64. function offset_a_block(DrawingSurface *surf, int x, int y, int w)
  65. {
  66.   int xoff = FloatToInt(1.0*get_gradient_x(x + w/2, y + w/2));
  67.   int yoff = FloatToInt(1.0*get_gradient_y(x + w/2, y + w/2));
  68.   DynamicSprite *ds = DynamicSprite.CreateFromBackground(1, x, y, w, w);
  69.   #ifver 3.00
  70.   surf.DrawImage(x - xoff, y - xoff, ds.Graphic);
  71.   #endif
  72.   #ifnver 3.00
  73.   RawDrawImage(x - xoff, y - yoff, ds.Graphic);
  74.   #endif
  75. }
  76.  
  77. function repeatedly_execute()
  78. {
  79.   if (gEnabled)
  80.   {
  81.     tt = tt + 0.01;
  82.     t = 2.0*Maths.Pi*Maths.Sin(tt);
  83.  
  84.     SetBackgroundFrame(0);
  85.     // repeatedly grab a random chunk from bg 1 and paste it to bg 0, slightly offset
  86.     #ifver 3.00
  87.     DrawingSurface *surf = Room.GetDrawingSurfaceForBackground(0);
  88.     #endif
  89.     int i = 0;
  90.     while (i < 128)
  91.     {
  92.       i++;
  93.       int w = Room.Width/32;
  94.       int x = Random(Room.Width - 1 - w);
  95.       int y = Random(Room.Height - 1 - w);
  96.  
  97.       offset_a_block(surf, x, y, w);
  98.     }
  99.  
  100.     // draw some more around the player
  101.     ViewFrame *frame = Game.GetViewFrame(player.View, player.Loop, player.Frame);
  102.     int graphic = frame.Graphic;
  103.     int height = FloatToInt(IntToFloat(Game.SpriteHeight[graphic]*player.Scaling)/100.0);
  104.     int width  = FloatToInt(IntToFloat( Game.SpriteWidth[graphic]*player.Scaling)/100.0);
  105.     int left = player.x - width/2;
  106.     int top = player.y - height - player.z;
  107.  
  108.     i = 0;
  109.     while (i < 32)
  110.     {
  111.       i++;
  112.       int w = Room.Width/64;
  113.       int x = left - w/2 + Random(width - 1);
  114.       int y = top - w/2 + Random(height - 1);
  115.       if (x < 0) x = 0;
  116.       else if (x >= Room.Width - w) x = Room.Width - 1 - w;
  117.       if (y < 0) y = 0;
  118.       else if (y >= Room.Height - w) y = Room.Height - 1 - w;
  119.      
  120.       offset_a_block(surf, x, y, w);
  121.     }
  122.     #ifver 3.00
  123.     surf.Release();
  124.     #endif
  125.   }
  126. }
  127.  
Still waiting for Purity of the Surf II

TerranRich

  • I'm Terran Riiiick!
    • I can help with characters
    •  
    • I can help with proof reading
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
  • TerranRich worked on a game that was nominated for an AGS Award!
Re: MODULE: Underwater v1.1
« Reply #21 on: 25 Aug 2009, 05:43 »
My God, Steve, you have a ton of modules, all of them very useful and amazingly well-done! I gotta see which ones I can use. ;D
Status: Trying to come up with some ideas...

Kweepa

  • Mutated Guano Deviser
    • Best Innovation Award Winner 2009, for his modules and plugins
    •  
  • Kweepa worked on a game that was nominated for an AGS Award!
Re: MODULE: Underwater v1.1
« Reply #22 on: 25 Aug 2009, 06:20 »
I've got a way to go to catch up with SSH or monkey_05_06!
Still waiting for Purity of the Surf II

monkey0506

  • AGS Project Tracker Admins
  • Tasting the banhammer. Strangely, tastes like ham.
Re: MODULE: Underwater v1.1
« Reply #23 on: 25 Aug 2009, 06:30 »
To be fair though Steve your modules tend to be way cooler than mine. Most of mine are based on other people's scripts (like AGSMuse and QueuedSpeech) or a generic concept that's not really that difficult (like GUIAnimation for example where I just change the GUI.BackgroundGraphic property).

Yours implement 3D effects and things which I frankly don't understand what's happening at all! ::)
User was banned for this post.

Ascovel

  • Mittens Serf
  • The eyes of Rooster Cockburn
    • I can help with story design
    •  
  • Ascovel worked on a game that was nominated for an AGS Award!Ascovel worked on a game that won an AGS Award!
Re: MODULE: Underwater v1.1
« Reply #24 on: 01 Sep 2009, 16:22 »
For some reason everything stops moving during cutscenes. Any ideas?

EDIT: AH! I added "always" to "repeatedly_execute" and it did the trick.
« Last Edit: 01 Sep 2009, 16:31 by Ascovel »

Kweepa

  • Mutated Guano Deviser
    • Best Innovation Award Winner 2009, for his modules and plugins
    •  
  • Kweepa worked on a game that was nominated for an AGS Award!
Re: MODULE: Underwater v1.1
« Reply #25 on: 01 Sep 2009, 22:44 »
Ah yes, that'll do it.
It's probably worth putting out a new version with that change.
Still waiting for Purity of the Surf II

abstauber

  • Cavefish
  • Mittens Knight
  • still mowing the lawn
  • abstauber worked on a game that was nominated for an AGS Award!abstauber worked on a game that won an AGS Award!
Re: MODULE: Underwater v1.1
« Reply #26 on: 03 Sep 2009, 11:32 »
Wow, this is really a great module. Is there by any chance a source of all those algorithms, you're using?

Kweepa

  • Mutated Guano Deviser
    • Best Innovation Award Winner 2009, for his modules and plugins
    •  
  • Kweepa worked on a game that was nominated for an AGS Award!
Re: MODULE: Underwater v1.1
« Reply #27 on: 03 Sep 2009, 20:00 »
The source code is right up there ^^^. :=
The "magic" is in get_gradient_x/y, which just sum up some sine waves with different magnitude and phase, and are used to offset a block of pixels.
I don't have a specific reference. I just pulled the approach out of my arse. However, a quick web search for "2d fractal noise sum of sine waves" turned up this which seems similar:
http://developer.download.nvidia.com/SDK/9.5/Samples/samples.html#glsl_vertex_water
Still waiting for Purity of the Surf II

abstauber

  • Cavefish
  • Mittens Knight
  • still mowing the lawn
  • abstauber worked on a game that was nominated for an AGS Award!abstauber worked on a game that won an AGS Award!
Re: MODULE: Underwater v1.1
« Reply #28 on: 04 Sep 2009, 11:17 »
Hehe... that makes the module even more impressive :D

I once had a book about megademo-coding for Turbo Pascal, but unfortunately I've lost it :(
It was full of algorithms and 3d gimmicks... *sigh*

Re: MODULE: Underwater v1.1
« Reply #29 on: 10 Dec 2009, 11:35 »
thank Steve , this module is simply amazing

Kweepa

  • Mutated Guano Deviser
    • Best Innovation Award Winner 2009, for his modules and plugins
    •  
  • Kweepa worked on a game that was nominated for an AGS Award!
Re: MODULE: Underwater v1.1
« Reply #30 on: 15 Dec 2009, 03:06 »
thank Steve , this module is simply amazing

Glad you like it.
Let me know if you need any help integrating it into a game (that goes for everyone!). And also let me know if you release a game using it...
Still waiting for Purity of the Surf II

Re: MODULE: Underwater v1.1
« Reply #31 on: 26 Jan 2010, 15:30 »
Hi. I want to implement something like that in a completely different game engine and I thought this module could help me out. ... But I've trouble understanding how it works. ^^'

Starting here :
Code: Adventure Game Studio
  1. a[i] = IntToFloat(Random(2000)*(2*Random(1)-1))/scalar;
Get a random number between 0 and 2000, multiply by... either 0 or 1 ? then divide by 2000. I think I'm reading something wrong.

Then in get_gradient
Code: Adventure Game Studio
  1. float x = IntToFloat(xi)/160.0 - 1.0;
What's that 160 doing here ? Why -1 ?
I'll just trust you on the way to calculate dx and dy.

offset_a_block
Code: Adventure Game Studio
  1. int xoff = FloatToInt(1.0*get_gradient_x(x + w/2, y + w/2));
We're using the center of the chunk of background to displace as the argument for get_gradient, right ?

repeatedly_execute
Are you displacing 128 random chunks of background ?
I understand that first loop (I think), the rest of the function lost me.

I hope I'm not too annoying. >.>

Kweepa

  • Mutated Guano Deviser
    • Best Innovation Award Winner 2009, for his modules and plugins
    •  
  • Kweepa worked on a game that was nominated for an AGS Award!
Re: MODULE: Underwater v1.1
« Reply #32 on: 26 Jan 2010, 18:51 »
Code: Adventure Game Studio
  1. a[i] = IntToFloat(Random(2000)*(2*Random(1)-1))/scalar;
Get a random number between 0 and 2000, multiply by... either 0 or 1 ? then divide by 2000. I think I'm reading something wrong.
Yup; multiply by either -1 or 1; yup.
It's just a random float between -1 and 1. More complicated than it needs to be, sorry!

Quote
Code: Adventure Game Studio
  1. float x = IntToFloat(xi)/160.0 - 1.0;
What's that 160 doing here ? Why -1 ?
The 160 is the screen width divided by two. The -1 then makes x between -1 and 1.

Quote
Code: Adventure Game Studio
  1. int xoff = FloatToInt(1.0*get_gradient_x(x + w/2, y + w/2));
We're using the center of the chunk of background to displace as the argument for get_gradient, right ?
Yup, that's right.

Quote
repeatedly_execute
Are you displacing 128 random chunks of background ?
I understand that first loop (I think), the rest of the function lost me.
Yes, that's right.
The rest of the function displaces some more blocks near the player.

Good luck!
Still waiting for Purity of the Surf II

Cleanic

    • I can help with translating
    •  
Re: MODULE: Underwater v1.1
« Reply #33 on: 19 May 2013, 16:07 »
 First of all, I suck at scripting when it gets the tiniest bit complicated. So I was trying to use your module for a game (MAGS Underwater) and when using the fakescreen I don't really understand what are the parameters I need to put... one int for objects another one for characters and the baseline? I don't really get it (the numbers I 'intuitively' try result in error)
"Loose ends have a way of strangling you"

Re: MODULE: Underwater v1.1
« Reply #34 on: 13 Aug 2017, 20:47 »
Hey, does someone has a backup of this code somewhere? I am really interested in the code :). Also the FakeScreen module, I couldn't find it's topic. :~(

arj0n

  • Mittens Vassal
  • why do meteors always land in craters?
  • arj0n worked on a game that was nominated for an AGS Award!
Re: MODULE: Underwater v1.1
« Reply #35 on: 13 Aug 2017, 22:36 »

Re: MODULE: Underwater v1.1
« Reply #36 on: 13 Aug 2017, 23:06 »
Thanks arj0n ! Just downloaded both modules! :]

MJL

  • Global Moderator
  • Mittens Duke
  • Mittens Founder
    • Lifetime Achievement Award Winner
    •  
  • MJL worked on a game that was nominated for an AGS Award!MJL worked on a game that won an AGS Award!
Re: MODULE: Underwater v1.1
« Reply #37 on: 14 Aug 2017, 10:42 »
thanks arjon + eri0o! i was also going to ask for underwater a couple days ago :)

Danvzare

  • The Man with No Name
    • I can help with AGS tutoring
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with story design
    •  
    • I can help with voice acting
    •  
Re: MODULE: Underwater v1.1
« Reply #38 on: 14 Aug 2017, 11:12 »
I never knew I needed this module until now. :shocked:

Mehrdad

    • I can help with animation
    •  
    • I can help with characters
    •  
    • I can help with story design
    •  
    • I can help with web design
    •  
Re: MODULE: Underwater v1.1
« Reply #39 on: 07 Oct 2017, 09:04 »

Maybe I'm wrong to use this module. But I get an error in AGS 3.4.1. I only add underwater.Enabled(); in one of my rooms. Is it enough or I need other codes too?

Edit: Problem solved. I forgot duplicate frame. It works perfectly on 3.4.1 too.
« Last Edit: 08 Oct 2017, 08:31 by Mehrdad »