Beispiel #1
0
void Zombie::update(const std::vector<std::string>& levelData,
	std::vector<Human*>& humans,
	std::vector<Zombie*>& zombies,
	float deltaTime) {

	Human* closestHuman = getNearestHuman(humans);

	if (closestHuman != nullptr) {
		_direction = glm::normalize(closestHuman->getPosition() - _position);
		_position += _direction * _speed * deltaTime;
	}

	collideWithLevel(levelData);

}
Beispiel #2
0
void Zombie::update(const std::vector<std::string>& levelData,
                    std::vector<Human*>& humans,
                    std::vector<Zombie*>& zombies) {

    // Find the closest human
    Human* closestHuman = getNearestHuman(humans);

    // If we found a human, move towards him
    if (closestHuman != nullptr) {
        // Get the direction vector twoards the player
        glm::vec2 direction = glm::normalize(closestHuman->getPosition() - _position);
        _position += direction * _speed;
    }

    // Do collision
    collideWithLevel(levelData);
}