Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Please help! Homing and surroundings check

I am working on a game in c++:
Set on a grid, a player tries to navigate to a certain cordinate while
an enemy, like a homing device, moves everytime the player does, ultimately trying to get the player. Now to get the AI to recognize the boundaries of the grid, my teacher told me to have the bot check its neighbors, or surroundings. I am not sure how to do this. Any help would be
greatly appreciated. Thanks.

Comments

  • MT2002MT2002 Member Posts: 1,444
    : I am working on a game in c++:
    : Set on a grid, a player tries to navigate to a certain cordinate
    : while
    : an enemy, like a homing device, moves everytime the player does,
    : ultimately trying to get the player. Now to get the AI to recognize
    : the boundaries of the grid, my teacher told me to have the bot check
    : its neighbors, or surroundings. I am not sure how to do this. Any
    : help would be
    : greatly appreciated. Thanks.
    :
    The bounderies of the [b]grid[/b] or the bounderies of the [b]tiles[/b]
    within the grid?

    I assume you are trying to have the AI collision code to check its
    surroundings. If so, all you need to do is store the object positions
    within the grid, kind of like this:
    [code]
    enum {
    INVALID = 0,
    PLAYER = 1,
    ENEMY = 2
    };

    int _Grid[][] = {
    { INVALID, INVALID, INVALID },
    { INVALID, ENEMY, PLAYER },
    { INVALID, INVALID, INVALID }
    };

    int _posX=0, _posY=0; // actual position of enemy

    const int TILE_WIDTH=32, TILE_HEIGHT=32;
    const int GRID_WIDTH=3, GRID_HEIGHT=3;

    // get location in grid
    int locX = _posX / TILE_WIDTH;
    int locY = _posY / TILE_HEIGHT;

    // make sure we stay inside grid
    if (locX <= 0 || locX >= GRID_WIDTH) return;
    if (locY <= 0 || locY >= GRID_HEIGHT) return;

    // look around!
    if (_grid [locY] [locX]==ENEMY) // enemy hit us!
    if (_grid [locY-1] [locX]==ENEMY) // enemy is above us

    // and so on...
    [/code]

    A better method is using std::vector so you can have a resizable map.

    Search Google for [b]tilemapping[/b]:-)
Sign In or Register to comment.