Monday, 20 May 2013

collision and moving player on map

collision and moving player on map

2d array: as map 0=sky, 1=player, 2=ground
000
100
222

public void levelWCollision(Player p)
{
    /*** FIND PLAYER POSTION ***/
    int y = 0;
    int x = 0;
    int z = 0;

    for(y = 0; y < map01.length; y++){
        for( x = 0; x < map01[y].length; x++){
            if(map01[y][x] == 1){
                z = y;
                y = map01.length;
                break;
            }
        }
    }

    if(map01[z+1][x] == 2){
        System.out.println("stand on ground");
    }
}
move player by:
public void playerMove()
{
    if(right)
        x += dx;
    else if(left)
        x -= dx;
    }
the Problem is that. I am moving the player by
x+=3 or x-= 3.
but the map doesnt change. so x and y in levelWcollision method will always stay the same bc in 2d array '1' doesnt change. so no matter where iam standing this method levelWcollision will always check for this array below:
0000
1000
2222
i was thinking to store this 2d array in arraylist but i dont think it will make any differece bc arraylist wont change too.
another way i was think to make my player move forward like this:

No comments:

Post a Comment