Hey guys,
I was wondering if you can help me with my problem. I read a lot of different posts but what they get solved is quite different from my problem. I want to increase the speed of a single actor. I want to let a bullet fly faster than the object shooting it, but I don't want the bullet to skip a cell
public class Bullet extends Actor { private int speed; public Bullet(int rotation) { setImage("images/bullet.png"); setRotation(rotation); speed = 1; } public void act() { if(außerReichweite()) { getWorld().removeObject(this); } move(speed); } public boolean außerReichweite() { if(this.getX() >= 20 || this.getY() >= 13 || this.getX() == 0 || this.getY() == 0) { return true; } return false; } }
public class Rover extends Actor { int Ammo = 10; int reloadDelay = 20; public void act() { shoot(); tastatur(); } public void tastatur() { if(Greenfoot.isKeyDown("left")) { this.setRotation(180); move(1); } else if(Greenfoot.isKeyDown("up")) { this.setRotation(270); move(1); } else if(Greenfoot.isKeyDown("right")) { this.setRotation(0); move(1); } else if(Greenfoot.isKeyDown("down") ) { this.setRotation(90); move(1); } } public void shoot() { if (Greenfoot.isKeyDown("0") && Ammo > 0) { getWorld().addObject(new Bullet(getRotation()), xPos(), yPos()); Ammo--; } if (Ammo <= 0) { reloadDelay--; if (reloadDelay <= 0) { Ammo = 10; reloadDelay = 20; } } } public int xPos() { if(getRotation()==0) { return getX()+1; } else if(getRotation()==180) { return getX()-1; } return getX(); } public int yPos() { if(getRotation()==90) { return getY()+1; } else if(getRotation()==270) { return getY()-1; } return getY(); } }