Modelling track in top down racer

Hello,

I’m starting on a top-down racer in the style of micro machines, although using a more traditional “grand-prix” style track.

I am stumbling on how to represent the tracks.

I’m trying to use Slick (1st time) and my first stab involved trying to create a shape that represented the tracks geometry. The idea being that I could use the shape to test whether the car is on the track.
However Slicks polygons don’t seem to support having holes in the middle - which all tracks will - consider a simple loop.

So a) is this a good approach, b) is Slick a good choice and c) any other ideas/direction.

thanks in advance for any help,
cheers, Don.

this is probably a really clumbsy and inefective way but it may work. Make the edges of the track lines. and then if the car crosses over the line he goes of

here is sort of wat it would look like:

if (ontrack = true)
{
ontrack = false;
}
if (ontrack = false)
{
ontrack = true;
}

you get it :slight_smile:

then again though this may not work. I just thought of it off the top of my head.

no offense, but if you didn’t loose some lines while posting, then this is one of the silliest code snippets I saw lately :o :stuck_out_tongue:

umm not aht is all I meant. I was just showing that it needed ot go from of to on and on to off. but I was jsut showing how you would write it in java.

Ok, you meant he should toggle the ontrack variable every time he crosses the line, but the code itself just looks funny (and btw. is wrong: if(ontrack=true) is completely different to if(ontrack==true))

[quote]and btw. is wrong: if(ontrack=true) is completely different to if(ontrack==true))
[/quote]
i am sorry but I was right. cause ontrack was a boolean and a boolean only has 1 = sign. also why do you have a second close parenthesis, there is only one open.

Don, instead of making of the track as one huge polygon with a hole in the center, try making it as a collection of road segments made of polygons. This way you can make less collision test yet still have roads shaped anyway you might want.

Heckboy, you are correct that the double parenthesis are a syntactical error. Your code segment has a logic error because a single equals is an assignment equals and a double is equals is a comparison equals.

no in an if statement a boolean uses only 1 = sign. If i am wrong then all my programs work for a wrong reason ??? so…

h3ckboy, zoto is correct, no matter what the variable type, equality is tested by == and assignment by =

your programs are probably not behaving as you expect as the condition " if (ontrack=true)" would always be satisfied as ontrack is firstly set to true by “ontrack=true” and then ontrack is conditionally tested.

the opposite is true for if (ontrack=false) will cause the if statement to always be unsatisfied.

And even if the “=” is replaced by “==” in this example it’ll still have logic problems :frowning:
You need an “else” before your second conditional, otherwise the boolean will always end up turned to true.

Easier just to use

ontrack = !ontrack;

if that’s the behaviour you want.

thats half a smiley, missed the ; :wink:

hm one = has always worked for me… for me it set 1= is boolean 2= is int and .equals() is for String

anyways backt o topic has enay how these ideas worked??

Sorry to derail this again, but this is really plain wrong and not understanding it will give you real problems. if(onTrack = true) will first set onTrack to true and then always evaluate the if statement to true. It is the same as writing:


onTrack=true;
if(true){
...
}

Seriously, No Kidding! :o

Cylab is correct, this really is completely wrong!

yeah sry. i was wrong. that explains why some things did not work. cause I dont get an error it just doesnt work.

thx for setting me straight :slight_smile:

Getting back on topic, in my 2006 java 4k entry Java Rally Racer 4k i used tracks consisting of different tiles. The road segments were drawn on to tiles.

I then used the getRGB() method on the final image to determine what surface each car was on (snow, mud, grass, tarmac) and adjust the car dynamics accordingly.

This is probably not the best way of modeling a track, but it was quite space efficient.