I am making an game in which i have to show that the plane is in an turbulence , so to show it I have to make it vibrate or shake.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public class Plane extends Actor { int rn; int crot; public void act() { if (getOneIntersectingObject(Turbulance. class )!= null ) { rn=Greenfoot.getRandomNumber( 3 )- 2 ) //returns numbers -1, 0 and 1 crot=getRotation(); //current angle setRotation(getRotation()+rn); //rotate if (crot> 355 &&> 5 ) //if rotated too much, turn back setRotation(crot+ 1 ); if (crot< 355 &&< 5 ) //if rotated too much, turn back setRotation(crot- 1 ); } else if (getOneIntersectingObject(Turbulance. class )== null ) //when not in turbulance { //turn back to original angle if (crot< 0 ) setRotation(crot- 1 ); if (crot> 0 ) setRotation(crot+ 1 ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import greenfoot.*; public class Plane extends Actor { public void act() { int rot = getRotation(); if (getOneIntersectingObject(Turbulance. class ) != null ) { rot += Greenfoot.getRandomNumber( 3 )- 1 ; if (rot>= 180 && rot < 355 ) rot = 355 ; if (rot <= 180 && rot > 5 ) rot = 5 ; } else { if (rot > 180 ) rot++; if (rot < 180 && rot != 0 ) rot--; } setRotation(rot); } } |