RoomWhere Room::where(float x, float z, float radius) const {
    if (x + radius > Room::width) {
        if (doors[1] and glm::abs(z) < doorWidth)
            return E_DOOR;
        return E_COLLISION;
    } if (x - radius < -Room::width) {
        if (doors[3] and glm::abs(z) < doorWidth)
            return W_DOOR;
        return W_COLLISION;
    } if (z + radius > Room::width) {
        if (doors[2] and glm::abs(x) < doorWidth)
            return S_DOOR;
        return S_COLLISION;
    } if (z - radius < -Room::width) {
        if (doors[0] and glm::abs(x) < doorWidth)
            return N_DOOR;
        return N_COLLISION;
    }

    for (Enemy *enemy : enemies) { //cofres
        if (enemy->type()==5 and collition(enemy->position(),glm::vec3(x,0,z),enemy->radius(),radius)) {
            return COLLISION;
        }
    }
    return CAN_BE;
}
Exemple #2
0
void game::update(){
	if(meny->getShowMeny()){//if meny is on.
		meny->guiUpdate();//calls meny memeber function guiUpdate.
		resetGame(); // resets the game over and over.
	} else { //if meny is off.
		ball->movementOfBall(updateTime);//move the ball with updatetime clock.
		//Player pad movement.
		if(fPlayer->getLeft()){//if player pad should move left.
			fPlayer->moveLeft();//move player pad left.
		}
		if(fPlayer->getRight()){//if player pad should move right.
			fPlayer->moveRight();//move player pad right.
		}

		if(boxesIsEmpty()){ //vector with boxes is empty
			meny->winner(updateTime);//call winning text.
		}

		if(ball->checkIfDead()){//check if ball is dead(position under player pad).
			fPlayer->loseLife();//removes a extra life.
			if(fPlayer->getLife() >= 0){//if extra life is more/= to 0.
				delete ball;//delete old ball
				ball = new bounceBall();//alocate new ball.
			}else{
				meny->gameOver(updateTime);//show gameover text object.
			}
		}
		collition();//check if ball collide with something.
	} 
}
bool Room::enemiesCollision(Enemy *e, glm::vec3 nextPos) {
    /*evitar q los enemigos se transpasen, no contar las balas*/
    if (e->type() == 4)
        return false;
    for (Enemy *other_enemy : enemies){
        if (other_enemy != e and other_enemy->type() != 4)
            return collition(other_enemy->position(),nextPos,other_enemy->radius(),e->radius());
    }
    return false;
}
int Room::playerCollision(glm::vec3 playerPos, float r) {
    for (Enemy *enemy : enemies) {
        if (collition(enemy->position(),playerPos,enemy->radius(),r)) {
            if (enemy->type() == 4)
                enemy->receiveImpact(1);
            return enemy->getPower();
        }
    }
    return 0;
}
bool Room::openTreasure(glm::vec3 pos, glm::vec3 dir, float r) {
    for (Enemy *e : enemies){
        if (e->type() == 5 and collition(pos+dir*(r+e->radius()),e->position(),r,e->radius())){// hay cofre delante
            std::cout<<"cofreee!"<<std::endl;
            e->receiveImpact(-1);
            return true;
        }
    }
    return false;
}
int Room::itemCollition(glm::vec3 pos, float r) {
    for (int i=0 ; i<items.size() ; ++i){
        if (collition(pos,items[i]->position(),r,Item::radio)){
            int item = items[i]->getType();
            items.erase(items.begin()+i);
            return item;
        }
    }
    return -1;
}
int Room::bulletCollision(Enemy *e) {
    if (e->getLifePoints() <= 0 )
        return 0;
    for (Enemy *other_enemy : enemies)
        if (other_enemy != e and other_enemy->type() == 4 and other_enemy->getLifePoints() > 0)
            if (collition(other_enemy->position(),e->position(),other_enemy->radius(),e->radius())){
                other_enemy->receiveImpact(1);
                return other_enemy->getPower();
            }
    return 0;
}
glm::vec3 Room::generatePosition(float r) {
    glm::vec3 newPos= {0,0,0};
    if (enemies.empty()){
        newPos.x = std::uniform_real_distribution<float>(-width*0.5f, width*0.5f)(random_engine);
        newPos.z = std::uniform_real_distribution<float>(-width*0.5f, width*0.5f)(random_engine);
        return newPos;
    }

    int i = 0;
    while(i != enemies.size()){
        newPos.x = std::uniform_real_distribution<float>(-width*0.5f, width*0.5f)(random_engine);
        newPos.z = std::uniform_real_distribution<float>(-width*0.5f, width*0.5f)(random_engine);
        for (i=0 ; i<enemies.size() and !collition(enemies[i]->position(),newPos,enemies[i]->radius(),r); ++i){}
    };
    return newPos;
}