0
\$\begingroup\$

I ran into a problem last night and I can't solve it since. I'm making an isometric game based on tiles with equal rows and columns. Now I made moving entities which should turn whenever they reach the boundaries of the world. As I illustrated on the picture they are turning back on the upper boundaries (green) , but not on the lower ones (red). I tried various equations on the lower part, but i cannot figure out for the life of me what is the lower parts code. What would be an appropriate solution for the shrinking lines?

boolean checkBounds(){ float absX = Math.abs(getX()); float absY = Math.abs(getY()); if(absY*2-absX<0 || ??? ) return false else return true; }

enter image description here

\$\endgroup\$
  • 2
    \$\begingroup\$ Usually an isometric game will use the diamond layout exclusively for display. All world & gameplay logic is done in a separate coordinate system, with the axes aligned to the rows & columns (so eg. (2, 0) is the third column of the first row, assuming 0-based indices), and transformed to the isometric perspective only for the drawing step. This kind of switch will likely make a lot of your logic much simpler. \$\endgroup\$ – DMGregory Feb 23 at 18:34
0
\$\begingroup\$

To elaborate on what DMGregory said... you don't want to imagine them moving on diamond tiles, but rather imagine them moving on the ordinary grid you've set up as a 2D array in memory. That is what you do your movement and collision detection / resolution on; at least at this early stage.

This way your transition between (unoccupied) tiles becomes a simple fractional value, for example, xFractionToNextCell == 0.4 means you're 40% of the way on your movement to the next tile, in x. You can do the same for y. Once it hits 1.0 AND you are at the edge of the map, you can turn.

Using the view-transformed grid just unnecessarily complicates things in this regard. So rather work in the original 2D array co-ordinates.

\$\endgroup\$
  • \$\begingroup\$ Yes I was thinking about how should i seperate the drawing and the logic of the game based on DMGregory's answer. I got stuck with the drawing coordinates, when I should just translate the simple positions. This method will definietly work for the bounds thanks. \$\endgroup\$ – Ádám Sors Feb 23 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.