I need to make a game for my Computer Science course and I need a bit of help with one part.
I have all the code set up properly (or at least it looks (and compiles) properly). However, I have a princess class and a guard class. I am trying to make it so the guard moves but not very far from the princess (who is immobilized). I thought I had it set up but, for some reason, the guard stays on the princess and goes back and forth on her (doesn't move more than maybe 1 grid space from her).
Here is what I have regarding the Guard's actions:
er, the code that's relevant (there's also code telling him to kill people who he touches (other than her)). (560, 560) is the princess' location which is why I have him facing there if he ever can't find her in his radius. If you could help me with this, that would make me a good bit happier, if not, I can probably tell the teacher I couldn't resolve the issue when I turn it in (in 5 days). Anyhow, thanks for at least bothering to read it.
public boolean isPrincessNear() { return getObjectsInRange(200, Princess.class).isEmpty(); } public void guard() { if(isPrincessNear()) { randomTurn(); move(3); } else { turnTowards(560, 560); move(10); } }