I wanted to know how to reverse the direction an Actor is moving. I've tried to do it, but I can't show my code here because all my code for this is in two different classes...


1 2 3 4 5 | class Example { public static void main(String[] args) { System.out.println( "First class" ); } } |
1 2 3 4 5 | class Example2 { public static void main(String[] args) { System.out.println( "Second class" ); } } |
1 2 3 4 5 | class Example3 { public static void main(String[] args) { System.out.println( "Third class" ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | private void ignite( boolean boosterOn) { if (boosterOn) { setImage (rocketWithThrust); addToVelocity ( new Vector(getRotation(), 0.3 )); } else { setImage(rocket); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public void checkKeys() { ignite(Greenfoot.isKeyDown( "w" )); Space space = (Space) getWorld(); if (Greenfoot.isKeyDown( "a" )) { turn(- 5 ); } if (Greenfoot.isKeyDown( "d" )) { turn( 5 ); } if (Greenfoot.isKeyDown( "space" )) { fire(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public void move() { exactX = exactX + velocity.getX(); exactY = exactY + velocity.getY(); if (exactX >= getWorld().getWidth()) { exactX = 0 ; } if (exactX < 0 ) { exactX = getWorld().getWidth() - 1 ; } if (exactY >= getWorld().getHeight()) { exactY = 0 ; } if (exactY < 0 ) { exactY = getWorld().getHeight() - 1 ; } super .setLocation(( int ) exactX, ( int ) exactY); } |
1 2 3 4 5 6 7 8 9 | public void checkShield() { Actor shield = getOneIntersectingObject(Shield. class ); if (shield != null ) { getWorld().removeObject(shield); setRotation( 180 ); } } |