Creating a Basic Shoreline with Script (WDL)

Posted By: Garrettwademan

Creating a Basic Shoreline with Script (WDL) - 02/18/10 05:27

I figured this would be right place to put this topic. I was looking for a way to make a real basic shoreline effect on my terrain where it meets the ocean/water, here is what I came up with.



I am doing a simple scan on the map to find the edges and where there should be some white water. You can download the code and TGA file I used for this script. You can of course improve on this if you wish. If used efficiently, it won't tax your system to much. I found if you abuse it, it can drop the FPS of your game fairly quick. Well, here is the poor man's shoreline info. Hope you find a place to use this.

http://www.garrettwademan.com/3dgs/shoreline/shoreline.zip

Here are the two functions I used, just adjust the variables and call "find_shore_line".

Code:
function wave_control(){
	my.transparent = on;  //Make shore line a transparent
	my.red = 255;  //Adjust colors, this may not do anything depending on which water you are using
	my.blue = 255;
	my.green = 255;
	my.tilt += 90;  //Tilt the TGA file so it is flat
	my.bright = on;  //Add brightness to the TGA file
	my.ambient = 100;  //Ambient look
	my.albedo = 100;  //Albedo look
	
	while(1){
		wait(random(50));  //Add some random wait time so it doesn't look syncronized
		my.scale_x = 0.5;  //Start scale at half size, you can adjust this to your needs
		my.scale_y = my.scale_x;
		my.alpha = 100;  //Start out as 100 alpha value, change this to your needs
		while(my.scale_x < 10){  //Go until the size = 10, adjust this to your needs
			my.alpha -= 0.3;  //How fast this TGA shore line fades		
			my.scale_x += 0.03;  //Make the shore line effect larger as time goes on
			my.scale_y = my.scale_x;
			wait(1);
		}
		wait(1);
	}
}

function find_shore_line(){
	var start_x = 0;
	var start_y = 0;
	var height = 0;
	var old_height = 0;

	start_x = 0;  //This is where you want to start scanning, this should be on the corner of your map at the lowest value
	start_y = 0;  //Same as above, except on the y axis
	
	while(start_x < 80000){  //Set this number "80000" to the max scan on the X axis
		while(start_y <= 15000){  //Set this number "15000" to the max scan on the Y axis
			old_height = height;  //Take note of the old height checked
			
			//For the code below, start scane for height of water line.  The 1975 will be 25 quants above the water line and 1950 is the
			//water line itself, you can adjust the 1975 to a number just right above your water line, and 1950 to your water line or just
			//1 or 2 quants below water line, up to you
			height -= c_trace(vector(start_x,start_y,1975), vector(start_x,start_y,1950), ignore_sprites + ignore_passable + ignore_flag2 + ignore_models);
			
			if(old_height != height){  //If this scan senses a change in height because start of terrain, execute below code
				ent_create("shore.tga",vector((start_x + 0),start_y,1950.5), wave_control);  //Create the shoreline, only change the 1950 to match your water level
				old_height = 1950;  //Reset the old height to your water line
				height = 0;  //Reset your height check
			}			
			start_y += 100;  //This will scan every 100 quants on the Y axis
		}
		
		start_x += 100;  //This will scane every 100 quants on the X axes
		start_y = 0;  //Reset the Y scan to begin over again using a different vector
		wait(1);
	}
}


Posted By: Blink

Re: Creating a Basic Shoreline with Script (WDL) - 02/18/10 14:12

Awesome contribution! I am glad to see you are still at it! your pesistance gives me hope, maybe one day i can finish my project.
Posted By: Garrettwademan

Re: Creating a Basic Shoreline with Script (WDL) - 02/18/10 17:22

Hey there. Yea, I am still whacking away at the game. I am expanding my terrain even more this time to get more land. It is a slow process, but every line of code will get me closer to the end.
Posted By: mikaldinho

Re: Creating a Basic Shoreline with Script (WDL) - 02/18/10 17:39

thanks for the wonderful script man! this will help me so much.
Posted By: Blink

Re: Creating a Basic Shoreline with Script (WDL) - 02/18/10 17:43

Good luck! I am looking forward to seeing the results.
Posted By: mikaldinho

Re: Creating a Basic Shoreline with Script (WDL) - 02/18/10 17:44

are you saying good luck to me or to Garettewademan?

if to me thanks for that.
Posted By: Garrettwademan

Re: Creating a Basic Shoreline with Script (WDL) - 02/20/10 00:11

As I have been working more with this, I have realized that if you want to improve the speed of the game, you can change the WAIT value in the following loop.

Code:
while(1){
		wait(random(50));  //Add some random wait time so it doesn't look syncronized
		my.scale_x = 0.5;  //Start scale at half size, you can adjust this to your needs
		my.scale_y = my.scale_x;
		my.alpha = 100;  //Start out as 100 alpha value, change this to your needs
		while(my.scale_x < 10){  //Go until the size = 10, adjust this to your needs
			my.alpha -= 0.3;  //How fast this TGA shore line fades		
			my.scale_x += 0.03;  //Make the shore line effect larger as time goes on
			my.scale_y = my.scale_x;
			wait(5);
		}
		wait(5);
	}


Posted By: Blink

Re: Creating a Basic Shoreline with Script (WDL) - 02/20/10 13:08

i was talking to garrett.
Posted By: mikaldinho

Re: Creating a Basic Shoreline with Script (WDL) - 02/20/10 19:22

oh. ok. i was only asking
© 2024 lite-C Forums