This site requires JavaScript, please enable it in your browser!
Greenfoot back
armoredarmada
armoredarmada wrote ...

2012/3/17

How to flip image

1
2
armoredarmada armoredarmada

2012/3/18

#
THANK YOU THANK YOU THANK YOU!!! now another question if you dont mind, how would I code a boolean statement where if the heli's angle was >= 20, it would move along x axis?
danpost danpost

2012/3/18

#
First, you will need a different boolean value to keep track of the direction
private boolean movingLeft = false;
Then, when changing the image (either way) add this
movingLeft = !movingLeft;
Now, you can use that information, with the current angle to determine if it should move or not
if ((movingLeft && getRotation() <=340 && getRotation() >=290) || (!movingLeft && getRotation() >= 20 && getRotation() <=70))
I have not tested it, but this should, when the nose is down by 20 degrees or more, return true.
armoredarmada armoredarmada

2012/3/18

#
Ill try that, in the movingLeft = !movingLeft; what does ! mean and how do I adjust speed of movingLeft
danpost danpost

2012/3/18

#
The exclamation point is read as 'Not'. A boolean has two values (true and false), so setting it to 'not' itself is just changing it from 'true' to 'not true' (or 'false'), or from 'false' to 'not false' (or 'true') This plays into the logic of: not(a or b) = not a and not b or: (not a and b) or (a and not b) = (a or b) and (not a or not b) = (a or b) and not(a and b)
armoredarmada armoredarmada

2012/3/18

#
INCEPTION! lol, ok so Ill try pluggin this all into my heli, but instead of using the movingLeft method, why not: (boolean angle degree statement) and then the result if it is true would be ...setLocation(getX()-+int,getY();
danpost danpost

2012/3/18

#
You need something (an instance variable, either a boolean or an int , ) to track which way the heli is going at the moment (right or left). The integer might be better, as you could just multiply that by the change in position to create the 'vector' What did you mean by "boolean angle degree statement"? I would like to see an example.
armoredarmada armoredarmada

2012/3/18

#
I know this isnt right but this is what it would be like, If(heli.Rotation <= 20(setLocation(getX()+1, getY()));
danpost danpost

2012/3/18

#
if (getRotation() <=20) setLocation(getX() + 1, getY());
Are you sure it isn't >=? And this will only work for one of the directions, not for the other.
armoredarmada armoredarmada

2012/3/18

#
thats ok, I was planning on using two different codes, one for each direction, and one will be <= and otehr will be >= thank you for showing me the correct code. helped alot! btw, what is difference between wait and delay and which one should I use for an explosion actor?
danpost danpost

2012/3/18

#
wait() : method in Java.lang.Object Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. delay(int time) : method in Greenfoot Delay the current execution by a number of time steps. The size of one time step is defined by the Greenfoot environment (the speed slider). The wait will continue indefinitely, until 'notified', while the delay will resume execution when the time has expired.
davmac davmac

2012/3/18

#
what is difference between wait and delay and which one should I use for an explosion actor?
'wait' is a Java method which you shouldn't use. Use Greenfoot.delay(...).
You need to login to post a reply.
1
2