Programming on the Nintendo DS - issue with collisions

162 views Asked by At

Sorry if this question has already been asked, but I have not managed to find any advice on the internet for my issue. I am currently trying to program a little game on the Nintendo DS, in which the player has to move a sprite (currently a square) until it reaches the exit. For this, I use a sprite I have included using a grit file, and also a background enabled in tiled mode. However, I am having a problem when it comes to checking if the sprite is going to collide with a wall. Here is the code I have both for the background configuration (where I declare the tiles and the map) and also for the sprite movements (I didn't add the condition for all cases yet, as it didn't work well) :

void configureMaze_Sub() {

int row, col;

for (row = 0; row < 24; row ++) {
    for (col = 0; col < 32; col ++) {
        BG_MAP_RAM_SUB(3)[row * 32 + col] = 1;

        if (col == 15 && (row != 12 && row !=4 && row != 19)) {
            BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
        }

        if ((row == 1 || row == 22) && (col > 2 && col < 29)) {
            BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
        }

        if ((col == 3 || col == 28) && (row > 1 && row < 22 && row != 12)) {
            BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
        }

        if ((row == 3 || row == 20) && (col > 4 && col < 27)) {
            BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
        }

        if ((col == 5 || col == 26) && (row != 9 && row != 15 && row > 3 && row < 20)) {
            BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
        }

        if (row == 8 && (col > 5 && col < 15)) {
            BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
        }

        if (row == 16 && (col > 15 && col < 26)) {
            BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
        }

        if ((row == 12) && (col > 5 && col < 26)) {
            BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
        }

    }
}

}

void gameplayMaze() {

int x = 103, y = 41, keys;
int maze_success = 0;

while (maze_success == 0) {

    scanKeys();
    keys = keysHeld();
    int xmod = x / 8;
    int ymod = x / 8;

    if ((keys & KEY_RIGHT) && BG_MAP_RAM_SUB(3)[xmod + 32 * ymod] == 1) { 
        x++;
        printf("%d \n", x);
    }

    if ((keys & KEY_LEFT) && BG_MAP_RAM_SUB(3)[xmod + 32 * ymod] == 1) {
        x--;
    }

    if (keys & KEY_UP) {
        y--;
    }

    if (keys & KEY_DOWN) {
        y++;
    }

    oamSet(&oamSub,
        0,
        x, y,
        0,
        0,
        SpriteSize_8x8,
        SpriteColorFormat_256Color,
        gfxSub,
        -1,
        false,
        false,
        false, false,
        false
        );

    swiWaitForVBlank();

    oamUpdate(&oamSub);
}

The main problem I have is to try to change from the coordinates of the tiles (which are 8x8) to the ones of the map, as for the coordinates of the sprite (256x192). If any of you have any hint to help me, I would be very grateful! I am still new to programming on the NDS, so I am still struggling to get the hang of it.

0

There are 0 answers