// colormap.wdl find the color by a terrain under a entity (most the player) // by Lolek september 2003 /changed august 2004 now ready for A6.2 // www.lolek.net bmap* mymap; entity* myter; var terrain_ver[3] = 0,0,0; //world pos of terrain vertex 1 var terrain_ver_frc[3] = 0,0,0; //decimals of terrain vertex1 var terrain_ver_mov[3] = 0,0,0; //contain the shift from // terrain vertex 1 to world xy = 0 var colormap_x = 0; //pos x of colorpixel in the colormap var colormap_y = 0; //pos y of colorpixel in the colormap var cmap_temp_x = 0; //intern player pos x rescaled on terrain scale = 1 var cmap_temp_y = 0; //intern player pos y rescaled on terrain scale = 1 var colormap_frc_x = 0; //decimals of colormap pos x var colormap_frc_y = 0; //decimals of colomap pos y //put the terrain scale into terrain skill1 //put the proportion between original terrain & colormap size into terrain skill2 //example: terrain originalsize 1000x1000 pixel, colormap size 500x500 pixel = 2:1 //now write into terrain skill2 = 2 ! DEFINE TERRAIN_SCALE,skill1; DEFINE COLORMAP_SCALE,skill2; // uses: TERRAIN_SCALE, COLORMAP_SCALE action terrain_colmap //give this action to terrain in WED { myter= my; myter.TERRAIN_SCALE = my.skill1; myter.COLORMAP_SCALE = my.skill2; ent_vertex(terrain_ver,1); //get vertex 1 pos from WED terrain_ver.x = terrain_ver.x / myter.TERRAIN_SCALE; //rescale vertex 1 back to terrain_ver.y = terrain_ver.y / myter.TERRAIN_SCALE; //original terrain_size = scale 1 terrain_ver_frc.x = frc(terrain_ver.x); terrain_ver_frc.y = frc(terrain_ver.y); if (terrain_ver_frc.x >= 0.5) { //round up > 0.5 if (terrain_ver.x < 0) { //if vertex1 pos_x negativ terrain_ver.x -= 1;} //-1 else {terrain_ver.x += 1;} //else positiv +1 } if (terrain_ver_frc.y >= 0.5) { //round up > 0.5 if (terrain_ver.y < 0) { //if vertex pos_y negativ terrain_ver.y -= 1;} //-1 else {terrain_ver.y += 1;} //else positiv +1 } terrain_ver.x = int(terrain_ver.x); //integer vertex pos_x terrain_ver.y = int(terrain_ver.y); //integer vertex pos_y terrain_ver_mov.x = terrain_ver.x; terrain_ver_mov.y = terrain_ver.y; if(terrain_ver_mov.x < 0) { vec_inverse(terrain_ver_mov.x); } if(terrain_ver_mov.y < 0) { vec_inverse(terrain_ver_mov.y); } } //in the vector rgb_vec can find the terrain color under the entity //in this order: rgb_vec.blue, rgb_vec.green and rgb_vec.red //in the soundmap example i use the colorvector to give the player the right sound under his feets. var rgb_vec[3];//blue,green,red vector var pix_alpha; //pixel alpha 0 var format; //bitmap format var pixel; //pixelcolor function pixelcolor(colormap_x,colormap_y) { while(mymap == 0) { wait(1); } format = bmap_lock(mymap,0); pixel = pixel_for_bmap(mymap,colormap_x,colormap_y); // get the pixel under the entity pixel_to_vec(rgb_vec,pix_alpha,format,pixel); // store pixel color in temp bmap_unlock(mymap); } function color_on_terrain() { //give this function to entity (player) while(myter == NULL) { wait(1); } cmap_temp_x = my.x; //copy my pos_x to colormap_pos cmap_temp_y = my.y; //copy my pos_y to colormap_pos cmap_temp_x = cmap_temp_x / myter.TERRAIN_SCALE; //rescale colormap pos to terrainbasic size cmap_temp_y = cmap_temp_y / myter.TERRAIN_SCALE; colormap_frc_x = frc(cmap_temp_x); colormap_frc_y = frc(cmap_temp_y); if (colormap_frc_x >= 0.5) { //round up > 0.5 if (cmap_temp_x < 0) { //if colormap pos_x negitiv cmap_temp_x -= 1;} //-1 else {cmap_temp_x += 1;} //else positiv +1 } if (colormap_frc_y >= 0.5) { //round up > 0.5 if (cmap_temp_y < 0) { //if colormap pos_y negativ cmap_temp_y -= 1;} //-1 else {cmap_temp_y += 1;} //else positiv +1 } cmap_temp_x = int(cmap_temp_x); //int colormap pos_x cmap_temp_y = int(cmap_temp_y); //int colormap pos_y if(terrain_ver.x < 0) { cmap_temp_x += terrain_ver_mov.x; } else { cmap_temp_x -= terrain_ver_mov.x; } if(terrain_ver.y < 0) { cmap_temp_y += terrain_ver_mov.y; vec_inverse(cmap_temp_y); } else { cmap_temp_y -= terrain_ver_mov.y; vec_inverse(cmap_temp_y); } if(myter.COLORMAP_SCALE <= 0) { //avoid crash myter.COLORMAP_SCALE = 1; } cmap_temp_x = cmap_temp_x / myter.COLORMAP_SCALE;//rescale terrainbasic size to colormap size cmap_temp_y = cmap_temp_y / myter.COLORMAP_SCALE; colormap_frc_x = frc(cmap_temp_x); colormap_frc_y = frc(cmap_temp_y); if (colormap_frc_x >= 0.5) { //round up > 0.5 if (cmap_temp_x < 0) { //if colormap pos_x negativ cmap_temp_x -= 1;} //-1 else {cmap_temp_x += 1;} //else positiv +1 } if (colormap_frc_y >= 0.5) { //round up > 0.5 if (cmap_temp_y < 0) { //if colormap posYx negativ cmap_temp_y -= 1;} //-1 else {cmap_temp_y += 1;} //else positiv +1 } cmap_temp_x = int(cmap_temp_x); //int colormap pos_x cmap_temp_y = int(cmap_temp_y); //int colormap pos_y colormap_x = cmap_temp_x; colormap_y = cmap_temp_y; pixelcolor(colormap_x,colormap_y); } action get_color //give this action to colormap bitmap in WED { mymap = bmap_for_entity(my,0); }