My issue is, that the pipe-object moves with the tank, although it doesnt rotate.
Here is the full code of the pipe:
Here is the code of the Player-class:
public void mutualmovement()
{
Pipe actor = (Pipe) getOneIntersectingObject(Pipe.class);
if (actor != null) {
actor.setLocation(this.getX(),this.getY());
}
}
My second problem is, that the bullets are only being shot into one direction and not even through the pipe. My goal is to make the bullets shoot through the pipe, which should be rotated like the tank itself.
public class Pipe extends Actor { boolean didShoot = false; int shotCoolDown = 0; World myWorld = getWorld(); BattleWorld battleWorld = (BattleWorld)myWorld; public int myPlayerNum; String shootKey = "o"; GreenfootImage myImage; /** * Act - tut, was auch immer Rohr tun will. Diese Methode wird aufgerufen, * sobald der 'Act' oder 'Run' Button in der Umgebung angeklickt werden. */ public Pipe(int playerNum, String image) { myImage = new GreenfootImage(image); myPlayerNum = playerNum; myImage.scale(25, 25); myImage = new GreenfootImage(image); if (playerNum == 1) { myImage = new GreenfootImage("Rohr1.PNG"); shootKey = "o"; } else { myImage = new GreenfootImage("Rohr2.PNG"); shootKey = "e"; } myImage.scale(50, 50); setImage(myImage); } public void act() { shootStuff(); didShoot = false; //getWorld().getObjects(Player.class).turnTowardsEnemy(); //getWorld().getObjects(Player.class).movementEngine(); World world = getWorld(); List<Player> player = world.getObjects(Player.class); for (Player p : player) { p.turnTowardsEnemy(); } for (Player p: player) { p.movementEngine(); } } public void shootStuff() { if(Greenfoot.isKeyDown(shootKey) && shotCoolDown == 0) { getWorld().addObject(new Bullet(getRotation()), getX(), getY()); shotCoolDown = 20; didShoot = true; } if(shotCoolDown > 0) shotCoolDown -= 1; } }