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.
IndexDiscussionExhibition › catch me if u can
Page Index Toggle Pages: 1
catch me if u can (Read 725 times)
catch me if u can
Apr 8th, 2007, 8:05am
 
try out the following game prg i built after a day's  introduction to Processing. i find Processing a user friendly language and wud like to actively contribute and participate in the future.


/*
Catch Me If You Can
by Suhasini Gadag

Try to catch the ball with the mouse pointer

Created 08 April 2007
*/

/*
The setup() function is called once when the program is started.
It is used to define initial environment properties such as screen size, background color etc.
*/
void setup()
{
 size(400, 400);                    //Defines the dimension of the display window in units of pixels.
 background(10);                    //The background() function sets the color used for the background of the Processing window.
 smooth();                          //Draws all geometry with smooth (anti-aliased) edges.
}

float curX=200,curY=200;             //Global Variables defining the initial position of the ball
                                   
/*
The draw() function is called directly after setup()
and continuously executes the lines of code contained inside its block
until the program is stopped or noLoop() is called.
draw() is invoked automatically and should never be called explicitly.
*/

void draw()
{
 fill(200);                         //Sets the color used to fill shapes.
 ellipse(curX,curY,10,10);          //Draws an ellipse (oval) in the display window. An ellipse with an equal width and height is a circle.
}


/*
The mouseMoved() function is called every time the mouse moves and the mouse button is not pressed.
The system variable mouseX always contains the current horizontal coordinate of the mouse.
The system variable mouseY always contains the current vertical coordinate of the mouse.
width: System variable which stores the width of the display window.
height: System variable which stores the height of the display window.
*/

void mouseMoved()
{
 if((abs(curX-mouseX)<=30)&&(abs(curY-mouseY)<=30))  //Checks if the mouse is in the vicinity
 {        
   fill(10);                                         //Erases the circle with the background color
   ellipse(curX,curY,10,10);
   curX=random(width);                               //Reforms the coordinates of the circle
   curY=random(height);
 }
}

Page Index Toggle Pages: 1