JohnBoyJohn / Game_Engine

0 stars 0 forks source link

Mob movement and collision #9

Open DidiCatman opened 7 years ago

DidiCatman commented 7 years ago

movement and collision should be revised. i have to simple methods in my abstract mob (your creature) class that handle movement and collision. movement works just fine. i only have some problems with collision detection with npc.

DidiCatman commented 7 years ago

move method in my abstract mob class:

protected enum Direction {
    UP, DOWN, LEFT, RIGHT
}

protected Direction dir;

public void move(int xa, int ya) {
    if (xa != 0 && ya != 0) {
        move(xa, 0);
        move(0, ya);
        return;
    }

    if (xa > 0) dir = Direction.RIGHT;
    if (xa < 0) dir = Direction.LEFT;
    if (ya > 0) dir = Direction.DOWN;
    if (ya < 0) dir = Direction.UP;

    if (!collision(xa, ya)) {
        x += xa;
        y += ya;
    }
}
JohnBoyJohn commented 7 years ago

can you provide this code in a new branch, to test and highlight the differences?