Exemple #1
0
void Map::setup(IGame &game, int cols, int rows, int width, int height)
{
    this->c=cols;
    this->r=rows;
    this->w=width;
    this->h=height;
    m.clear();
    m.resize(cols,vector<int>(rows,0));
    // Changed for use a same seed
    //srand(time(NULL));
    mapgen();
    game.getPacman()->X((cols/2+0.5)*width);
    game.getPacman()->Y(1.5*height);
    game.getPacman()->speed(width*3.0);
    unsigned int c=0;
    for(int j=-2;j<=0;j++)
        for(int i=-2;i<=2;i++)
            if(c<game.getGhosts().size())
            {
                IGhost *g=game.getGhosts().at(c);
                // ghost's speed is dynamic
                //g->speed(game.getPacman()->speed()*1.5);
                g->X((cols/2+i+0.5)*width);
                g->Y((rows/2+j+0.5)*height);
                c++;
            }
    game.reshape(0,0);
}
void FakeArtificialIntelligence::idle(IGame &game)
{
    double px=game.getPacman()->X();
    double py=game.getPacman()->Y();
    for(unsigned int c=0;c<game.getGhosts().size();c++)
    {
        IGhost *g=game.getGhosts().at(c);
        double gx=g->X();
        double gy=g->Y();
        if(py==gy) py-=0.1;
        double r=(px-gx)/(py-gy);
        if(r>1||r<-1)
        {
            if(px<gx)
            {
                g->setDirection(-1,0);
            }
            else
            {
                g->setDirection(1,0);
            }
        }
        else
        {
            if(py<gy)
            {
                g->setDirection(0,-1);
            }
            else
            {
                g->setDirection(0,1);
            }
        }
    }
}