hello, im sorta new to greenfoot, and Im having trouble getting the API, im currently trying to program a tank that can track your movements
public void turnTowardsCharacter() { List<Character> characters = getWorld().getObjects(Character.class); if (characters != null && !characters.isEmpty()) { Character character = characters.get(0); turnTowards(character.getX(), character.getY()); } }
//you first need a global variable; private long time = System.currentTimeMillis(); public void shootAtCharacter() { if (System.currentTimeMillis() - time > 3000) { //this will make your tank shoot every 3 seconds. If you change the value in the if statement you can change the time. time = System.currentTimeMillis(); getWorld().addObject(new Bullet(getRotation()), getX(), getY()); } } //to use this method you now need the class Bullet; //If you already got a class similar to this you just have to change the constructor; //you just need the constructor of this class; //If you need help concerning the rest of the class just ask. public Bullet(int rotation) { setRotation(rotation); }
public void turnTowardsCharacter() { List<Tank> tanks = getWorld().getObjects(Tank.class); if (tanks != null && !tanks.isEmpty()) { Tank tank = tanks.get(0); turnTowards(Tank.getX(), Tank.getY()); } }
turnTowards(tank.getX(), tank.getY());