FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   simulate a fall
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: simulate a fall  (Read 410 times)
katapulp


simulate a fall
« on: Nov 20th, 2004, 11:41am »

Hello,
 
i've a problem with a simulation of a fall. I created a rect that you can drad & drop on the screen. I would like it to be falling vertically when you release it. I tryied with this piece of code:
 
Quote:

  // mex= x coordinate / mey= y coordinate of the rect
  if (release) {
    mex = mouseX;
    mey = 50;
  }

 
It is falling right but you can still move the rect horizontally  after... I couldn't find a way to recover the value of mouseX when the mouse is released, and to assign it to mex.  
 
I also tried to make it with booleans but it didn't work well :/
 
If someone could explain me how to solve it?
Thx a lot.
 
katapulp
 
Quote:

Sketch:
http://www.regarde.org/processing/fall/applet/
 
Source code:
http://www.regarde.org/processing/fall/askinghelp.pde
 
fjen

WWW
Re: simulate a fall
« Reply #1 on: Nov 20th, 2004, 4:21pm »

i think you are doing this a little too complicated, but anyway here's how to solve your problem:
 
Code:
if (release) {
    //mex = mouseX;
    mey = 50;
    dragdrop = false;
  }

 
if you assign mouseX here it will keep following the mouse .. and dragdrop has to be set to false (somewhere) to recover from dragging.
 
Code:
void mouseDragged()
{
  // if mouseDragged on the avatar
  if  ( mouseX > mex && mouseX < mex+32 &&  mouseY > mey && mouseY < mey+73) {
    dragdrop = true;
    release = false;
  }
}

 
( no need to check for mousePressed in mouseDragged .. that for sure in there ... )
 
set release false here, otherwise it will release the drag-drop in the loop ...
 
-----
 
less is more and might not get you confused with all that bools ..
 
Code:

void me () {
  blockx = constrain(mouseX-16, 0, width-32);
  blocky = constrain(mouseY, 0, 50);
  fill (120, 30, 10);
  rect(mex, mey, 32, 73);
  if ( dragdrop ) {
    int blockxint = int(blockx);
    int blockyint = int(blocky);
    mex = blockxint;
    mey = blockyint;
    if (mouseX < 15 && mouseX >-100 || mouseX > 200 - 32 && mouseX < 300 || mouseY <3 && mouseY>-100 ) {
 fill (0);
 rect (100, 100, 10, 10);
    }
  } else {
    mey = 50;
  }
}
void mouseDragged()
{
  if  (mouseX > mex & mouseX < mex+32 &  mouseY > mey & mouseY < mey+73 ) {
    dragdrop = true;
  }
}
void mouseReleased()
{
  dragdrop = false;
}

 
best,
/F
 
katapulp


Re: simulate a fall
« Reply #2 on: Nov 20th, 2004, 4:42pm »

You're right for the bools, i made too many this was useless... I'm stupid, the solution was so easy :s
By the way, thx fjen, i learned a lot with your code !
 
fjen

WWW
Re: simulate a fall
« Reply #3 on: Nov 20th, 2004, 6:59pm »

not stupid ... i made similar mistakes, so i'm stupid too i guess
 
you're very welcome.
 
Pages: 1 

« Previous topic | Next topic »