Exemplo n.º 1
0
/**\brief Update function on every frame.
 */
void Ship::Update( lua_State *L ) {
	Sprite::Update( L ); // update momentum and other generic sprite attributes
	
	if( status.isAccelerating == false 
		&& status.isRotatingLeft == false
		&& status.isRotatingRight == false) {
		flareAnimation->Reset();
	}
	flareAnimation->Update();
	Coordinate momentum	= GetMomentum();
	momentum.EnforceMagnitude( shipStats.GetMaxSpeed()*engineBooster );
	// Show the hits taken as part of the radar color
	if(IsDisabled()) SetRadarColor( GREY );
	else SetRadarColor( RED * GetHullIntegrityPct() );
	
	// Ship has taken as much damage as possible...
	// It Explodes!
	if( status.hullDamage >=  (float)shipStats.GetHullStrength() ) {
		SpriteManager *sprites = Simulation_Lua::GetSimulation(L)->GetSpriteManager();
		Camera* camera = Simulation_Lua::GetSimulation(L)->GetCamera();

		// Play explode sound
		if(OPTION(int, "options/sound/explosions")) {
			Sound *explodesnd = Sound::Get("Resources/Audio/Effects/18384__inferno__largex.wav.ogg");
			explodesnd->Play( GetWorldPosition() - camera->GetFocusCoordinate());
		}

		// Create Explosion
		sprites->Add( new Effect( GetWorldPosition(), "Resources/Animations/explosion1.ani", 0) );

		// Remove this Sprite from the SpriteManager
		sprites->Delete( (Sprite*)this );
	}
Exemplo n.º 2
0
/**\brief Update the Projectile
 *
 * Projectiles do all the normal Sprite things like moving.
 * Projectiles check for collisions with nearby Ships, and if they collide,
 * they deal damage to that ship. Note that since each projectile knows which ship fired it and will never collide with them.
 *
 * Projectiles have a life time limit (in milli-seconds).  Each tick they need
 * to check if they've lived to long and need to disappear.
 *
 * Projectiles have the ability to track down a specific target.  This only
 * means that they will turn slightly to head towards their target.
 */
void Projectile::Update( void ) {
	Sprite::Update(); // update momentum and other generic sprite attributes
	SpriteManager *sprites = SpriteManager::Instance();

	// Check for projectile collisions
	Sprite* impact = sprites->GetNearestSprite( (Sprite*)this, 100,DRAW_ORDER_SHIP|DRAW_ORDER_PLAYER );
	if( (impact != NULL) && (impact->GetID() != ownerID) && ((this->GetWorldPosition() - impact->GetWorldPosition()).GetMagnitude() < impact->GetRadarSize() )) {
		((Ship*)impact)->Damage( (weapon->GetPayload())*damageBoost );
		sprites->Delete( (Sprite*)this );
		
		// Create a fire burst where this projectile hit the ship's shields.
		// TODO: This shows how much we need to improve our collision detection.
		Effect* hit = new Effect(this->GetWorldPosition(), "Resources/Animations/shield.ani", 0);
		hit->SetAngle( -this->GetAngle() );
		hit->SetMomentum( impact->GetMomentum() );
		sprites->Add( hit );
	}

	// Expire the projectile after a time period
	if (( Timer::GetTicks() > secondsOfLife + start )) {
		sprites->Delete( (Sprite*)this );
	}

	// Track the target
	Sprite* target = sprites->GetSpriteByID( targetID );
	float tracking = weapon->GetTracking();
	if( target != NULL && tracking > 0.00000001f ) {
		float angleTowards = normalizeAngle( ( target->GetWorldPosition() - this->GetWorldPosition() ).GetAngle() - GetAngle() );
		SetMomentum( GetMomentum().RotateBy( angleTowards*tracking ) );
		SetAngle( GetMomentum().GetAngle() );
	}
}
Exemplo n.º 3
0
bool Simulation::Run( void ) {
	bool quit = false;
	Input inputs;
	int fpsCount = 0; // for FPS calculations
	int fpsTotal= 0; // for FPS calculations
	Uint32 fpsTS = 0; // timestamp of last FPS printing

	// Grab the camera and give it coordinates
	Camera *camera = Camera::Instance();
	camera->Focus(0, 0);

	// Generate a starfield
	Starfield starfield( OPTION(int, "options/simulation/starfield-density") );

	// Create a spritelist
	SpriteManager sprites;

	Player *player = Player::Instance();

	// Set player model based on simulation xml file settings
	player->SetModel( models->GetModel( playerDefaultModel ) );
	sprites.Add( player->GetSprite() );

	// Focus the camera on the sprite
	camera->Focus( player->GetSprite() );

	// Add the planets
	planets->RegisterAll( &sprites );

	// Start the Lua Universe
	Lua::SetSpriteList( &sprites );
	Lua::Load("Resources/Scripts/universe.lua");

	// Start the Lua Scenarios
	Lua::Run("Start()");

	// Ensure correct drawing order
	sprites.Order();
	
	// Create the hud
	Hud::Hud();

	Hud::Alert( "Captain, we don't have the power! Pow = %d", 3 );

	fpsTS = Timer::GetTicks();
	// main game loop
	while( !quit ) {
		quit = inputs.Update();
		
		if( !paused ) {
			Lua::Update();
			// Update cycle
			starfield.Update();
			camera->Update();
			sprites.Update();
			camera->Update();
			Hud::Update();
			UI::Run(); // runs only a few loops
			
			// Keep this last (I think)
			Timer::Update();
		}

		// Erase cycle
		Video::Erase();
		
		// Draw cycle
		starfield.Draw();
		sprites.Draw();
		Hud::Draw( sprites );
		UI::Draw();
		Video::Update();
		
		// Don't kill the CPU (play nice)
		Timer::Delay();
		
		Coordinate playerPos = player->GetWorldPosition();

		// Counting Frames
		fpsCount++;
		fpsTotal++;

		// Update the fps once per second
		if( (Timer::GetTicks() - fpsTS) >1000 ) { 
			Simulation::currentFPS = static_cast<float>(1000.0 *
					((float)fpsCount / (Timer::GetTicks() - fpsTS)));
			fpsTS = Timer::GetTicks();
			fpsCount = 0;
		}
	}

	Log::Message("Average Framerate: %f Frames/Second", 1000.0 *((float)fpsTotal / Timer::GetTicks() ) );
	return true;
}