Skip to content

The X & Y coordinate layouts are different throughout engine (?) #5

@ghost

Description

Some (or all or many) portions of LITIengine are inverted or different as to the standard XY Graph I'm used to in the United States:
82338fea60fbf48fd86e2103ce7b3526

I do get it, it depends on what your starting corner is. I actually do like that maps start at 0,0 top left and left to right, get larger. Makes math easier. But I do think at the same time, everything should start top left also.

The bottom line is it seems like Camera() coordinates are different from Physics() coordinates are different from Creature() coordinates, etc, etc.

I'm not a math guy but I can figure stuff out through a lot of trial and error.
My first implementation on this thing was a visual debugger.

There's some inversion required when generating tmxMaps -> for y first, then for x

I had to inverse the player's movements to convert it into something Game.physics() can understand.
Here's some of the finagling I did to get collision to work properly:

Point2D oldPosition = _entity.getPosition();
Point2D newPositionCollisonInverse = _entity.getPosition();
Point2D newPosition = _entity.getPosition();
...
switch (keyCode.getKeyCode()) {
     case 87: timeRestrictedKeyPressed(); newPosition.setLocation(newPosition.getX(), newPosition.getY() + stepY); newPositionCollisonInverse.setLocation(oldPosition.getX(), oldPosition.getY() - stepY); break; //w
     case 65: timeRestrictedKeyPressed(); newPosition.setLocation(newPosition.getX() + stepX, newPosition.getY()); newPositionCollisonInverse.setLocation(oldPosition.getX() - stepX, oldPosition.getY()); break; //a
     case 83: timeRestrictedKeyPressed(); newPosition.setLocation(newPosition.getX(), newPosition.getY() - stepY); newPositionCollisonInverse.setLocation(oldPosition.getX(), oldPosition.getY() + stepY); break; //s
     case 68: timeRestrictedKeyPressed(); newPosition.setLocation(newPosition.getX() - stepX, newPosition.getY()); newPositionCollisonInverse.setLocation(oldPosition.getX() + stepX, oldPosition.getY()); break;  //d
}
boolean collides = Game.physics().collides(new Point2D.Double(newPositionCollisonInverse.getX(), newPositionCollisonInverse.getY())) || newPositionCollisonInverse.getX() < stepY || newPositionCollisonInverse.getY() < stepX;
if (!collides) {super.handlePressedKey(keyCode); HEROUtility.moveCreatureTransition(_entity, (int)newPosition.getX(), (int)newPosition.getY(), 10, 10);}
       

Github Project:
https://github.com/evnsch/OpenHero/blob/master/src/main/java/com/escho/game/creatures/hero/HeroController.java

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions