コード例 #1
0
ファイル: UnitFiring.cpp プロジェクト: pthimon/hammerQt
bool UnitFiring::launch(osg::Vec3 from, osg::Vec3 direction) {
	bool loaded = isLoaded();
	bool inRange = isTargetInRange(mTargetPosition);
	if (loaded && inRange) {
		//create and launch projectile
		Projectile *projectile = new Projectile(mProjectileRadius, mProjectileMass, mProjectileYield, mProjectileType);
		projectile->init();
		projectile->setPosition(from);
		projectile->setTarget(mTargetPosition);
		projectile->setOwner(this);
		projectile->launch(direction, mProjectileVelocity);

		theApp->BroadcastEvent(Event::FIRE, this,  const_cast<Unit*>(mTargetUnit));

		/*//debug
		osg::Vec3 t = p->getPosition();
		std::cout << "Launching projectile from " << t[0] << "," << t[1] << "," << t[2] << std::endl;
		std::cout << "With direction " << direction[0] << "," << direction[1] << "," << direction[2] << std::endl;
		direction.normalize();
		std::cout << "With (normalized) direction " << direction[0] << "," << direction[1] << "," << direction[2] << std::endl;*/

		reload();

		return true;

	} else if (!loaded) {
		//std::cout << "Reloading! You must wait " << getRemainingReloadTime() << "secs!" << std::endl;
		//theApp->hudGUI->setReload(mReloadWindow, getRemainingReloadTime());
	} else if (!inRange) {
		//std::cout << "Target is out of range! Target is " << (mTargetPosition - getPosition()).length() << " away, max range is " << getProjectileRange() << std::endl;
	}
	return false;
}
コード例 #2
0
ファイル: weapon_system.cpp プロジェクト: Gordath/mars2030
void WeaponSystem::shoot_gun(GunPosition gun_pos, long time)
{
	Projectile *p = new Projectile;
	p->init();
	Object *front = guns[gun_pos]->get_object("NUC_energy.nogravity$front");
	Object *back = guns[gun_pos]->get_object("NUC_energy.nogravity$back");
    Vector3 front_pos = front->get_matrix().get_translation();
	Vector3 back_pos = back->get_matrix().get_translation();
	Vector3 vel = front_pos - back_pos;
	vel.normalize();
	p->set_velocity(vel);
	p->set_position(front_pos);
	p->set_speed(125.0);
	if (heat >= 70) {
		p->set_dmg(overheat_dmg);
	}
	else {
		p->set_dmg(dmg);
	}
	p->calc_matrix(time);
	NucEmitter *em = p->get_emitter();
	Vector4 start_color = em->get_start_color();
	Vector4 end_color = em->get_end_color();

	float vec_term = (std::max)(0.0, (std::min)(1.0 - heat_factor * 1.51, 1.0));

	Vector3 factor_vec = Vector3(1.0, vec_term, vec_term);
	em->set_start_color(Vector4(start_color.x, start_color.y * factor_vec.y, start_color.z * factor_vec.z, start_color.w));
	em->set_end_color(Vector4(end_color.x, end_color.y  * factor_vec.y, end_color.z  * factor_vec.z, end_color.w));
	em->calc_matrix(time);
	add_projectile(p);


	muzzle_emitters[gun_pos]->set_active(true);
	muzzle_emitters[gun_pos]->set_activation_time(time);

	int anim_idx = guns[gun_pos]->lookup_animation("shoot");
	if (anim_idx == -1)
		return;
	guns[gun_pos]->start_animation(anim_idx, time);
	guns[gun_pos]->set_anim_speed(anim_idx, fire_rate);

	heat += log(heat_rate) * 1.1;
	heat_rate++;

	if (heat >= 100){
		heat = 100;
		heat_rate = 0;
		overheated = true;
		game::engine::audio_manager->play_sample(game::utils::get_audio_sample_by_name("overheat"), 1.0, AUDIO_PLAYMODE_ONCE);
		game::engine::audio_manager->play_sample(game::utils::get_audio_sample_by_name("alarm"), 0.4, AUDIO_PLAYMODE_ONCE, Vector3(), &overheat_alarm_source_idx);
		game::engine::audio_manager->play_sample(game::utils::get_audio_sample_by_name("warning"), 1.5, AUDIO_PLAYMODE_LOOP, Vector3(), &warning_source_idx);
	}

	game::engine::audio_manager->play_sample(game::utils::get_audio_sample_by_name("laser_gun"), 1.0, AUDIO_PLAYMODE_ONCE, front_pos);
}
コード例 #3
0
ファイル: Projectile.cpp プロジェクト: ashpemb/TGPProject
Projectile* Projectile::create(Vec2 position, Vec2 direction)
{
	Projectile* bullet = new Projectile();
	if (!bullet->init())
	{
		CC_SAFE_DELETE(bullet);
		return nullptr;
	}
	bullet->autorelease();

	bullet->setPosition(position);
	bullet->setRotation(-CC_RADIANS_TO_DEGREES(direction.getAngle()));
	bullet->direction = direction;
	
	return bullet;
}
コード例 #4
0
ファイル: Hunter.cpp プロジェクト: Rubiks14/LudumDare33Entry
std::vector<Projectile> Hunter::shootBullets(long currentTime)
{
	std::mt19937 randEng;
	randEng.seed(SDL_GetTicks());
	std::uniform_real_distribution<float> randAngle(-4.0, 4.0);
	std::uniform_int_distribution<int> randX(0, 10);
	std::vector<Projectile> bullets;
	if (currentTime >= shootTime)
	{
		for (int i = 0; i < 5; i++)
		{
			MoveableObject newbulletBody;
			double angle = this->body->getDirection() + randAngle(randEng);
			newbulletBody.init(this->body->getPosition(), angle, 20, 20);
			Projectile bullet;
			bullet.init(newbulletBody, TYPE_BULLET, 600, "bulletTexture");
			bullets.push_back(bullet);
		}
		shootTime = currentTime + shootInterval;
	}
	status = WELL;
	action = TRACK;
	return bullets;
}