Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (henrybane), 1,499 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Scan texture for terrains. :) #55943
09/23/05 23:39
09/23/05 23:39
Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
XNASorcerer Offline OP
Expert
XNASorcerer  Offline OP
Expert

Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
If you are making a car game and wants to make the car to see the road, you can use a c_trace scan_texture to get the name of the blocks texture. But if you want to use a terrain, that won't work. The solution is to have a texture painted with defined color to define areas as your terrains second skin, or the first one if you are using the Multitexturing shader from templates.

I don't know if this is the best way, but it works fine. More or less like the Lolek's code. This code will play a sound if you are inside the red area.(You can change that. )
And this was made by Spaz and me.

You will need a skin like this, that fits your terrain:


Here is the code:
Code:
 
//This code is supposed to work with PlCar01.wdl from templates because of the plCar01_entity pointer.

entity* myter;
bmap* get_skin;
var get_pixel_var;
sound sndOutOfRoad = <horn.wav>;

var TerrainVert1X;
var TerrainVert1Y;
var TerrainWidth;
var SkinSize = 512; // Give this var the size of the skin that you are going to use.


// Give this action to your terrain or copy the inside code to after
//the last line of the terrain_multi3 action from templates
Action Terrain
{
//...
myter = my;
my.skill48 = 0; //tempskill
my.skill49 = -99999999; //tempskill
WHILE(1)
{
my.skill48 += 1;
vec_for_vertex(temp,my,my.skill48);
IF(temp.x < my.skill49)
{
break;
}
my.skill49 = max(my.skill49,temp.x);
}
my.skill49 = ent_vertices(me)/my.skill48;
vec_for_vertex(my.skill50,my,1);
vec_for_vertex(my.skill53,my,ent_vertices(me));

TerrainVert1X = my.skill50;
TerrainVert1Y = my.skill51;
TerrainWidth = (my.skill53 - TerrainVert1X);
}

function get_pixel(a)
{
var DeltaX;
var DeltaY;
var c;
var d;
DeltaX = plCar01_entity.X - TerrainVert1X;
DeltaY = TerrainVert1Y - plCar01_entity.Y;
c = (SkinSize*(DeltaX/TerrainWidth));
d = (SkinSize*(DeltaY/TerrainWidth));
var format;
get_skin = bmap_for_entity(myter,a);
format = bmap_lock(get_skin,0);
get_pixel_var = pixel_for_bmap(get_skin, c, d);
bmap_unlock(get_skin);
return(get_pixel_var);
}

function SoundOfRoad() //Call this function inside you main
{
var store_pixel;
var pixel_colorAl[3];

pixel_colorAl[0] = 0;
pixel_colorAl[1] = 0;
pixel_colorAl[2] = 0;
store_pixel = 0;
while(plCar01_entity == null) { wait(1); }
while(1)
{
store_pixel = get_pixel(1);//The one is the number of your terrains skin to be used.
//The 888 is the format of the texture. Just look inside the manual
// and search for bmap_lock. There you will find the which format to use.
//It should be based on your terrain color skin. If you don't know what format is your texture,
//just open it in a image editor program and save as a format and try to see it.
pixel_to_vec(pixel_colorAl,NULL,888,store_pixel);

// This will test if the pixel color is red and play the Horn sound.
if(pixel_colorAl[0] >= 200 && pixel_colorAl[1] == 0 && pixel_colorAl[2] == 0)
{
snd_play(sndOutOfRoad,100,0);
//You can change this to make the car get back to the road or something else...
}
wait(1);
}
}




By the way... Use it at you onw risk.

Last edited by Sorcerer; 09/23/05 23:53.
Re: Scan texture for terrains. :) [Re: XNASorcerer] #55944
09/23/05 23:59
09/23/05 23:59
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline
Serious User
Lion_Ts  Offline
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
thank you, Sorcerer.
I'm using similar code for step sounds on the terrain

Re: Scan texture for terrains. :) [Re: Lion_Ts] #55945
09/26/05 06:07
09/26/05 06:07
Joined: Oct 2003
Posts: 2,628
IL,US
FeiHongJr Offline
Expert
FeiHongJr  Offline
Expert

Joined: Oct 2003
Posts: 2,628
IL,US
Great idea, I prolly wouldve never thought of converting that code for such a use. Now makes me want to think what other possiblities it could be used for different colors different entities ect... thanks alot


http://www.freewebs.com/otama_syndicate/index.htm - Each master to his own technique.

- Not me said the bee, Nor I said the fly.
Re: Scan texture for terrains. :) [Re: FeiHongJr] #55946
09/26/05 06:58
09/26/05 06:58
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
i've posted this kinda code in tutorials a while ago myself..
only was made for stepsounds, but i said it could be used for these kinda things indeed as well..

looks good (Y)

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Scan texture for terrains. :) [Re: Helghast] #55947
09/26/05 07:31
09/26/05 07:31
Joined: Jul 2002
Posts: 5,181
Austria
Blattsalat Offline
Senior Expert
Blattsalat  Offline
Senior Expert

Joined: Jul 2002
Posts: 5,181
Austria
can this be used with models as well??


Models, Textures and Levels at:
http://www.blattsalat.com/
portfolio:
http://showcase.blattsalat.com/
Re: Scan texture for terrains. :) [Re: Blattsalat] #55948
09/26/05 12:39
09/26/05 12:39
Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
XNASorcerer Offline OP
Expert
XNASorcerer  Offline OP
Expert

Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
Blattslat,

Yes, I think so.

dennis_fantasy,

I had not seen your tutorial. If I had seen, it would not have wasted so much time in that code. It gave me a few headaches.

Last edited by Sorcerer; 09/26/05 12:58.

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1