Esempio n. 1
0
static void handleMouse(void)
{
	faceMouse();
	
	if (battle.status == MS_IN_PROGRESS)
	{
		if (isControl(CONTROL_FIRE) && !player->reload && player->guns[0].type)
		{
			if (player->selectedGunType != BT_ROCKET)
			{
				fireGuns(player);
			}
			else
			{
				fireRocket(player);
			}
			
			if (battle.hasSuspicionLevel && !battle.numEnemies && !battle.suspicionCoolOff)
			{
				battle.suspicionLevel += (MAX_SUSPICION_LEVEL * 0.05);
			}
		}
		
		if (isControl(CONTROL_ACCELERATE))
		{
			if (battle.boostTimer > BOOST_FINISHED_TIME || game.currentMission->challengeData.noBoost)
			{
				applyFighterThrust();
			}
		}
		
		if (isControl(CONTROL_MISSILE))
		{
			preFireMissile();
			
			app.mouse.button[SDL_BUTTON_MIDDLE] = 0;
		}
		
		if (isControl(CONTROL_GUNS))
		{
			switchGuns();
			
			app.mouse.button[SDL_BUTTON_X1] = 0;
		}
		
		if (isControl(CONTROL_RADAR))
		{
			cycleRadarZoom();
			
			app.mouse.button[SDL_BUTTON_X2] = 0;
		}
	}
}
Esempio n. 2
0
void Player::update(sf::RenderWindow const &window, BulletManager &bManager,
					sf::Time &time, bool isThrusting, bool isShooting)
{
	static sf::Time prevTime;
	//extern size_t playerEnergy;

	sf::Vector2f pos = playerT.getPosition();
	sf::Vector2f mPos = sf::Vector2f(sf::Mouse::getPosition(window));
	sf::Vector2f faceDir;

	if(isShooting)
		fireMod += 0.03f;
	if(fireMod > 0.02f)
		fireMod -= 0.02f;
	else
		fireMod = 0.00f;

	if(vec2fLen(mPos - pos) > 20.0f)
	{
		faceDir = faceMouse(pos, mPos);

		if(isThrusting && playerVel < 8.0f)
		{
			playerVel += 0.2f;

			// fix this, not looping properly
			/*
			if(rocketSound.getStatus() == sf::SoundSource::Status::Stopped)
			rocketSound.play();
			*/
		}
		else if(playerVel > 0.5f)
		{
			playerVel -= 0.05f;
			//rocketSound.stop();
		}

		playerT.move(faceDir * playerVel);
		if(isHit)
			isHit = false;
	}
	else
	{
		// player 'hit' the crosshair
		if(!isHit)
		{
			hurtSound.play();
			playerVel = 0.0;
			//playerEnergy -= 25;
			isHit = true;
		}

		return;
	}

	if(isShooting && (time - prevTime).asSeconds() > 0.20f)
	{
		bManager.addBullet(playerT.getPosition(), faceDir, 20.0f, fireMod);
		//--playerEnergy;
		prevTime = time;
	}

	// die
	/*
	if(playerEnergy <= 0)
	{
	//playerVel = 0.0;
	}
	*/
}