_______
English
#######

I thought, search for the "place gras on terrain code", cause i want
create the same like Sputnicker.

My problem:
The definition of COLOR to create the colormap with green channel.(function place_grass())
If i want define this line, my menue wont work-.-and i can t press anyone
to start my game.
What to do?
Help pls.
(place_tree function cleared)

______
German
######

Ich dacht mir, ich kram den Thread mal raus...da ich das selbe erreichen
moechte wie der Threadersteller.

Mein problem ist die definition COLOR damit RGB code der
farbkarte funktioniert.(function place_grass())
Definiere ich das allerdings, funktioniet mein menue code nicht mehr.
(z.B. kann ich keine panels mehr anklicken).
und ohne COLOR definition gehts nicht-.-
(Place_tree function entfernt...)

Bin natuerlich nicht weiter mit dem uebersetzen
gekommen.Aber bis dahin scheint alles zu funktionieren.
Viell. mal die _startup definition entfernen?!





Code:
function generate_grass_startup();
function color_map();
function place_grass();
function weaving_grass();

var skin_size_x; // Skin groesse an der -
var skin_size_y; // x,y achse

STRING* grass1_mdl = "grass1.mdl";
STRING* grass2_mdl = "grass2.mdl";
STRING* colormap_tga = "Colormap.tga";

BMAP* vegetation_map;

ENTITY* terrain1 = "test_terrain_unreal1.hmp";

#define grass_area skill1 // Gras um den Player 
#define grass_dist skill2 // Distance zwischen 2 Grasmodellen

// uses grass_area, grass_dist
action my_terrain()
{
	if (my.grass_area == 0) {my.grass_area = 500;} // default grass um den Player
	if (my.grass_dist == 0) {my.grass_dist = 50;} // default gras distanz zw. 2 modellen
	terrain1 = my;
	my.push = 3; // Terrain nicht durchdringen
}


function generate_grass_startup()
{
	max_entities = 1000;
	wait (3); // wait until the level is loaded
	VECTOR grass_pos;
	var grass_id = 1;
	VECTOR grass_coords;
	
	ent_create (colormap_tga, nullvector, color_map); // erstelle colormap
	
	while ((player == NULL) || (terrain1 == NULL) || (vegetation_map == NULL)) {wait (1);}
	grass_pos.x = player.x - terrain1.grass_area; // setzte Grass position
	grass_pos.y = player.y - terrain1.grass_area; // um den Spieler
	grass_pos.z = terrain1.z + 400; // richtung Himmel
	grass_coords.x = grass_pos.x;	
	grass_coords.y = grass_pos.y;
	while (grass_coords.x < player.x + terrain1.grass_area)
	{
		grass_pos.y = grass_coords.y + (random(0.2 * terrain1.grass_dist) - 0.4 * terrain1.grass_dist);
		grass_pos.x = grass_coords.x + (random(0.2 * terrain1.grass_dist) - 0.4 * terrain1.grass_dist);
		if (random (1) > 0.1)
		{
			you = ent_create (grass1_mdl, grass_pos.x, place_grass);
		}
		else
		{
			you = ent_create (grass2_mdl, grass_pos.x, place_grass);
		}

		you.skill1 = grass_id; 
		grass_id %= 10;
		grass_id += 1;
		grass_coords.y += terrain1.grass_dist;
		if (grass_coords.y > (player.y + terrain1.grass_area))
		{
			grass_coords.x += terrain1.grass_dist;
			grass_coords.y = player.y - terrain1.grass_area;
		}
	}
}
function color_map()
{
	set(my, PASSABLE | INVISIBLE);
 	vegetation_map = bmap_for_entity (my, 0);
	skin_size_x = bmap_width (vegetation_map); // get the size of the color map (same with the skin of the terrain)
	skin_size_y = bmap_height (vegetation_map); // on the x and y axis
}
 
function place_grass()
{
	COLOR pixel_color;
	var format;
	var pixel;
	var coords_x;
	var coords_y;
	VECTOR temp5;
	
	
	
	my.scale_x += 0.1 - random(2) / 10;
	my.scale_y = my.scale_x;
	my.scale_z = my.scale_x;
	set( my, INVISIBLE | PASSABLE | TRANSLUCENT);
	my.push = 2;
	weaving_grass();
	while (player != NULL)
	{
		//temp = random(10);
		//wait (temp); // spread the cpu load over 10 consecutive frames
		wait(1);
		my.alpha = minv (100, (10000 / ((vec_dist(player.x, my.x) + 1)))); // play with 10000
		my.x = cycle(my.x, camera.x - terrain1.grass_area, camera.x + terrain1.grass_area); // wrap the grass around player's position
		my.y = cycle(my.y, camera.y - terrain1.grass_area, camera.y + terrain1.grass_area); // on the x and y axis
		my.z = terrain1.z + 400; // and place it up high in the sky
	
		vec_set(temp5.x, my.x);
		temp5.z -= 10000;
		my.skill10 = c_trace (my.x, temp.x, IGNORE_SPRITES | IGNORE_PASSABLE | IGNORE_PUSH);
		// the tracing ray has hit the terrain? (not the surrounding hollowed cube)
		if ((trace_hit != 0) && (you != NULL)) 
		{
			coords_x = (my.x - terrain1.min_x) / ((terrain1.max_x - terrain1.min_x) / skin_size_x); // get the coordinates of the current pixel
			coords_y = (terrain1.max_y - my.y) / ((terrain1.max_y - terrain1.min_y) / skin_size_y); // on x and y
			format = bmap_lock (vegetation_map, 0);
			pixel = pixel_for_bmap(vegetation_map, coords_x, coords_y);
			pixel_to_vec (pixel_color, NULL, format, pixel); // store the color of the pixel in pixel_color 
			bmap_unlock (vegetation_map);
			// detected a green area on the color map bitmap?
			if (pixel_color.green == 255)
			{
				my.z -= my.skill10 - 1; // then place a grass model on the ground (skill10 was used to store the result of the c_trace operation)
				vec_to_angle (my.pan, normal); // and align it properly
				my.tilt -= 90;
				reset(my, INVISIBLE);
			}
			else // this isn't a green pixel on the color map?
			{
				set(my, INVISIBLE);
			}
		}
		wait (1);
	}
}


function weaving_grass()
{
	var grass_angles;
	var grass_speed;
	grass_speed = 2 + random(5);
	while (1)
	{
		grass_angles += grass_speed * time_step; // allow the grass to weave
		my.roll += 0.02 * sin(grass_angles);
		wait (1);
	}
}





Last edited by Ayumi; 07/27/09 03:05.