MODULE: Underwater v1.1

Started by Kweepa, Wed 19/08/2009 06:13:55

Previous topic - Next topic

Kweepa

Underwater module
v1.0 for AGS 2.72+

Distorts a background in a wibbly wavy way.
Hard to show a screenshot, but you can see it in action in this demo:
http://www.kweepa.com/step/ags/tech/UnderwaterDemo.zip
Get the module here:
http://www.kweepa.com/step/ags/tech/Underwater11.zip
Video on youtube:
http://www.youtube.com/watch?v=EP1iFfDPXvY

Version history:
1.1 Added characters and objects (depending on baseline)
1.0 Initial version

Steve
Still waiting for Purity of the Surf II

Dualnames

Are you married? Wow, subspark will love this!!! Thanks a lot stevey!!
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)

SSH

Is it possible to run this effect on only a small area?
12

Snake

Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

TerranRich

I wish people would post videos of their modules in action. :P

Thanks, Steve! This will be very useful to a lot of developers here :)
Status: Trying to come up with some ideas...

Kweepa

Quote from: TerranRich on Wed 19/08/2009 15:42:56
I wish people would post videos of their modules in action. :P
Be my guest! It would take me longer to record, convert, and upload the video than to write the module! :=

Quote from: SSH on Wed 19/08/2009 11:04:19
Is it possible to run this effect on only a small area?
Yes, that would be possible. Are you thinking about a window in an underwater base or something like that? I'll have a think about the best way to handle the edges.

Quote from: Dualnames on Wed 19/08/2009 08:16:10
Are you married? Wow, subspark will love this!!! Thanks a lot stevey!!
Sorry, yes I am!
I considered posting this in sparky's thread...
Still waiting for Purity of the Surf II

Joseph DiPerla

Wow. Nice job. Anyway you can get that to work along with the character? It just doesn't seem right that the character doesn't have the same effect happen to him.
Joseph DiPerla--- http://www.adventurestockpile.com
Play my Star Wars MMORPG: http://sw-bfs.com
See my Fiverr page for translation and other services: https://www.fiverr.com/josephdiperla
Google Plus Adventure Community: https://plus.google.com/communities/116504865864458899575

Kweepa

Quote from: Joseph DiPerla on Wed 19/08/2009 17:16:54
Anyway you can get that to work along with the character?
I'd have to have a third buffer, render the bg, characters and objects to that, then do the underwater effect on top (and hide the visible objects). I think it's easy enough to get the current frame for characters...
Still waiting for Purity of the Surf II

monkey0506

Quote from: SteveMcCrea on Wed 19/08/2009 17:50:42I think it's easy enough to get the current frame for characters...

Sure, that's easy enough:

Code: ags
ViewFrame *frame = Game.GetViewFrame(player.View, player.Loop, player.Frame);
DynamicSprite *sprite = DynamicSprite.CreateFromExisitingSprite(frame.Graphic);
if (frame.Flipped) sprite.Flip(eFlipLeftToRight);


Though you do have to use a DynamicSprite if the frame is flipped (otherwise you can just use the raw sprite number). You could avoid creating the sprite unnecessarily by doing something like:

Code: ags
ViewFrame *frame = Game.GetViewFrame(player.View, player.Loop, player.Frame);
DynamicSprite *sprite;
int graphic = frame.Graphic;
if (frame.Flipped) {
  sprite = DynamicSprite.CreateFromExistingSprite(graphic);
  sprite.Flip(eFlipLeftToRight);
  graphic = sprite.Graphic;
}


I am assuming that you're using a DrawingSurface at some point which the character sprites would be drawn onto? Because at that point it's safe to delete the DynamicSprite (if any) of course.

GarageGothic

Cool module. The functionality is very similar to the refraction part of my EffectObjects module, though that works on objects (as you can tell from the name) rather than backgrounds. Basically it turns any object into a lens which can scale/distort background, objects and characters behind it. I'm using 3.1.2, so DrawingSurface functions and CopyTransparencyMask are a great help. But I'm sure something similar could be done in 2.72.

The thing you have to remember if you want to RawDraw characters/objects onto the background before distorting it is to sort them by baseline first. Since characters and objects can move around and new characters can enter the room this has to be done every game loop, which is a bit of a pain but doesn't cause too much slowdown. Also, any walkbehinds within the distorted area would have to be faked by using objects.

Snake

Wow, if you can get this to work with the characters and objects too, that would be even better. I was actually going to ask about that in my first post but I had lost track of time and had to leave.
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Kweepa

Thanks monkey & GG for the pointers.
New version uploaded with a new helper module FakeScreen that composites objects and characters (sorted, scaled and transparent) onto a background frame before the Underwater module does its work. A walkbehind hides the actual objects and characters.

The demo has also been updated to reflect the changes.

Steve
Still waiting for Purity of the Surf II

monkey0506

Quote from: SteveMcCrea on Thu 20/08/2009 06:05:17A walkbehind hides the actual objects and characters.

So you have to cover the entire room in a walkbehind area, or does the module apply the effect to said area?

And you're welcome...looked over your code. Snazzy stuff you've got going on in there. :D

Kweepa

Quote from: monkey_05_06 on Thu 20/08/2009 06:16:51
Quote from: SteveMcCrea on Thu 20/08/2009 06:05:17A walkbehind hides the actual objects and characters.
So you have to cover the entire room in a walkbehind area...?
Yup! This is the easiest way to keep all the properties of the objects and characters intact. If you want to draw a window or porthole in front, you just set the walkbehind baseline above the window baseline. Then you can have a character walk in front of the window or swim behind it.
Still waiting for Purity of the Surf II

Kweepa

Still waiting for Purity of the Surf II

SSH

Hmm, what I actually really wanted was a reflective, wobbly surface of the water but only taking up a small part of the screen (e..g. in a fountain thats part of the background)
12

Kweepa

Then you want the Lake module!
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=27356.0
You'd need to cover up a bit of it with an object.
Still waiting for Purity of the Surf II

subspark

Good work Steve! I knew someone would tackle my idea. Although I'm sure it was hardly a tackle.

Many cheers,
Sparky.

Ali

#18
The demo looks great, I could watch it for ten minutes...

However I ran into problems using it in an 800x600 32bit game. It came out like this:


(The background was a pencil line drawing from uncle-mum's Stediddy game)

Before I added a full screen walkbehind the pink colour was constant and behind the characters. Now it flashes on and off - at about the default rate for background animation now that I think about it. I tried downgrading to 16 setting which had no effect and I lowered the game resolution but the magenta colour remained.


EDIT: Ignore all this, Steve. It looks like AGS corrupted the bitmap somehow when I exported it. Opening the file in MSPaint and saving it again made the magenta go away. Nothing to do with your module. Keep up the good work!

GarageGothic

Quote from: Ali on Sat 22/08/2009 18:38:45Now it flashes on and off - at about the default rate for background animation now that I think about it.

Have you tried calling SetBackgroundFrame(0) in the player_enters_room event (unless the module already does this)?

SMF spam blocked by CleanTalk