Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Some general comments:</p> <p>Your code is quite hard to read. Please try to use meaningfull variable names in the future (or at least comment on those that are not). For example: what is Dx?</p> <p>Also: hero.drawPlayer(g) seems to be independent of the loop it is in. So why put it in the loop? The player will be drawn way more often than needed. It seems that the map is loaded (from a file!) every time paint() is called. That seems unneccesary.</p> <p>To your problem:</p> <p>Are you sure that this line: targetX=x /= 36; is correct? You did not include the PathFinding class so I assume that you are sure that it returns the correct path (you printed it out or something)? </p> <p>In your moveit() loop: path.getX(x) That just does not look right. I do not know your implementation of Path class, but I would assume that it is some kind of list. On one call of moveit() you want to move the player to the next element of that list, right? Or at least in the direction of that element. But you never call path.getFirst or path.getNext, you seem to use all the elements of the path.</p> <p>// edit: as to how to do that:</p> <p>either add a pop method to your path:</p> <pre><code>public Step popStep() { Step temp = steps.get(0); steps.remove(0); return temp; } </code></pre> <p>And use that or add a counter somewhere (in case you need the full path later).</p> <p>And then change your move method to:</p> <pre><code>public void moveit() { Step nextStep = path.popStep(); hero.setX(nextStep.getX()); hero.setY(nextStep.getY()); } </code></pre> <p>This way the player will always move to the next step in your path. Also, maybe you want to wait more than 5 milliseconds between calls to move.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload