Пример #1
0
//-----------------------------------------------------------------------------
//! 更新(この中で更新すべきUpdateを呼び出す)
//-----------------------------------------------------------------------------
void EnemyBase::Update()
{
	// 死亡フラグが立っていたら処理しない
	if( _isDead ) return;
	// 所属している分隊からリーダーの位置を取得
	if( _keyType != KEY_LEADER ) { 
		_goalPos = _pSquad->getLeader()->getPosition();
	}

	s32	currentAnimation = _pTaskModel->getAnimation();

	// リーダーの命令によって処理変更
	UpdateByCommand();
	
	//---- 移動
	// キャラの移動(左スティックの情報取得)
	_mov._x = sinf( _rotation._y )  * _speed;
	_mov._z = cosf( _rotation._y )  * _speed;

	if( _speed > 0.0f ) 
	{
		// デグリーに直す
		_rotation._y = TO_DEGREE(_rotation._y );
	}

	// 更新
	_oldPosition = _position;

	// フリーズしなかったら
	if( !checkFreeze(currentAnimation) ){
		// 移動してなければ
		if( _mov._x == 0.0f && _mov._z == 0.0f )
		{
			// 立ちモーション
			//_aniState = STATE_WAIT;
			if( currentAnimation != _aniWait ) {
				_pTaskModel->setAnimation(_aniWait, ANIMATION_PLAY_REPEAT);
			}
		}else{
			// 歩きモーション
			//_aniState = STATE_MOVE;
			if( currentAnimation != _aniMove ) {
				_pTaskModel->setAnimation(_aniMove, ANIMATION_PLAY_REPEAT);
			}
		}
	}

	// 攻撃してたら
	if( currentAnimation == _aniAttack ) {
		// 移動速度を少なくする
		_mov._x *= 0.5f;
		_mov._z *= 0.5f;
	}else if( currentAnimation == _aniDamage ){
		// 移動速度をなくす
		_mov._x *= 0.0f;
		_mov._z *= 0.0f;
	}

	_position += _mov * Global::deltaTime;

	//---- パーティクル
	// パーティクルの生成待ち時間カウント
	_genCount += 1 * Global::deltaTime;

	Vector3 sub = _oldPosition - _position;

	// 移動している且つ、生成待ち時間が切れた時
	if( (abs(sub._x) > 0.0f || abs(sub._z) > 0.0f) && _genCount >= _waitGenTime ) {

		// カウントリセット
		_genCount = 0;

		Vector3 pos = _position + Vector3( (f32)(rand() % 40 - 20) );

		Vector3 mov = -_mov;

		mov._x *= (rand() %  50) / 100.0f;
		mov._y  = (rand() % 100) / 100.0f;
		mov._z *= (rand() %  50) / 100.0f;

		f32		rot = ( rand() % 20 ) / 20.0f;
		Radian	angVel = Radian( ( rand() % 10 ) / 100.0f );

		// パーティクル生成
		IParticleMan()->generateParticle(pos,
										 mov,
										 Vector3(0.5f, 0.5f, 0.0f),
										 Radian(rot),
										 100, 0,
										 angVel,
										 ParticleManager::PARTICLE_SMOKE); 
	}


	// あたり判定の球の更新
	Man::Update();
	
	//---- マップとの当たり判定
	GmSystemCollision()->checkCollisionModel(_hitPosition, _radius, _hitGround);

	// 外にいけなくする
	ICastleCol()->hitOutRange(_hitPosition);

	// あたり判定用の球情報更新
	setSphereParam(_hitPosition, _hitRadius);
	// 座標の設定
	toPosition(_hitPosition, _position);

	// 重力処理
	if( !_hitGround ){
		_mov._y -= 0.6f * Global::deltaTime;
	}
	else{
		_mov._y = 0.0f;
	}

	// 最大重力設定
	if( _mov._y <= -9.8f )
	{
		_mov._y = -9.8f; 
	}

	if( _aniAttack != -1 ) {

		// 攻撃ボタンが押されているかどうか
		if( _key->getPushState("Attack") )
		{
			// 攻撃アニメーション再生
			_pTaskModel->setAnimation(_aniAttack);
			// 攻撃
			Attack();

		}else if ( currentAnimation == _aniAttack ) {

			// 攻撃再生中なら
			// 再生比率取得
			f32	aniRate = _pTaskModel->getAnimationRate();
			// 再生が半分いったら
			if( aniRate >= 0.5f && !_isAttack ) {
				// 攻撃
				Attack();
			}else if( _isAttack ){
				// 攻撃範囲、座標を戻す
				_attackPosition = Vector3( 0.0f, 0.0f, 0.0f );
				_attackRadius	= 0.0f;
			}

		}else{
			// この時点で半径が初期化されてなければ
			if( _attackRadius != 0.0f ){
				// 攻撃範囲、座標を戻す
				_attackPosition = Vector3( 0.0f, 0.0f, 0.0f );
				_attackRadius	= 0.0f;
			}
			// 攻撃フラグを元に戻す
			_isAttack = false;
		}

	}

	// 体力が0以下なら
	if( _myStatus->getParam()->_HP <= 0 )
	{
		// 死亡フラグを立てる
		_isDead = true;
	}
}
Пример #2
0
void Enemy::updateAction(Landscape* landscape, Point playerPosition)
{
	_AStarFields.clear();
	_AStarAimField = -1;
	_AStarBestField = -1;

	// reset all
	setAccelerating(false);
	setDecelerating(false);
	setAcceleratingLeft(false);
	setAcceleratingRight(false);
	setIncreasingElevation(false);
	setDecreasingElevation(false);
	setIncreasingAzimuth(false);
	setDecreasingAzimuth(false);
	setIncreasingPower(false);
	setDecreasingPower(false);
	setShootingMG(false);
	setShootingGrenade(false);

	// get surrounding of this enemy
	TerrainType** surroundings = landscape->getMap(_position, AI_VIEW_DISTANCE);

	// make sure Point.w is 1 for _position and playerPosition
	_position.x /= _position.w;
	_position.y /= _position.w;
	_position.z /= _position.w;
	_position.w = 1.0f;
	playerPosition.x /= playerPosition.w;
	playerPosition.y /= playerPosition.w;
	playerPosition.z /= playerPosition.w;
	playerPosition.w = 1.0f;

	// field of this enemy
	int x = (int)_position.x + FIELD_SIZE / 2;
	int z = (int)_position.z + FIELD_SIZE / 2;

	//// if this enemy is facing a building, just go backwards and do nothing else
	//TerrainType t11 = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE];
	//TerrainType t21 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 1];
	//TerrainType t31 = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE];
	//TerrainType t41 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 1];
	//TerrainType t12 = surroundings[AI_VIEW_DISTANCE + 2][AI_VIEW_DISTANCE];
	//TerrainType t22 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 2];
	//TerrainType t32 = surroundings[AI_VIEW_DISTANCE - 2][AI_VIEW_DISTANCE];
	//TerrainType t42 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 2];
	//if (_speed >= 0.0f && ((_angle < 45.0f || 315.0f <= _angle) && (surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE] == BUILDING || surroundings[AI_VIEW_DISTANCE + 2][AI_VIEW_DISTANCE] == BUILDING)
	//	|| 45.0f <= _angle && _angle < 135.0f && (surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 1] == BUILDING || surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 2] == BUILDING)
	//	|| 135.0f <= _angle && _angle < 225.0f && (surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE] == BUILDING || surroundings[AI_VIEW_DISTANCE - 2][AI_VIEW_DISTANCE] == BUILDING)
	//	|| 225.0f <= _angle && _angle < 315.0f && (surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 1] == BUILDING || surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 2] == BUILDING)))
	//{
	//	setDecelerating(true);
	//	return;
	//}

	// field of player
	int x_player = (int)playerPosition.x + FIELD_SIZE / 2;
	int z_player = (int)playerPosition.z + FIELD_SIZE / 2;

	// calculate aim vector = vector from this enemy's position to player's position
	Vector3D aim = Vector3D(playerPosition.x - _position.x, 0.0f, playerPosition.z - _position.z);
	float aimAngle = TO_DEGREE(atan2f(-aim.z, aim.x));
	if (aimAngle >= 360.0f)
		aimAngle -= 360.0f;
	else if (aimAngle < 0.0f)
		aimAngle += 360.0f;
	float aimDist = sqrtf(aim.x * aim.x + aim.z * aim.z);

	// find and store all fields in surrounding having a building (used for visibility check)
	IntVector buildingFieldsOfSurrounding;
	for (int ii = 0; ii < 2 * AI_VIEW_DISTANCE + 1; ii++)
	{
		for (int jj = 0; jj < 2 * AI_VIEW_DISTANCE + 1; jj++)
		{
			if (surroundings[ii][jj] == BUILDING)
				buildingFieldsOfSurrounding.push_back((z + jj - AI_VIEW_DISTANCE) * FIELD_SIZE + (x + ii - AI_VIEW_DISTANCE));
		}
	}

	// check if player is within surrounding
	bool inSurrounding = x - AI_VIEW_DISTANCE <= x_player && x_player <= x + AI_VIEW_DISTANCE && z - AI_VIEW_DISTANCE <= z_player && z_player <= z + AI_VIEW_DISTANCE;
	bool visible = false;

	if (inSurrounding)
	{
		// PLAYER IS IN SURROUNDING

		// check if player is directly visible
		visible = isVisible(_position.x, _position.z, playerPosition.x, playerPosition.z, buildingFieldsOfSurrounding);

		if (visible)
		{
			// PLAYER IS DIRECTLY VISIBLE -> aim at player and shoot (do not drive)

			// aim at player
			if (_angle < aimAngle && aimAngle - _angle <= 180.0f || _angle > aimAngle && _angle - aimAngle > 180.0f)
				setAcceleratingLeft(true);
			else
				setAcceleratingRight(true);

			// shoot with machine gun
			setShootingMG(true);
		}

		// shoot grenade if player tank is near (or aim grenade launcher if not ready)
		if (aimDist <= AI_GRENADE_DIST && _hasGrenadeLauncherEnabled)
		{
			if (_firingStateGrenade == READY)
				setShootingGrenade(true);
			else
			{
				float totalAngle = _angle + _azimuth;
				if (totalAngle >= 360.0f)
					totalAngle -= 360.0f;
				else if (totalAngle < 0.0f)
					totalAngle += 360.0f;
				if (totalAngle < aimAngle && aimAngle - totalAngle <= 180.0f || totalAngle > aimAngle && totalAngle - aimAngle > 180.0f)
					setIncreasingAzimuth(true);
				else
					setDecreasingAzimuth(true);

				if (_elevation > 20.0f)
					setDecreasingElevation(true);
			}
		}
	}

	if (!inSurrounding || !visible)
	{
		// PLAYER IS OUTSIDE OF SURROUNDING OR NOT DIRECTLY VISIBLE -> try to get as near as possible to player (do not shoot)

		// find goal state ( = field within surroundings which is closest to player position)
		int i_goal = AI_VIEW_DISTANCE;
		int j_goal = AI_VIEW_DISTANCE;
		float d, min_dist = dist(x, z, playerPosition);
		for (int ii = 0; ii < 2 * AI_VIEW_DISTANCE + 1; ii++)
		{
			for (int jj = 0; jj < 2 * AI_VIEW_DISTANCE + 1; jj++)
			{
				if (surroundings[ii][jj] != BUILDING)
				{
					d = dist(x + ii - AI_VIEW_DISTANCE, z + jj - AI_VIEW_DISTANCE, playerPosition);
					if (d < min_dist)
					{
						min_dist = d;
						i_goal = ii;
						j_goal = jj;
					}
				}
			}
		}

		// variables needed in A* search
		Fringe fringe;
		unsigned int step = 0;
		AStarNode *node = new AStarNode(0.0f, aimDist, AI_VIEW_DISTANCE, AI_VIEW_DISTANCE, AI_VIEW_DISTANCE, AI_VIEW_DISTANCE, true, NULL);
		int i, j;
		bool fieldVisible;

		// add initial state to fringe
		fringe.push(node);

		// do actual A* search
		while (step < AI_MAX_STEPS && !fringe.empty())
		{
			node = fringe.top();
			fringe.pop();
			i = node->i;
			j = node->j;

			if (DEBUG_ENEMY)
				_AStarFields.push_back((z + j - AI_VIEW_DISTANCE) * FIELD_SIZE + (x + i - AI_VIEW_DISTANCE));

			// goal test (stop iteration when goal is reached)
			if (i == i_goal && j == j_goal)
				break;

			// expand node
			if (0 <= i - 1 && surroundings[i - 1][j] != BUILDING && !node->hasVisited(i - 1, j))
			{
				if (node->isVisible)
					fieldVisible = isFieldVisible(_position.x, _position.z, i - 1, j, x, z, surroundings);
				else
					fieldVisible = false;
				//fringe.push(AStarNode(node.cost_so_far + 1.0f, dist(x + i - 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, playerPosition),
				//	i - 1, j, fieldVisible ? i - 1 : node.i_aim, fieldVisible ? j : node.j_aim, fieldVisible));
				fringe.push(new AStarNode(fieldVisible ? dist(x + i - 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, _position) : node->cost_so_far + 1.0f,
					dist(x + i - 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, playerPosition),
					i - 1, j, fieldVisible ? i - 1 : node->i_aim, fieldVisible ? j : node->j_aim, fieldVisible, node));
			}
			if (i + 1 < 2 * AI_VIEW_DISTANCE + 1 && surroundings[i + 1][j] != BUILDING && !node->hasVisited(i + 1, j))
			{
				if (node->isVisible)
					fieldVisible = isFieldVisible(_position.x, _position.z, i + 1, j, x, z, surroundings);
				else
					fieldVisible = false;
				fringe.push(new AStarNode(fieldVisible ? dist(x + i + 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, _position) : node->cost_so_far + 1.0f,
					dist(x + i + 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, playerPosition),
					i + 1, j, fieldVisible ? i + 1 : node->i_aim, fieldVisible ? j : node->j_aim, fieldVisible, node));
			}
			if (0 <= j - 1 && surroundings[i][j - 1] != BUILDING && !node->hasVisited(i, j - 1))
			{
				if (node->isVisible)
					fieldVisible = isFieldVisible(_position.x, _position.z, i, j - 1, x, z, surroundings);
				else
					fieldVisible = false;
				fringe.push(new AStarNode(fieldVisible ? dist(x + i - AI_VIEW_DISTANCE, z + j - 1 - AI_VIEW_DISTANCE, _position) : node->cost_so_far + 1.0f,
					dist(x + i - AI_VIEW_DISTANCE, z + j - 1 - AI_VIEW_DISTANCE, playerPosition),
					i, j - 1, fieldVisible ? i : node->i_aim, fieldVisible ? j - 1 : node->j_aim, fieldVisible, node));
			}
			if (j + 1 < 2 * AI_VIEW_DISTANCE + 1 && surroundings[i][j + 1] != BUILDING && !node->hasVisited(i, j + 1))
			{
				if (node->isVisible)
					fieldVisible = isFieldVisible(_position.x, _position.z, i, j + 1, x, z, surroundings);
				else
					fieldVisible = false;
				fringe.push(new AStarNode(fieldVisible ? dist(x + i - AI_VIEW_DISTANCE, z + j + 1 - AI_VIEW_DISTANCE, _position) : node->cost_so_far + 1.0f,
					dist(x + i - AI_VIEW_DISTANCE, z + j + 1 - AI_VIEW_DISTANCE, playerPosition),
					i, j + 1, fieldVisible ? i : node->i_aim, fieldVisible ? j + 1 : node->j_aim, fieldVisible, node));
			}

			step++;
		}

		if (DEBUG_ENEMY)
		{
			_AStarAimField = (z + node->j_aim - AI_VIEW_DISTANCE) * FIELD_SIZE + (x + node->i_aim - AI_VIEW_DISTANCE);
			_AStarBestField = (z + node->j - AI_VIEW_DISTANCE) * FIELD_SIZE + (x + node->i - AI_VIEW_DISTANCE);
			std::cout << step << std::endl;
		}

		// set new aim according to A* search (aim at farthest visible field in path to the chosen node)
		aim = Vector3D(x + node->i_aim - AI_VIEW_DISTANCE - FIELD_SIZE / 2 + 0.5f - _position.x,
			0.0f,
			z + node->j_aim - AI_VIEW_DISTANCE - FIELD_SIZE / 2 + 0.5f - _position.z);
		aimAngle = TO_DEGREE(atan2f(-aim.z, aim.x));
		if (aimAngle >= 360.0f)
			aimAngle -= 360.0f;
		else if (aimAngle < 0.0f)
			aimAngle += 360.0f;
		aimDist = sqrtf(aim.x * aim.x + aim.z * aim.z);

		// calculate angle difference alpha and steer in the desired direction to reach aim
		float alpha;
		if (_angle < aimAngle)
		{
			alpha = aimAngle - _angle;
			if (alpha <= 180.0f)
				setAcceleratingLeft(true);
			else
			{
				alpha = 360.0f - alpha;
				setAcceleratingRight(true);
			}
		}
		else
		{
			alpha = _angle - aimAngle;
			if (alpha <= 180.0f)
				setAcceleratingRight(true);
			else
			{
				alpha = 360.0f - alpha;
				setAcceleratingLeft(true);
			}
		}

		//// if this enemy is facing a building, go backwards, no matter where the aim is
		//if (/*_speed >= 0.0f &&*/ ((_angle < 45.0f || 315.0f <= _angle) && surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE] == BUILDING /*|| surroundings[AI_VIEW_DISTANCE + 2][AI_VIEW_DISTANCE] == BUILDING*/
		//	|| 45.0f <= _angle && _angle < 135.0f && surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 1] == BUILDING /*|| surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 2] == BUILDING*/
		//	|| 135.0f <= _angle && _angle < 225.0f && surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE] == BUILDING /*|| surroundings[AI_VIEW_DISTANCE - 2][AI_VIEW_DISTANCE] == BUILDING*/
		//	|| 225.0f <= _angle && _angle < 315.0f && surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 1] == BUILDING /*|| surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 2] == BUILDING*/))
		//{
		//	setDecelerating(true);
		//}
		//else
		//{
			// else: using alpha, maximum turn speed and distance to aim to adapt speed to reach aim
			if (alpha != 0.0f)
			{
				float v_optimal = AI_SPEED_FACTOR * omega_max * aimDist / 2.0f / std::sin(TO_RADIAN(alpha) / 2.0f);
				if (_speed < v_optimal)
					setAccelerating(true);
				else
					setDecelerating(true);
			}
			else
				setAccelerating(true);
		//}

		// delete nodes
		while (!fringe.empty())
		{
			delete fringe.top();
			fringe.pop();
		}
	}

	// if this enemy is facing a building, go backwards
	TerrainType t11 = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE];
	TerrainType t11l = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE - 1];
	TerrainType t11r = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE + 1];
	TerrainType t12 = surroundings[AI_VIEW_DISTANCE + 2][AI_VIEW_DISTANCE];
	TerrainType t12l = surroundings[AI_VIEW_DISTANCE + 2][AI_VIEW_DISTANCE - 1];
	TerrainType t12r = surroundings[AI_VIEW_DISTANCE + 2][AI_VIEW_DISTANCE + 1];
	TerrainType t21 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 1];
	TerrainType t21l = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE - 1];
	TerrainType t21r = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE - 1];
	TerrainType t22 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE - 2];
	TerrainType t22l = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE - 2];
	TerrainType t22r = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE - 2];
	TerrainType t31 = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE];
	TerrainType t31l = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE - 1];
	TerrainType t31r = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE + 1];
	TerrainType t32 = surroundings[AI_VIEW_DISTANCE - 2][AI_VIEW_DISTANCE];
	TerrainType t32l = surroundings[AI_VIEW_DISTANCE - 2][AI_VIEW_DISTANCE - 1];
	TerrainType t32r = surroundings[AI_VIEW_DISTANCE - 2][AI_VIEW_DISTANCE + 1];
	TerrainType t41 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 1];
	TerrainType t41l = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE + 1];
	TerrainType t41r = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE + 1];
	TerrainType t42 = surroundings[AI_VIEW_DISTANCE][AI_VIEW_DISTANCE + 2];
	TerrainType t42l = surroundings[AI_VIEW_DISTANCE - 1][AI_VIEW_DISTANCE + 2];
	TerrainType t42r = surroundings[AI_VIEW_DISTANCE + 1][AI_VIEW_DISTANCE + 2];
	if (/*_speed >= 0.0f &&*/ ((_angle < 45.0f || 315.0f <= _angle) && (t11 == BUILDING /*|| t11l == BUILDING || t11r == BUILDING*/ || t12 == BUILDING /*|| t12l == BUILDING || t12r == BUILDING*/)
		|| 45.0f <= _angle && _angle < 135.0f && (t21 == BUILDING /*|| t21l == BUILDING || t21r == BUILDING */|| t22 == BUILDING /*|| t22l == BUILDING || t22r == BUILDING*/)
		|| 135.0f <= _angle && _angle < 225.0f && (t31 == BUILDING /*|| t31l == BUILDING || t31r == BUILDING */|| t32 == BUILDING /*|| t32l == BUILDING || t32r == BUILDING*/)
		|| 225.0f <= _angle && _angle < 315.0f && (t41 == BUILDING /*|| t41l == BUILDING || t41r == BUILDING */|| t42 == BUILDING /*|| t42l == BUILDING || t42r == BUILDING*/)))
	{
		setAccelerating(false);
		setDecelerating(true);
	}

	// delete surroundings
	for (int s = 0; s < 2 * AI_VIEW_DISTANCE + 1; s++)
		delete[] surroundings[s];
	delete[] surroundings;

	// random movement
	/*setAccelerating(rand()%2==0);
	setDecelerating(rand()%2==0);
	setAcceleratingLeft(rand()%2==0);
	setAcceleratingRight(rand()%5==0);
	setIncreasingElevation(rand()%2==0);
	setDecreasingElevation(rand()%2==0);
	setIncreasingAzimuth(rand()%2==0);
	setDecreasingAzimuth(rand()%2==0);
	setIncreasingPower(rand()%2==0);
	setDecreasingPower(rand()%2==0);*/

	/*if(rand()%10==0)
		shoot();*/
}
Пример #3
0
void level::renderLevel(character &currentCharacter, level &currentLevel)
{
	float2D tempPos;
	switch(_colorModel)
	{
		//This is the full color mode
		//This is black tiles
		case 1:
			currentCharacter.render();
			_render();
			break;
			//This is feathered lighting model and the
			//point light model
		case 2:
			//check if the player has moved
			tempPos = currentCharacter.getPosition() + float2D().polarRotate(currentCharacter.getViewAngle())*currentCharacter.getSize();
			if(!(_previousCharacterPos == tempPos) || currentCharacter.getViewAngle() != _flashLightAngle)
			{
				_frontSound = 0;
				_leftSound = 0;
				_backSound = 0;
				_rightSound = 0;
				//if the player has moved then set the 
				//previous position to the new position
				_previousCharacterPos = tempPos;
				_flashLightAngle = currentCharacter.getViewAngle();
				//next update the flash light
				_flashLight = new light(_previousCharacterPos, TO_DEGREE(_flashLightAngle) - (135 / 2), 135, 135, 100);
				//_flashLight = new light(_previousCharacterPos, TO_DEGREE(_flashLightAngle), 1, 1, 200);
				_flashLight->buildEmitter(currentLevel, currentCharacter);
				cout << endl;
				cout << "Front sound: " << _frontSound << endl;
				cout << "Back sound: " << _backSound << endl;
				cout << "Left sound: " << _leftSound << endl;
				cout << "Right sound: " << _rightSound << endl;
				ALchangeGain(_frontSound, _leftSound, _backSound, _rightSound);
			}
			currentCharacter.render();
			_render();
			break;
		case 3:
		case 4:
			_render();
			_renderRayTexture();
			currentCharacter.render();
			
			
			
			break;
			//This is the mode you can see the 
			//rays in i.e. the light debug render
		case 5:
			//check if the player has moved
			tempPos = currentCharacter.getPosition() + float2D().polarRotate(currentCharacter.getViewAngle())*currentCharacter.getSize();
			if(!(_previousCharacterPos == tempPos) || currentCharacter.getViewAngle() != _flashLightAngle)
			{
				_frontSound = 0;
				_leftSound = 0;
				_backSound = 0;
				_rightSound = 0;
				//if the player has moved then set the 
				//previous position to the new position
				_previousCharacterPos = tempPos;
				_flashLightAngle = currentCharacter.getViewAngle();
				//next update the flash light
				_flashLight = new light(_previousCharacterPos, TO_DEGREE(_flashLightAngle) - (135/2), 135, 135, 100);
				//_flashLight = new light(_previousCharacterPos, TO_DEGREE(_flashLightAngle), 1, 1, 200);
				_flashLight->buildEmitter(currentLevel, currentCharacter);
				
				cout << "Front sound: " << _frontSound << endl;
				cout << "Back sound: " << _backSound << endl;
				cout << "Left sound: " << _leftSound << endl;
				cout << "Right sound: " << _rightSound << endl;
			}
			currentCharacter.render();
			_flashLight->debugRender();
			_render();
			break;
			//This will be the flash light mode
		case 6:
			break;
			//This is the sound model
		case 7:
			break;
		default:;
	}
}