I have a program where a knight and lance switch between three lanes, it uses a get key to move either up or down, however only one of the two ever moves at a time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | String key = Greenfoot.getKey(); System.out.println(key); if ( "w" .equals(key) ){ System.out.println( "here" ); if (y > 100 ){ y = y - 100 ; charge(y,di); } } if ( "s" .equals(key)){ System.out.println( "here" ); if (y < 300 ){ y = y + 100 ; charge(y,di); } } if (Greenfoot.isKeyDown( "space" )){ System.out.println( "pere" ); } else { charge(y,di); } |