I need help accessing one class's rotation from another class. For example, I need to have a bullet class know a turret's rotation so it fires the right way.


1 2 3 4 5 | public static int rotation = 0 ; public void act() { rotation = getRotation(); } |
1 2 3 4 | // in the turret class code, when triggered to fire a bullet Bullet bullet = new Bullet(); bullet.setRotation(getRotation()); addObject(bullet, getX(), getY()); |
1 2 3 4 5 6 7 | if (Greenfoot.isKeyDown( "space" )) { bullet bullet = new bullet(); bullet.setRotation(getRotation()); addObject(bullet, getX(), getY()); } } |
1 2 3 4 5 6 7 8 9 10 11 12 | if (Greenfoot.isKeyDown( "space" )) { if (ammo > 0 ) { //the fire code ammo = - 10 ; } } else { ammo = (ammo + 1 ); } |
1 2 3 4 5 6 7 8 9 10 11 12 | if (Greenfoot.isKeyDown( "space" )) { if (ammo > 0 ) { //the fire code ammo = - 10 ; } } else { ammo = (ammo + 1 ); } |