Don Kiddick
|
 |
«
Posted
2009-01-06 09:56:54 » |
|
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.
|
|
|
|
|
h3ckboy
|
 |
«
Reply #1 - Posted
2009-01-24 19:16:13 » |
|
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  then again though this may not work. I just thought of it off the top of my head.
|
|
|
|
|
cylab
|
 |
«
Reply #2 - Posted
2009-01-26 13:18:11 » |
|
if (ontrack = true) { ontrack = false; } if (ontrack = false) { ontrack = true; }
no offense, but if you didn't loose some lines while posting, then this is one of the silliest code snippets I saw lately 
|
Mathias - I Know What [you] Did Last Summer!
|
|
|
Games published by our own members! Check 'em out!
|
|
h3ckboy
|
 |
«
Reply #3 - Posted
2009-01-26 17:34:17 » |
|
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.
|
|
|
|
|
cylab
|
 |
«
Reply #4 - Posted
2009-01-26 17:58:44 » |
|
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))
|
Mathias - I Know What [you] Did Last Summer!
|
|
|
h3ckboy
|
 |
«
Reply #5 - Posted
2009-01-26 20:03:56 » |
|
and btw. is wrong: if(ontrack=true) is completely different to if(ontrack==true)) 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.
|
|
|
|
|
zoto
|
 |
«
Reply #6 - Posted
2009-01-26 20:42:20 » |
|
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.
|
|
|
|
|
h3ckboy
|
 |
«
Reply #7 - Posted
2009-01-26 21:30:10 » |
|
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...
|
|
|
|
|
moogie
|
 |
«
Reply #8 - Posted
2009-01-26 21:48:00 » |
|
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.
|
|
|
|
|
Jono
|
 |
«
Reply #9 - Posted
2009-01-26 21:51:48 » |
|
And even if the "=" is replaced by "==" in this example it'll still have logic problems  You need an "else" before your second conditional, otherwise the boolean will always end up turned to true. Easier just to use if that's the behaviour you want.
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
cylab
|
 |
«
Reply #10 - Posted
2009-01-26 22:41:53 » |
|
also why do you have a second close parenthesis, there is only one open.
thats half a smiley, missed the ; 
|
Mathias - I Know What [you] Did Last Summer!
|
|
|
h3ckboy
|
 |
«
Reply #11 - Posted
2009-01-27 18:39:43 » |
|
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??
|
|
|
|
|
cylab
|
 |
«
Reply #12 - Posted
2009-01-27 19:16:49 » |
|
hm one = has always worked for me... for me it set 1= is boolean 2= is int and .equals() is for String
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: 1 2 3 4
| onTrack=true; if(true){ ... } |
Seriously, No Kidding! 
|
Mathias - I Know What [you] Did Last Summer!
|
|
|
Mr. Gol
|
 |
«
Reply #13 - Posted
2009-01-31 14:13:14 » |
|
hm one = has always worked for me... for me it set 1= is boolean 2= is int and .equals() is for String
Cylab is correct, this really is completely wrong!
|
|
|
|
|
h3ckboy
|
 |
«
Reply #14 - Posted
2009-01-31 16:54:31 » |
|
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 
|
|
|
|
|
moogie
|
 |
«
Reply #15 - Posted
2009-02-01 00:41:53 » |
|
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.
|
|
|
|
|
|