We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Racing game
Page Index Toggle Pages: 1
Racing game (Read 827 times)
Racing game
Nov 28th, 2005, 8:44pm
 
Hello,

I was wondering if anyone could give me any ideas on a problem I'm having: I am currently trying to create a small game: A button tapper racing game that will allow the users to race four balls around an oval track.  I'm fairly new to graphics based programming so I'm having a wee bit of trouble getting my head around it. My main difficulty is getting the balls to move in the direction of an oval in small iterations of the key press. From my understanding of the examples on the site it would be necessary to use the formula of an oval which in, my basic understanding of maths, I know is pages long. If anybody knows of any examples I could reference or even a starting point this would be much appreciated.

Many thanks.

Re: Racing game
Reply #1 - Nov 28th, 2005, 9:29pm
 
The math shouldn't be too hard. If you want to start simple you can use the parametric equation for an ellipse.

x = a * cos( t );
y = b * sin( t );

A simple start:

//---
float x;
float y;
float t;
float delta_t;
float a;
float b;

void setup()
{
 size( 640, 480 );
 
 t = 0.0;
 delta_t = 0.05;
 a = 300;
 b = 200;
}

void keyPressed()
{
 t += delta_t;
}

void draw()
{
 translate( width/2, height/2 );
 noStroke();
 fill( 0, 0, 0, 1 );
 rect( -width/2, -height/2, width, height );
 
 fill( 255, 50, 20 );
 x = a * cos( t );
 y = b * sin( t );
 ellipse( x, y, 10, 10 ); // this draws a circle on the screen
 
}
//---
Re: Racing game
Reply #2 - Nov 28th, 2005, 9:42pm
 
Sir, you are a gentleman and a scholar.

Thank you very much for you help - This is exactly what I needed.

Smiley

Page Index Toggle Pages: 1