I am trying to fire bullets from a turret. When I fire and rotate, the bullets come out of the center of the image to the east. How do I change it so that the bullets come out of the tip of the gun? This code is based of the asteroid code which the rocket image is a much smaller image than the one I am using. My image is also longer than the rocket image. This is the code I am using to rotate the turret:
and this code to fire the bullets:
private void checkKeys() { if (Greenfoot.isKeyDown("space")) { fire(); } if (Greenfoot.isKeyDown("left")) { setRotation(getRotation() - 5); } if (Greenfoot.isKeyDown("right")) { setRotation(getRotation() + 5); } }
private void fire() { if (reloadDelayCount >= gunReloadTime) { Bullets bullets = new Bullets (getMovement().copy(), getRotation()); getWorld().addObject (bullets, getX(), getY()-55); bullets.move (); reloadDelayCount = 0; } }