当前位置: 首页>>代码示例>>C++>>正文


C++ Ship类代码示例

本文整理汇总了C++中Ship的典型用法代码示例。如果您正苦于以下问题:C++ Ship类的具体用法?C++ Ship怎么用?C++ Ship使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Ship类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: UpdateGame

bool UpdateGame(void)
{
	Matrix2 orientation(gameShip.m_orientation);

	Vector2 gravity(0.0f,-0.004f);

	//gameShip.AddBodyForce(gravity);

	float k = 0.001f;

	if(debugSpring1)
	{
		Vector2 force = gameSpring1 - (gameShip.m_position + orientation * gameAnchor1);
		gameShip.AddBodyForce(force * k,gameShip.m_position + orientation * gameAnchor1);
	}
	
	if(debugSpring2)
	{
		Vector2 force = gameSpring2 - (gameShip.m_position + orientation * gameAnchor2);
		gameShip.AddBodyForce(force * k,gameShip.m_position + orientation * gameAnchor2);
	}

	if(HIWORD(GetAsyncKeyState(VK_LEFT)))
	{
		gameShip.m_rearEngineOrientation += GetElapsedTime() / 50.0f;
		gameShip.m_frontEngineOrientation += GetElapsedTime() / 50.0f;
	}

	if(HIWORD(GetAsyncKeyState(VK_RIGHT)))
	{
		gameShip.m_rearEngineOrientation -= GetElapsedTime() / 50.0f;
		gameShip.m_frontEngineOrientation -= GetElapsedTime() / 50.0f;
	}

	if(HIWORD(GetAsyncKeyState('B')))
	{
		gameShip.m_mainEngineOrientation += GetElapsedTime() / 50.0f;
	}

	if(HIWORD(GetAsyncKeyState('N')))
	{
		gameShip.m_mainEngineOrientation -= GetElapsedTime() / 50.0f;
	}

	if(HIWORD(GetAsyncKeyState(VK_UP)))
	{
		Matrix2 rotation(gameShip.m_frontEngineOrientation + gameShip.m_orientation);
		gameShip.AddBodyForce(rotation * Vector2(0.0f,0.002f),gameShip.m_position + orientation * gameShip.m_frontEnginePosition);
		gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_frontEnginePosition);
	}

	if(HIWORD(GetAsyncKeyState(VK_SPACE)))
	{
		Matrix2 rotation(gameShip.m_mainEngineOrientation + gameShip.m_orientation);
		gameShip.AddBodyForce(rotation * Vector2(0.0f,0.004f),gameShip.m_position + orientation * gameShip.m_mainEnginePosition);
		gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_mainEnginePosition);
		gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_mainEnginePosition);
	}

	if(HIWORD(GetAsyncKeyState(VK_UP)))
	{
		Matrix2 rotation(gameShip.m_rearEngineOrientation + gameShip.m_orientation);
		gameShip.AddBodyForce(rotation * Vector2(0.0f,0.001f),gameShip.m_position + orientation * gameShip.m_rearEnginePosition);
		gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_rearEnginePosition);
	}
	
	gameShip.UpdateBody();
	gameEmitter.UpdateParticles();

	for(unsigned long i = 0; i < gameMissles.GetSize(); ++i)
	{
		Matrix2 orientation(gameMissles[i]->m_orientation);

		gameMissles[i]->AddBodyForce(gravity);

		Vector2 target = Matrix2(-gameMissles[i]->m_orientation) * (gameMissles[i]->m_target - gameMissles[i]->m_position);

		bool left = false,right = false;

		if(gameMissles[i]->m_life > 50.0f)
		{
			if(target.x > -0.1f && target.x < 0.1f && target.y > 0)
				left = right = true;
			else if(target.x < 0)
				right = true;
			else
				left = true;
		}
		
		if(left)
		{
			gameMissles[i]->AddBodyForce(orientation * Vector2(0.0f,0.008f),gameMissles[i]->m_position + orientation * gameMissles[i]->m_engines[0]);
			gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[0]);
			gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[0]);
		}

		if(right)
		{
			gameMissles[i]->AddBodyForce(orientation * Vector2(0.0f,0.008f),gameMissles[i]->m_position + orientation * gameMissles[i]->m_engines[1]);
			gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[1]);
//.........这里部分代码省略.........
开发者ID:m1h4,项目名称:Xetrix,代码行数:101,代码来源:Game.cpp

示例2: strcpy_s

bool
NetGameClient::DoJoinBacklog(NetJoinAnnounce* join_ann)
{
	bool finished = false;

	if (!join_ann)
	return finished;

	Sim* sim = Sim::GetSim();
	if (!sim)
	return finished;

	DWORD nid       = join_ann->GetNetID();
	DWORD oid       = join_ann->GetObjID();
	Text  name      = join_ann->GetName();
	Text  elem_name = join_ann->GetElement();
	Text  region    = join_ann->GetRegion();
	Point loc       = join_ann->GetLocation();
	Point velocity  = join_ann->GetVelocity();
	int   index     = join_ann->GetIndex();
	int   shld_lvl  = join_ann->GetShield();
	Ship* ship      = 0;
	char  ship_name[128];

	strcpy_s(ship_name, Game::GetText("NetGameClient.no-ship").data());

	if (nid && oid) {
		NetPlayer* remote_player = FindPlayerByObjID(oid);
		if (remote_player) {
			remote_player->SetName(name);
			remote_player->SetObjID(oid);

			if (index > 0)
			sprintf_s(ship_name, "%s %d", elem_name.data(), index);
			else
			sprintf_s(ship_name, "%s", elem_name.data());
		}
		else {
			Element* element = sim->FindElement(elem_name);

			if (element) {
				ship = element->GetShip(index);
			}

			if (ship) {
				strcpy_s(ship_name, ship->Name());

				SimRegion* rgn = ship->GetRegion();
				if (rgn && region != rgn->Name()) {
					SimRegion* dst = sim->FindRegion(region);
					if (dst) dst->InsertObject(ship);
				}

				ship->MoveTo(loc);
				ship->SetVelocity(velocity);

				Shield* shield = ship->GetShield();
				if (shield)
				shield->SetNetShieldLevel(shld_lvl);

				NetPlayer* remote_player = new(__FILE__,__LINE__) NetPlayer(nid);
				remote_player->SetName(name);
				remote_player->SetObjID(oid);
				remote_player->SetShip(ship);

				players.append(remote_player);
				finished = true;

				if (name == "Server A.I. Ship") {
					Print("NetGameClient::DoJoinBacklog() Remote Player '%s' has joined as '%s' with ID %d\n", name.data(), ship_name, oid);
				}
				else {
					HUDView::Message(Game::GetText("NetGameClient.remote-join").data(), name.data(), ship_name);
				}
			}
		}
	}

	return finished;
}
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:80,代码来源:NetGameClient.cpp

示例3: new

void
NetGameClient::DoElemCreate(NetMsg* msg)
{
	if (!msg) return;

	NetElemCreate elem_create;
	elem_create.Unpack(msg->Data());

	const char* elem_name = elem_create.GetName().data();

	::Print("NetGameClient::DoElemCreate name: %s iff: %d type %s\n",
	elem_name,
	elem_create.GetIFF(),
	Mission::RoleName(elem_create.GetType()));

	Sim*     sim   = Sim::GetSim();
	Element* elem  = sim->FindElement(elem_name);
	if (elem) {
		::Print("  element '%' already exists - ignored\n", elem_name);
		return;
	}

	elem = sim->CreateElement(elem_name,
	elem_create.GetIFF(),
	elem_create.GetType());

	int*     load     = elem_create.GetLoadout();
	int*     slots    = elem_create.GetSlots();
	int      squadron = elem_create.GetSquadron();
	int      code     = elem_create.GetObjCode();
	Text     target   = elem_create.GetObjective();
	bool     alert    = elem_create.GetAlert();
	bool     active   = elem_create.GetInFlight();

	elem->SetIntelLevel(elem_create.GetIntel());
	elem->SetLoadout(load);

	if (code > Instruction::RTB || target.length() > 0) {
		Instruction* obj  = new(__FILE__,__LINE__) Instruction(code, target);
		elem->AddObjective(obj);
	}

	Ship* carrier = sim->FindShip(elem_create.GetCarrier());
	if (carrier) {
		elem->SetCarrier(carrier);

		Hangar* hangar = carrier->GetHangar();
		if (hangar) {
			Text squadron_name = hangar->SquadronName(squadron);
			elem->SetSquadron(squadron_name);

			if (active) {
				for (int i = 0; i < 4; i++) {
					int slot = slots[i];
					if (slot > -1) {
						hangar->GotoActiveFlight(squadron, slot, elem, load);
					}
				}
			}

			else {
				FlightDeck* deck   = 0;
				int         queue  = 1000;

				for (int i = 0; i < carrier->NumFlightDecks(); i++) {
					FlightDeck* d = carrier->GetFlightDeck(i);

					if (d && d->IsLaunchDeck()) {
						int dq = hangar->PreflightQueue(d);

						if (dq < queue) {
							queue = dq;
							deck  = d;
						}
					}
				}

				for (int i = 0; i < 4; i++) {
					int slot = slots[i];
					if (slot > -1) {
						hangar->GotoAlert(squadron, slot, deck, elem, load, !alert);
					}
				}
			}
		}
	}
}
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:87,代码来源:NetGameClient.cpp

示例4: l_ship_get_invulnerable

/*
 * Method: GetInvulnerable
 *
 * Find out whether a ship can take damage or not.
 *
 * > is_invulnerable = ship:GetInvulnerable()
 *
 * Return:
 *
 *   is_invulnerable - boolean; true if the ship is invulnerable to damage
 *
 * Availability:
 *
 *  November 2013
 *
 * Status:
 *
 *  experimental
 */
static int l_ship_get_invulnerable(lua_State *l)
{
	Ship *s = LuaObject<Ship>::CheckFromLua(1);
	lua_pushboolean(l, s->IsInvulnerable());
	return 1;
}
开发者ID:AmesianX,项目名称:pioneer,代码行数:25,代码来源:LuaShip.cpp

示例5: InBlastRadius

// Check if the given ship is within this projectile's blast radius. (The
// projectile will not explode unless it is also within the trigger radius.)
bool Projectile::InBlastRadius(const Ship &ship, int step) const
{
	const Mask &mask = ship.GetSprite().GetMask(step);
	return mask.WithinRange(position - ship.Position(), ship.Facing(), weapon->BlastRadius());
}
开发者ID:Phezzan,项目名称:endless-sky,代码行数:7,代码来源:Projectile.cpp

示例6: defaultColor

void MapPanel::DrawTravelPlan() const
{
	Color defaultColor(.5, .4, 0., 0.);
	Color outOfFlagshipFuelRangeColor(.55, .1, .0, 0.);
	Color withinFleetFuelRangeColor(.2, .5, .0, 0.);
	Color wormholeColor(0.5, 0.2, 0.9, 1.);
	
	Ship *ship = player.Flagship();
	bool hasHyper = ship ? ship->Attributes().Get("hyperdrive") : false;
	bool hasJump = ship ? ship->Attributes().Get("jump drive") : false;
	
	// Find out how much fuel your ship and your escorts use per jump.
	double flagshipCapacity = 0.;
	if(ship)
		flagshipCapacity = ship->Attributes().Get("fuel capacity") * ship->Fuel();
	double flagshipJumpFuel = 0.;
	if(ship)
		flagshipJumpFuel = hasHyper ? ship->Attributes().Get("scram drive") ? 150. : 100. : 200.;
	double escortCapacity = 0.;
	double escortJumpFuel = 1.;
	bool escortHasJump = false;
	// Skip your flagship, parked ships, and fighters.
	for(const shared_ptr<Ship> &it : player.Ships())
		if(it.get() != ship && !it->IsParked() && !it->CanBeCarried())
		{
			double capacity = it->Attributes().Get("fuel capacity") * it->Fuel();
			double jumpFuel = it->Attributes().Get("hyperdrive") ?
				it->Attributes().Get("scram drive") ? 150. : 100. : 200.;
			if(escortJumpFuel < 100. || capacity / jumpFuel < escortCapacity / escortJumpFuel)
			{
				escortCapacity = capacity;
				escortJumpFuel = jumpFuel;
				escortHasJump = it->Attributes().Get("jump drive");
			}
		}
	
	// Draw your current travel plan.
	if(!playerSystem)
		return;
	const System *previous = playerSystem;
	for(int i = player.TravelPlan().size() - 1; i >= 0; --i)
	{
		const System *next = player.TravelPlan()[i];
		
		// Figure out what kind of jump this is, and check if the player is able
		// to make jumps of that kind.
		bool isHyper = 
			(find(previous->Links().begin(), previous->Links().end(), next)
				!= previous->Links().end());
		bool isJump = isHyper ||
			(find(previous->Neighbors().begin(), previous->Neighbors().end(), next)
				!= previous->Neighbors().end());
		bool isWormhole = false;
		if(!((isHyper && hasHyper) || (isJump && hasJump)))
		{
			for(const StellarObject &object : previous->Objects())
				isWormhole |= (object.GetPlanet() && object.GetPlanet()->WormholeDestination(previous) == next);
			if(!isWormhole)
				break;
		}
		
		Point from = Zoom() * (next->Position() + center);
		Point to = Zoom() * (previous->Position() + center);
		Point unit = (from - to).Unit() * 7.;
		from -= unit;
		to += unit;
		
		if(isWormhole)
		{
			// Wormholes cost no fuel to travel through.
		}
		else if(!isHyper)
		{
			if(!escortHasJump)
				escortCapacity = 0.;
			flagshipCapacity -= 200.;
			escortCapacity -= 200.;
		}
		else
		{
			flagshipCapacity -= flagshipJumpFuel;
			escortCapacity -= escortJumpFuel;
		}
		
		Color drawColor = outOfFlagshipFuelRangeColor;
		if(isWormhole)
			drawColor = wormholeColor;
		else if(flagshipCapacity >= 0. && escortCapacity >= 0.)
			drawColor = withinFleetFuelRangeColor;
		else if(flagshipCapacity >= 0. || escortCapacity >= 0.)
			drawColor = defaultColor;
        
		LineShader::Draw(from, to, 3., drawColor);
		
		previous = next;
	}
}
开发者ID:pootthedestroyer,项目名称:endless-sky,代码行数:97,代码来源:MapPanel.cpp

示例7: l_ship_get_skin

static int l_ship_get_skin(lua_State *l)
{
	Ship *s = LuaObject<Ship>::CheckFromLua(1);
	LuaObject<SceneGraph::ModelSkin>::PushToLua(s->GetSkin());
	return 1;
}
开发者ID:AmesianX,项目名称:pioneer,代码行数:6,代码来源:LuaShip.cpp

示例8: CreateMissile


//.........这里部分代码省略.........
		if (hge_->Input_GetKeyState(HGEK_UP))
		{
			ships_.at(0)->Accelerate(DEFAULT_ACCELERATION, timedelta);
		}

		if (hge_->Input_GetKeyState(HGEK_DOWN))
		{
			ships_.at(0)->Accelerate(-DEFAULT_ACCELERATION, timedelta);
		}

		// Shooting
		if (hge_->Input_GetKeyState(HGEK_1))
		{
			if (missileShootTimer >= S_MISSILE_SHOOT_INTERVAL)
			{
				Shoot(Projectile::PROJ_SEEKING_MISSLE);
			}
		}
		if (hge_->Input_GetKeyState(HGEK_2))
		{
			if (bulletShootTimer >= S_BULLET_SHOOT_INTERVAL)
			{
				Shoot(Projectile::PROJ_BULLET);
			}
		}

		if (hge_->Input_GetKeyState(HGEK_ESCAPE))
		{
			return true;
		}
	}

	// Update all ships
	for (ShipList::iterator ship = ships_.begin();
	ship != ships_.end(); ship++)
	{
		(*ship)->Update(timedelta);

		//collisions
		/*if ((*ship) == ships_.at(0))
			checkCollisions((*ship));*/
	}

	// Lab 13 Task 5 : Updating the missile
	/*if (mymissile)
	{
		if (mymissile->Update(ships_, timedelta))
		{
			//havecollision
			delete mymissile;
			mymissile = 0;
		}
	}*/

	// Lab 13 Task 13 : Update network missiles
	/*for (MissileList::iterator missile = missiles_.begin(); missile != missiles_.end(); missile++)
	{
		if ((*missile)->Update(ships_, timedelta))
		{
			//havecollision
			delete*missile;
			missiles_.erase(missile);
			break;
		}
	}*/
开发者ID:NothingMuch123,项目名称:Multiplayer-Assignment-2,代码行数:66,代码来源:Application.cpp

示例9: float

void ScannerWidget::Update()
{
	m_contacts.clear();

	if (Pi::player->m_equipment.Get(Equip::SLOT_SCANNER) != Equip::SCANNER) {
		m_mode = SCANNER_MODE_AUTO;
		m_currentRange = m_manualRange = m_targetRange = SCANNER_RANGE_MIN;
		return;
	}

	enum { RANGE_MAX, RANGE_FAR_OTHER, RANGE_NAV, RANGE_FAR_SHIP, RANGE_COMBAT } range_type = RANGE_MAX;
	float combat_dist = 0, far_ship_dist = 0, nav_dist = 0, far_other_dist = 0;

	// collect the bodies to be displayed, and if AUTO, distances
	for (Space::bodiesIter_t i = Space::bodies.begin(); i != Space::bodies.end(); ++i) {
		if ((*i) == Pi::player) continue;

		float dist = float((*i)->GetPositionRelTo(Pi::player).Length());
		if (dist > SCANNER_RANGE_MAX) continue;

		Contact c;
		c.type = (*i)->GetType();
		c.pos = (*i)->GetPositionRelTo(Pi::player);
		c.isSpecial = false;

		switch ((*i)->GetType()) {

			case Object::MISSILE:
				// player's own missiles are ignored for range calc but still shown
				if (static_cast<Missile*>(*i)->GetOwner() == Pi::player) {
					c.isSpecial = true;
					break;
				}

				// fall through

			case Object::SHIP: {
				Ship *s = static_cast<Ship*>(*i);
				if (s->GetFlightState() != Ship::FLYING && s->GetFlightState() != Ship::LANDED)
					continue;

				if (m_mode == SCANNER_MODE_AUTO && range_type != RANGE_COMBAT) {
					if ((*i) == Pi::player->GetCombatTarget()) {
						c.isSpecial = true;
						combat_dist = dist;
						range_type = RANGE_COMBAT;
					}
					else if (dist > far_ship_dist) {
						far_ship_dist = dist;
						range_type = RANGE_FAR_SHIP;
					}
				}
				break;
			}

			case Object::SPACESTATION:
			case Object::CARGOBODY:
			case Object::HYPERSPACECLOUD:

				// XXX could maybe add orbital stations
				if (m_mode == SCANNER_MODE_AUTO && range_type != RANGE_NAV && range_type != RANGE_COMBAT) {
					if ((*i) == Pi::player->GetNavTarget()) {
						c.isSpecial = true;
						nav_dist = dist;
						range_type = RANGE_NAV;
					}
					else if (dist > far_other_dist) {
						far_other_dist = dist;
						range_type = RANGE_FAR_OTHER;
					}
				}
				break;

			default:
				continue;
		}

		m_contacts.push_back(c);
	}

	if (KeyBindings::increaseScanRange.IsActive()) {
		if (m_mode == SCANNER_MODE_AUTO) {
			m_manualRange = m_targetRange;
			m_mode = SCANNER_MODE_MANUAL;
		}
		else
			m_manualRange = m_currentRange;
		m_manualRange = Clamp(m_manualRange * 1.05f, SCANNER_RANGE_MIN, SCANNER_RANGE_MAX);
	}
	else if (KeyBindings::decreaseScanRange.IsActive() && m_manualRange > SCANNER_RANGE_MIN) {
		if (m_mode == SCANNER_MODE_AUTO) {
			m_manualRange = m_targetRange;
			m_mode = SCANNER_MODE_MANUAL;
		}
		else
			m_manualRange = m_currentRange;
		m_manualRange = Clamp(m_manualRange * 0.95f, SCANNER_RANGE_MIN, SCANNER_RANGE_MAX);
	}

	// range priority is combat target > ship/missile > nav target > other
//.........这里部分代码省略.........
开发者ID:Sunsetjoy,项目名称:pioneer,代码行数:101,代码来源:ShipCpanelMultiFuncDisplays.cpp

示例10: EnterSystem

void Engine::CalculateStep()
{
	FrameTimer loadTimer;
	
	// Clear the list of objects to draw.
	draw[calcTickTock].Clear(step);
	radar[calcTickTock].Clear();
	
	if(!player.GetSystem())
		return;
	
	// Now, all the ships must decide what they are doing next.
	ai.Step(ships, player);
	const Ship *flagship = player.Flagship();
	bool wasHyperspacing = (flagship && flagship->IsEnteringHyperspace());
	
	// Now, move all the ships. We must finish moving all of them before any of
	// them fire, or their turrets will be targeting where a given ship was
	// instead of where it is now. This is also where ships get deleted, and
	// where they may create explosions if they are dying.
	for(auto it = ships.begin(); it != ships.end(); )
	{
		int hyperspaceType = (*it)->HyperspaceType();
		bool wasHere = (flagship && (*it)->GetSystem() == flagship->GetSystem());
		bool wasHyperspacing = (*it)->IsHyperspacing();
		// Give the ship the list of effects so that it can draw explosions,
		// ion sparks, jump drive flashes, etc.
		if(!(*it)->Move(effects, flotsam))
		{
			// If Move() returns false, it means the ship should be removed from
			// play. That may be because it was destroyed, because it is an
			// ordinary ship that has been out of system for long enough to be
			// "forgotten," or because it is a fighter that just docked with its
			// mothership. Report it destroyed if that's really what happened:
			if((*it)->IsDestroyed())
				eventQueue.emplace_back(nullptr, *it, ShipEvent::DESTROY);
			it = ships.erase(it);
		}
		else
		{
			if(&**it != flagship)
			{
				// Did this ship just begin hyperspacing?
				if(wasHere && !wasHyperspacing && (*it)->IsHyperspacing())
					Audio::Play(
						Audio::Get(hyperspaceType >= 200 ? "jump out" : "hyperdrive out"),
						(*it)->Position());
				
				// Did this ship just jump into the player's system?
				if(!wasHere && flagship && (*it)->GetSystem() == flagship->GetSystem())
					Audio::Play(
						Audio::Get(hyperspaceType >= 200 ? "jump in" : "hyperdrive in"),
						(*it)->Position());
			}
			
			// Boarding:
			bool autoPlunder = !(*it)->GetGovernment()->IsPlayer();
			shared_ptr<Ship> victim = (*it)->Board(autoPlunder);
			if(victim)
				eventQueue.emplace_back(*it, victim,
					(*it)->GetGovernment()->IsEnemy(victim->GetGovernment()) ?
						ShipEvent::BOARD : ShipEvent::ASSIST);
			++it;
		}
	}
	
	if(!wasHyperspacing && flagship && flagship->IsEnteringHyperspace())
		Audio::Play(Audio::Get(flagship->HyperspaceType() >= 200 ? "jump drive" : "hyperdrive"));
	
	if(flagship && player.GetSystem() != flagship->GetSystem())
	{
		// Wormhole travel:
		if(!wasHyperspacing)
			for(const auto &it : player.GetSystem()->Objects())
				if(it.GetPlanet() && it.GetPlanet()->IsWormhole() &&
						it.GetPlanet()->WormholeDestination(player.GetSystem()) == flagship->GetSystem())
					player.Visit(it.GetPlanet());
		
		doFlash = Preferences::Has("Show hyperspace flash");
		player.SetSystem(flagship->GetSystem());
		EnterSystem();
	}
	
	// Draw the planets.
	Point newCenter = center;
	Point newCenterVelocity;
	if(flagship)
	{
		newCenter = flagship->Position();
		newCenterVelocity = flagship->Velocity();
	}
	else
		doClick = false;
	draw[calcTickTock].SetCenter(newCenter, newCenterVelocity);
	radar[calcTickTock].SetCenter(newCenter);
	
	for(const StellarObject &object : player.GetSystem()->Objects())
		if(object.HasSprite())
		{
			// Don't apply motion blur to very large planets and stars.
//.........这里部分代码省略.........
开发者ID:EndlessBureaucracy,项目名称:endless-bureaucracy,代码行数:101,代码来源:Engine.cpp

示例11: sprite

EscortDisplay::Icon::Icon(const Ship &ship, bool isHere)
	: sprite(ship.GetSprite().GetSprite()),
	isHere(isHere && !ship.IsDisabled()),
	isReadyToJump(ship.CheckHyperspace()),
	stackSize(1),
	cost(ship.Cost()),
	system((!isHere && ship.GetSystem()) ? ship.GetSystem()->Name() : ""),
	low{ship.Shields(), ship.Hull(), ship.Energy(), ship.Heat(), ship.Fuel()},
	high(low)
{
}
开发者ID:haroldmodesto,项目名称:endless-sky,代码行数:11,代码来源:EscortDisplay.cpp

示例12: sprite

void Engine::AddSprites(const Ship &ship)
{
	bool hasFighters = ship.PositionFighters();
	double cloak = ship.Cloaking();
	bool drawCloaked = (cloak && ship.GetGovernment()->IsPlayer());
	
	if(ship.IsThrusting())
		for(const Point &point : ship.EnginePoints())
		{
			Point pos = ship.Facing().Rotate(point) * ship.Zoom() + ship.Position();
			// If multiple engines with the same flare are installed, draw up to
			// three copies of the flare sprite.
			for(const auto &it : ship.Attributes().FlareSprites())
				for(int i = 0; i < it.second && i < 3; ++i)
				{
					Body sprite(it.first, pos, ship.Velocity(), ship.Facing());
					draw[calcTickTock].Add(sprite, cloak);
				}
		}
	
	if(hasFighters)
		for(const Ship::Bay &bay : ship.Bays())
			if(bay.side == Ship::Bay::UNDER && bay.ship)
			{
				if(drawCloaked)
					draw[calcTickTock].AddSwizzled(*bay.ship, 7);
				draw[calcTickTock].Add(*bay.ship, cloak);
			}
	
	if(drawCloaked)
		draw[calcTickTock].AddSwizzled(ship, 7);
	draw[calcTickTock].Add(ship, cloak);

	if(hasFighters)
		for(const Ship::Bay &bay : ship.Bays())
			if(bay.side == Ship::Bay::OVER && bay.ship)
			{
				if(drawCloaked)
					draw[calcTickTock].AddSwizzled(*bay.ship, 7);
				draw[calcTickTock].Add(*bay.ship, cloak);
			}
}
开发者ID:EndlessBureaucracy,项目名称:endless-bureaucracy,代码行数:42,代码来源:Engine.cpp

示例13: PiVerify

bool SpaceStation::OnCollision(Object *b, Uint32 flags, double relVel)
{
	if ((flags & 0x10) && (b->IsType(Object::SHIP))) {
		Ship *s = static_cast<Ship*>(b);

		int port = -1;
		for (Uint32 i=0; i<m_shipDocking.size(); i++) {
			if (m_shipDocking[i].ship == s) { port = i; break; }
		}
		if (port == -1) return false;					// no permission
		if (IsPortLocked(port)) {
			return false;
		}
		if (m_shipDocking[port].stage != 1) return false;	// already docking?

		SpaceStationType::positionOrient_t dport;
		// why stage 2? Because stage 1 is permission to dock
		// granted, stage 2 is start of docking animation.
		PiVerify(m_type->GetDockAnimPositionOrient(port, 2, 0.0, vector3d(0.0), dport, s));

		// must be oriented sensibly and have wheels down
		if (IsGroundStation()) {
			vector3d dockingNormal = GetOrient()*dport.yaxis;
			const double dot = s->GetOrient().VectorY().Dot(dockingNormal);
			if ((dot < 0.99) || (s->GetWheelState() < 1.0)) return false;	// <0.99 harsh?
			if (s->GetVelocity().Length() > MAX_LANDING_SPEED) return false;
		}

		// if there is more docking port anim to do, don't set docked yet
		if (m_type->NumDockingStages() >= 2) {
			shipDocking_t &sd = m_shipDocking[port];
			sd.ship = s;
			sd.stage = 2;
			sd.stagePos = 0;
			sd.fromPos = (s->GetPosition() - GetPosition()) * GetOrient();	// station space
			sd.fromRot = Quaterniond::FromMatrix3x3(GetOrient().Transpose() * s->GetOrient());
			LockPort(port, true);

			s->SetFlightState(Ship::DOCKING);
			s->SetVelocity(vector3d(0.0));
			s->SetAngVelocity(vector3d(0.0));
			s->ClearThrusterState();
		} else {
			s->SetDockedWith(this, port);				// bounces back to SS::SetDocked()
			LuaEvent::Queue("onShipDocked", s, this);
		}
		return false;
	} else {
		return true;
	}
}
开发者ID:walterar,项目名称:pioneer-sp,代码行数:51,代码来源:SpaceStation.cpp

示例14: DrawGame

bool DrawGame(void)
{
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	//glTranslatef(0.0f,0.0f,-8.0f);
	gluLookAt(0.0f,0.0f,18.0,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);

	glPushAttrib(GL_CURRENT_BIT);

	glBegin(GL_LINES);
		Matrix2 orientation(gameShip.m_orientation);

#ifdef _DEBUG
		if(debugDraw)
		{
			glColor3f(1.0f,0.0f,0.0f);

			glVertex2f(0.0f,0.0f);
			glVertex2f(1.0f,0.0f);

			glColor3f(0.0f,1.0f,0.0f);

			glVertex2f(0.0f,0.0f);
			glVertex2f(0.0f,1.0f);
		}
#endif

		glColor3f(0.0f,0.0f,1.0f);

		if(debugSpring1)
		{
			glVertex2fv(gameSpring1);
			glVertex2fv(gameShip.m_position + orientation * gameAnchor1);
		}

		if(debugSpring2)
		{
			glVertex2fv(gameSpring2);
			glVertex2fv(gameShip.m_position + orientation * gameAnchor2);
		}

		for(unsigned long i = 0; i < gameMissles.GetSize(); ++i)
		{
			if(gameMissles[i]->m_spring)
			{
				glVertex2fv(*gameMissles[i]->m_spring);
				glVertex2fv(gameMissles[i]->m_position);
			}
		}
	glEnd();

	glPopAttrib();

	gameShip.DrawShip();
	gameEmitter.DrawParticles();

	for(unsigned long i = 0; i < gameMissles.GetSize(); ++i)
		gameMissles[i]->DrawMissle();

	return true;
}
开发者ID:m1h4,项目名称:Xetrix,代码行数:62,代码来源:Game.cpp

示例15: Color

void BasicApp::draw()
{

	// this pair of lines is the standard way to clear the screen in OpenGL
	gl::clear( Color( 0.0f, 0.0f, 0.0f ) );
	gl::setMatricesWindow( getWindowSize() );

	if(game_state == Game_Demo)
	{
		gl::enableAlphaBlending( true );
		for (list<Asteroid>::iterator itr = asteroids.begin(); itr!=asteroids.end(); itr++)
		{
			if(itr->m_bHit)
			{

			}
			itr->Draw();
		}

		Font font  = Font( "Times New Roman", 50 );
		gl::drawString("Atari Asteroids Clone" , Vec2f(app::getWindowWidth()/4,app::getWindowHeight()/4),cinder::ColorA(1,1,1,1), font);
		gl::drawString("Presse SpaceBar to Play" , Vec2f(app::getWindowWidth()/4,app::getWindowHeight()/2 + 100),cinder::ColorA(1,1,1,1), font);

	}
	else if(game_state == GAME_Play)
	{

		for (list<Asteroid>::iterator itr = asteroids.begin(); itr!=asteroids.end(); itr++)
		{
			if(itr->m_bHit)
			{

			}
			itr->Draw();

		}
		enemy.Draw();
		particleManager.Move();
		particleManager.Draw();
		particleLineManager.Update();
		particleLineManager.Draw();
		currentShip.Draw();

		for (std::vector<Ship>::iterator itrShip = ships.begin(); itrShip!=ships.end();itrShip++)
		{
			if(itrShip->m_state== Ship::Ship_Alive)
			{
				itrShip->Draw();
			}
		}
		stringstream scoreString;
		scoreString<< score;
		gl::drawString("   " + scoreString.str(), Vec2f(10,10),cinder::ColorA(1,1,1,1), mFont);
	}

	else if (game_state == GAME_End)
	{

		gl::drawString("Game Over", Vec2f(getWindowWidth()/2,getWindowHeight()/2),cinder::ColorA(1,1,1,1), mFont);
	}
}
开发者ID:AndreAhmed,项目名称:asteroids-atari-clone,代码行数:61,代码来源:basicApp.cpp


注:本文中的Ship类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。