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 & HelpSyntax Questions › Can't make it Stick...
Page Index Toggle Pages: 1
Can't make it Stick... (Read 635 times)
Can't make it Stick...
Apr 4th, 2010, 4:07am
 
Okay I'm new to programming and very very new to proce55ing so this is probably a newb question but here it goes...

I'm creating a simple balloon shooting game. The way it's supposed to work is the player guides gun sight with the mouse, and clicks to fire.

I'm using update(int x , int y) to constantly check the position of the mouse. Also in the update {} is an if/else for mousePressed && the whether or not the gun sight is over the balloon. If both are true the balloon drops (popping animation will get worked in later) otherwise, it keeps rising.

The trouble is, the instant I release the mouse, or move the gun sight off the balloon, it starts to rise again. Update automatically resets to "else";

How do I get a the if/else to stay "if"?
Re: Can't make it Stick...
Reply #1 - Apr 4th, 2010, 4:19am
 
You need to have a boolean variable for storing the balloon's "popped" state (or an array of booleans if you have multiple balloons).  Initially, it is "false", but when the "if" in your update function comes true, you set the balloon's popped state to "true".  The movement of the balloon is then updated according to whether "popped" is true or false.

So, the state of the balloon is in a variable, and events happening to the balloon are in the "if" and depend on the state of the cannon – while in your current version, you do not have this separation of balloon state and cannon state.
Page Index Toggle Pages: 1