Im new to greenfoot and want to remake the mobile game "Twocars" but i have truble with the "smooth" movements of the cars
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import greenfoot.*; public class Blauesauto extends Actor { boolean rightPressed = false ; int Position = 0 ; int verschiebung = 88 ; public void act() { if (rightPressed== false && Greenfoot.isKeyDown( "right" ) && Position == 0 ) { nachlinks(); Position = 1 ; rightPressed = true ; } if (rightPressed== false && Greenfoot.isKeyDown( "right" ) && Position == 1 ) { nachrechts(); Position = 0 ; rightPressed = true ; } if (rightPressed== true && !Greenfoot.isKeyDown( "right" )) { rightPressed = false ; } if ( getOneIntersectingObject(Blauerkreis. class ) != null ) { } } void nachlinks() { for ( int i = 0 ; i < verschiebung; i++) { setLocation(getX()- 1 ,getY()); } } int smoothlinkscounter= 0 ; void smoothnachlinks() { smoothlinkscounter++; if (smoothlinkscounter % 30 == 0 ) { setLocation(getX()- 1 ,getY()); turn(- 1 ); } } void nachrechts() { for ( int i = 0 ; i < verschiebung; i++) { setLocation(getX()+ 1 ,getY()); } } } |