Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 line crossings
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Fashoomp




PostPosted: Mon May 21, 2007 10:51 am   Post subject: line crossings

im making a racing type game, where you just simply move a ball around a track. I have 2 questions about it. How can i mplement "laps". so it detects how many times it has gone around the track (crossed a finish line). Also, how can i make it bounce of walls at a specific angle. like if the wall is slanted, it will bounce off sideways.
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Mon May 21, 2007 11:11 am   Post subject: RE:line crossings

For laps you could try putting a few "checkpoints" around the track. Have a few lines that stretch across the track (to the boundaries, if there is grass or something to drive on), one of these lines being the start/finish line. Keep track of which line was crossed most recently to ensure they are going the right way (ie, to make sure the player doesn't start the race, reverse, and then cross the finish line skipping 90% of the track).

You could make this easier by using rectangles rather than lines, and checking to see if the center of the player's vehicle ever goes inside of that rectangle. If so, they've reached that checkpoint.

The bouncing is a bit trickier if you aren't familiar with collision detection and physics, but it can be done with a little learning. Basically, when you've determined that the vehicle collided with the wall, you need to find the angle of incidence. Then just set the vehicle's angle of reflection similarly (like light waves hitting a mirror, grade 11 physics). It's actually a bit more complicated than that if you're considering things like friction and non-round vehicles, but take it a step at a time and see where it gets you.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: