예제 #1
0
파일: gamedisplay.cpp 프로젝트: bbaksh/pvz
void GameDisplay::moveZombiesAndPlants()
{

    for(int i=0;i<lawnmowerVector.size();i++)
    {
        if(lawnmowerVector[i]->getX()==800&&lawnmowerVector[i]->timeElapsed()>=1500)//removes a lawnmower 1.5 seconds if it was triggered
        {
            lawnmowerVector[i]->setPosition(-1,-1);
            scene()->removeItem(lawnmowerVector[i]);
        }
    }
    for(int i=0;i<zombieVector.size();i++)
    {
        if(zombieVector[i]->getX()<0&&zombieVector[i]->getY()!=-1)//triggers a lawnmower if a zombie steps on it
        {
            emit lawnmowerAttack(zombieVector[i]);
        }
        for(int n=0;n<plantVector.size();n++)
        {
            if(zombieVector[i]->getX()!=-1&&plantVector[n]->getX()!=-1)//only cycles through plants and zombies that are visible to the scene
            {
                if(zombieVector[i]->getX()==plantVector[n]->getX()&&zombieVector[i]->getY()==plantVector[n]->getY())//checks if a zombie encountered a plant
                {
                    zombieVector[i]->setMovement(false);//stops movement
                    emit zombieAttack(zombieVector[i],plantVector[n]);
                }
                else
                {
                    if(plantVector[n]->getStatus())//checks if the plant died
                        zombieVector[i]->setMovement(true);//allows zombie to move again
                }
                if(zombieVector[i]->getX()>=plantVector[n]->getX()&&zombieVector[i]->getY()==plantVector[n]->getY())//checks if a zombie is infront a plant
                {
                    if((plantVector[n]->getType()==1||plantVector[n]->getType()==6||plantVector[n]->getType()==8))//if the plant is ranged, attack it
                    {
                        emit plantAttack(zombieVector[i],plantVector[n]);
                    }
                }
                if(zombieVector[i]->getX()==plantVector[n]->getX()&&zombieVector[i]->getY()==plantVector[n]->getY()&&plantVector[n]->getType()==5)//checks if a zombie triggers potato mine
                {
                    grid[plantVector[n]->getY()/100][plantVector[n]->getX()/90]=true;//allow to plant here after mine disappears
                    plantVector[n]->setPosition(-1,-1);
                    zombieVector[i]->setPosition(-1,-1);
                    zombieVector[i]->loseHealth(plantVector[n]->getDamage());
                    scene()->removeItem(plantVector[n]);
                    scene()->removeItem(zombieVector[i]);
                }
                if(plantVector[n]->getType()==3&&plantVector[n]->timeElapsed()>=1000)//if a cherry bomb is placed and 1 second passes, trigger it
                {
                    for(int m=0;m<zombieVector.size();m++)
                    {
                        if((zombieVector[m]->getX()>=plantVector[n]->getX()-90)&&(zombieVector[m]->getX()<plantVector[n]->getX()+180)&&(zombieVector[m]->getY()>=plantVector[n]->getY()-100)&&(zombieVector[m]->getY()<plantVector[n]->getY()+200))//checks for zombies in a 3x3 radius of the cherry bomb
                        {
                            zombieVector[m]->loseHealth(plantVector[n]->getDamage());//kills them acordingly
                            zombieVector[m]->setPosition(-1,-1);
                            scene()->removeItem(zombieVector[m]);
                        }
                    }
                    grid[plantVector[n]->getY()/100][plantVector[n]->getX()/90]=true;//allows to plant on the grid again
                    plantVector[n]->setPosition(-1,-1);
                    scene()->removeItem(plantVector[n]);
                }
                if(zombieVector[i]->getX()==plantVector[n]->getX()&&zombieVector[i]->getY()==plantVector[n]->getY()&&plantVector[n]->getType()==7)//checks if a zombie is on chomper
                {
                    if(plantVector[n]->okayToChomp())//checks if chomper can attack
                    {
                        zombieVector[i]->loseHealth(plantVector[n]->getDamage());
                        if(zombieVector[i]->getLife()<=0)
                        {
                            zombieVector[i]->setPosition(-1,-1);
                            scene()->removeItem(zombieVector[i]);
                        }

                    }
                }
            }

        }
        zombieVector[i]->slideZombie();//move the zombies
        scene()->update();//refresh the scene
    }
    for(int i=0;i<sunVector.size();i++)
    {
        if(sunVector[i]->getType()==1)//see what random suns have spawned (not sunflower suns)
        {
            sunVector[i]->slideSun();//slide random suns
            scene()->update();
        }
    }

}
예제 #2
0
void Zombie::attack(const Human& target)
{
  zombieAttack(ptr, target.ptr);
}