Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / matrix trouble

Author
Message
Code eater
17
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 17th Feb 2008 19:25
Basicly I am making a motor bike race game, and the track is a matrix with a picture of the track (with out any trees or anything just the ground and track) on it, but im having trouble detecting when I come off the track because I want something that will check the colour of the matrix at the possition of the motor bike so if it isnt on the track it will know because of he colour. I was wandering if there was anyway to do this in DBC if not any suggestions on how to do it
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 17th Feb 2008 20:19
You could do what you are talking about, but I wouldn't suggest trying it. It would be a real pain - not to mention very slow.

You should use waypoints. Check the DBC Programming Challenge thread - it was one of the challenges a while back.

To actually stop vehicles going off the track, make a fence or some structure around the edge - you can use long thin plains for this to keep the poly count down and even make them invisible if you don't want anything seen.

You can then use DBC's basic inbuilt collision to stop the vehicles from going through them.

TDK_Man

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th Feb 2008 22:55
@TDK
If you make an object with transparency (some of it is black) will the transparent parts return a collision?

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 18th Feb 2008 00:44 Edited at: 18th Feb 2008 00:45
No. But you are hiding them - not making them black and transparent.

TDK_Man

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Feb 2008 13:29
@TDK
I was thinking of making a large plain textured with the track and a black background.
but the waypoints idea is much better, like the races in GTA

Code eater
17
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 18th Feb 2008 19:08
Thanks although i was planning on trying not to use objects because it will mean i'll have to make a new object for each track wereas I was just thinking of changing the image but I will give it a try.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 18th Feb 2008 23:12
OK, do you have a single image for each complete track (which is mapped onto the matrix) or are the tracks built from a series of track pieces (tiled)?

There are no commands to get the colour of the matrix at any given X/Z location, but I have something you could try. If the tracks are single images then you have a chance. If not, then you would need to create images of each track.

Essentially, you texture the matrix with the image and also place it on a hidden screen. As you move over the matrix, you test the colour of the pixel on the hidden image at the equivalent position of the hidden image. It works, but there is a performance hit.

I've knocked together a very basic code snippet just to show the idea, but it needs working on and would probably be a lot better if you adapted it to use memblocks.



TDK_Man

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 19th Feb 2008 04:20
Hey TDK,

Could you do the same idea but use hidden sprites and sprite collision tests for the color? You make the sprite transparent where the track is, use another sprite to move around on it and test collision with the outer edges of the track. That way you can eliminate a color test all together (using point or a memblock) - and the hidden sprites should take up less processing. You can even shrink the sprites down for faster processing (but less accurate detection) or make them larger for more accurate detection.

Or perhaps, use Object Screen X() and Object Screen y() (assuming the pivot is in the middle of the bike or car) and check the color under that screen position so you look at the matrix directly without having to compare it to a bitmap in memory or a sprite position.

Enjoy your day.
Code eater
17
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 19th Feb 2008 21:17
thanks guys but the only problem with the second thing latch said was that if another object gets in the way of me being able to see my charater it would go all wrong
Code eater
17
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 19th Feb 2008 21:23
yes I do have a single image for the whole of the matrix btw.
here is a code snipit of what i have tried

set current bitmap 1
c=point(INT(x#*10),INT(z#*10))
set current bitmap 0
set cursor 10,10
print c

(bitmap one is a hidden image of the track with the track red, the area you are allowed to go in but you go slower green) ( the bitmap is 5000x500 in size and the matrix is 500 across so i mutiplied the x position of my character by ten and the z position of my haracter) but it still wont work as it doesnt seem to change the colour value at the right point.

Login to post a reply

Server time is: 2025-06-04 02:10:36
Your offset time is: 2025-06-04 02:10:36