Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (578)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Modelling track in top down racer  (Read 3757 times)
0 Members and 1 Guest are viewing this topic.
Offline Don Kiddick

Junior Member





« 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.
Offline 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  Smiley

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

JGO Knight


Medals: 34



« 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  Shocked  Tongue

Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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.
Offline cylab

JGO Knight


Medals: 34



« 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!
Offline h3ckboy
« Reply #5 - Posted 2009-01-26 20:03:56 »

Quote
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.
Offline zoto

Senior Member


Medals: 4



« 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.
Offline 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  Huh so...
Offline moogie

JGO Knight


Medals: 11
Projects: 5
Exp: 10 years


Java games rock!


« 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  Huh 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.
Offline 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  Sad
You need an "else" before your second conditional, otherwise the boolean will always end up turned to true.

Easier just to use
1  
ontrack = !ontrack;

if that's the behaviour you want.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cylab

JGO Knight


Medals: 34



« 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 ; Wink

Mathias - I Know What [you] Did Last Summer!
Offline 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??
Offline cylab

JGO Knight


Medals: 34



« 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!  Shocked

Mathias - I Know What [you] Did Last Summer!
Offline Mr. Gol

Senior Member


Medals: 1



« 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!
Offline 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 Smiley
Offline moogie

JGO Knight


Medals: 11
Projects: 5
Exp: 10 years


Java games rock!


« 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.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (26 views)
2014-04-15 18:08:23

BurntPizza (21 views)
2014-04-15 03:46:01

UprightPath (37 views)
2014-04-14 17:39:50

UprightPath (19 views)
2014-04-14 17:35:47

Porlus (35 views)
2014-04-14 15:48:38

tom_mai78101 (61 views)
2014-04-10 04:04:31

BurntPizza (119 views)
2014-04-08 23:06:04

tom_mai78101 (219 views)
2014-04-05 13:34:39

trollwarrior1 (186 views)
2014-04-04 12:06:45

CJLetsGame (193 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!