Beispiel #1
0
static int drawGib()
{
	if (drawLoopingAnimationToMap() == TRUE)
	{
		if (!(self->flags & ON_GROUND))
		{
			if (prand() % 6 == 0)
			{
				addBlood(self->x + self->w / 2, self->y + self->h / 2);
			}
		}

		else
		{
			self->frameSpeed = 0;
		}
	}

	return TRUE;
}
Beispiel #2
0
void MainGame::updateBullet(float deltaTime){

	bool wasBulletRemoved;
	//=打墙
	for (int i = 0; i < _bullets.size();i++){
		//打墙上了
		
		if (_bullets[i].update(_levels[_currentLevel]->getLevelData(), _deltaTime)){
			_bloodColor.r = 139;
			_bloodColor.g = 170;
			_bloodColor.b = 102;
			_bloodColor.a = 128;
			addBlood(_bullets[i].getPosition(), 10,3.0f);///<我曹,冒血了
			_bullets[i] = _bullets.back();
			_bullets.pop_back();
		}
	}
	//打人
	for (int i = 0; i < _bullets.size();i++){
		wasBulletRemoved = false;
		for (int j = 0; j < _zombies.size();){
			//打僵尸
			if (_bullets[i].collideWithAgent(_zombies[j])){
				_bloodColor.r = 139;
				_bloodColor.g = 0;
				_bloodColor.b = 0;
				_bloodColor.a = 128;
				addBlood(_zombies[j]->getAgentPos(), 20,30.0f);///<我曹,冒血了
				_zombies[j]->setPosition(_zombies[j]->getAgentPos() + glm::vec2(_bullets[i].getDirection().x*2,_bullets[i].getDirection().y*2));
				if (_zombies[j]->applyDamage(_bullets[i].getDamge())){
					//僵尸消失
					delete _zombies[j];
					_zombies[j] = _zombies.back();
					_zombies.pop_back();
					std::cout << "还有" << _zombies.size() << "个僵尸!" << std::endl;
				}else{
					j++;
				}
				//子弹消失
				_bullets[i] = _bullets.back();
				_bullets.pop_back();
				_numZombieKilled++;
				wasBulletRemoved = true;
				i--;
				break;
			}
			else{
				j++;
			}
		}
		if (wasBulletRemoved == false){

			for (int j = 1; j < _humans.size();){
				//打人啦
				if (_bullets[i].collideWithAgent(_humans[j])){
					_bloodColor.r = 139;
					_bloodColor.g = 0;
					_bloodColor.b = 0;
					_bloodColor.a = 128;
					addBlood(_humans[j]->getAgentPos(),20,30.0f);///<冒血了
					_humans[j]->setPosition(_humans[j]->getAgentPos() + glm::vec2(_bullets[i].getDirection().x * 2, _bullets[i].getDirection().y * 2));

					if (_humans[j]->applyDamage(_bullets[i].getDamge())){
						//人消失
						delete _humans[j];
						_humans[j] = _humans.back();
						_humans.pop_back();
					}
					else{
						j++;
					}
					//子弹消失
					_bullets[i] = _bullets.back();
					_bullets.pop_back();
					_numHumKilled++;
					wasBulletRemoved = true;
					i--;
					break;
				}
				else{
					j++;
				}
			}
		}
	}

}
Beispiel #3
0
void MainGame::updateAgent(float deltaTime){
	//更新人类
	for (int i = 0; i < _humans.size();i++){
		_humans[i]->update(_levels[_currentLevel]->getLevelData(), _humans, _zombies, _deltaTime);
	}

	//更新僵尸
	for (int i = 0; i < _zombies.size(); i++){
		_zombies[i]->update(_levels[_currentLevel]->getLevelData(), _humans, _zombies, _deltaTime);
	}

	for (int i = 0; i < _humans.size(); i++){
		for (int j = i + 1; j < _humans.size();j++){
			_humans[i]->collideWithAgent(_humans[j]);
		}
	}

	for (int i = 0; i < _zombies.size(); i++){
		//同类
		for (int j = i + 1; j < _zombies.size(); j++){
			_zombies[i]->collideWithAgent(_zombies[j]);
		}
		//传染
		for (int j = 1; j < _humans.size(); j++){
			if (_zombies[i]->collideWithAgent(_humans[j])){
				//添加僵尸
				//此处僵尸升级

				_zombies[i]->beStronger();
				_zombies.push_back(new Zombie);
				_zombies.back()->init(ZOMBIE_SPEED, _humans[j]->getAgentPos());

				//播放被僵尸感染音效
				//_audioEngine.loadSoundEffect("Sound/zombie.mp3").play();
				

				_humans[j] = _humans.back();
				_humans.pop_back();
				
			}
		}
		//与玩家碰上,玩家被咬死
		if (_zombies[i]->collideWithAgent(_player)){
			//此处需要修改
			if (_player->applyDamage(_zombies[i]->getDamage())){
				//_audioEngine.loadSoundEffect("Sound/die.ogg").play();
				_bloodColor.r = 139;
				_bloodColor.g = 0;
				_bloodColor.b = 0;
				_bloodColor.a = 128;
				addBlood(_player->getAgentPos(),10,50.0f);
				
				_camera.setScale(2);
				
				//::fatalError("你已被咬死!");
			}
		}
	}


}
Beispiel #4
0
void MainGame::updateBullets(float deltaTime) {
	// Update and collide with world
	for (int i = 0; i < m_bullets.size();) {
		// If update returns true, the bullet collided with a wall
		if (m_bullets[i].update(m_levels[m_currentLevel]->getLevelData(), deltaTime) || m_bullets[i].outOfRange()) {
			m_bullets[i] = m_bullets.back();
			m_bullets.pop_back();
		}
		else {
			i++;
		}
	}

	bool wasBulletRemoved;

	// Collide with humans and zombies
	for (int i = 0; i < m_bullets.size(); i++) {
		wasBulletRemoved = false;
		// Loop through zombies
		for (int j = 0; j < m_zombies.size();) {
			// Check collision
			if (m_bullets[i].collideWithAgent(m_zombies[j])) {
				// Add blood
				addBlood(m_bullets[i].getPosition(), 5);

				// Damage zombie, and kill it if its out of health
				if (m_zombies[j]->applyDamage(m_bullets[i].getDamage())) {
					// If the zombie died, remove him
					delete m_zombies[j];
					m_zombies[j] = m_zombies.back();
					m_zombies.pop_back();
					m_numZombiesKilled++;
				}
				else {
					j++;
				}

				// Remove the bullet
				m_bullets[i] = m_bullets.back();
				m_bullets.pop_back();
				wasBulletRemoved = true;
				i--; // Make sure we don't skip a bullet
				// Since the bullet died, no need to loop through any more zombies
				break;
			}
			else {
				j++;
			}
		}
		// Loop through humans
		if (wasBulletRemoved == false) {
			for (auto j = 1; j < m_humans.size();) {
				// Check collision
				if (m_bullets[i].collideWithAgent(m_humans[j])) {
					// Add blood
					addBlood(m_bullets[i].getPosition(), 5);
					// Damage human, and kill it if its out of health
					if (m_humans[j]->applyDamage(m_bullets[i].getDamage())) {
						// If the human died, remove him
						delete m_humans[j];
						m_humans[j] = m_humans.back();
						m_humans.pop_back();
					}
					else {
						j++;
					}

					// Remove the bullet
					m_bullets[i] = m_bullets.back();
					m_bullets.pop_back();
					m_numHumansKilled++;
					i--; // Make sure we don't skip a bullet
					// Since the bullet died, no need to loop through any more zombies
					break;
				}
				else {
					j++;
				}
			}
		}
	}
}