samedi 20 février 2016

C: how to check if two [x][y] co-ords match?

I am trying to build a maze game with a player @ and two monsters M.

When a monster is on the same coordinate as the player, it should print GAME OVER.

But I only have this working for one of the two monsters.

Why? How do you solve this?

void check_and_move(game_object *obj, int xoffset, int yoffset, char *v) {
    game_object *treasure = treasure_position->object;
    game_object *monster = monster_position->object;
    game_object *monster2 = monster_position->object;


    // If player gets eaten by a monster: GAME OVER!
    if(player->x == monster->x) {
        if(player->y == monster->y) {
            printf("GAME OVER!\n");
            free_memory();
        }
    }
    // If player gets eaten by a monster: GAME OVER!
    if(player->x == monster2->x) {
        if(player->y == monster2->y) {
            printf("GAME OVER!\n");
            free_memory();
        }
    }

    // If player coordinate == treasure coordinate: PLAYER WINS!
    if(player->x == treasure->x) {
        if(player->y == treasure->y) {
            printf("You have captured the treasure!\n");
            free_memory();
        }
    }

    // If coordinate is not blocked and can be moved to, object gets moved to it.
    if (isMovable(obj, obj->x + xoffset, obj->y + yoffset)) {
        move_object(obj, obj->x + xoffset, obj->y + yoffset);
    } else {
        *v = 0;
    }
}

Aucun commentaire:

Enregistrer un commentaire