コード例 #1
0
ファイル: projectile.cpp プロジェクト: eoi/Epiar
/**\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() );
	}
}
コード例 #2
0
ファイル: hud.cpp プロジェクト: moses7/Epiar
void Radar::Draw( SpriteManager &sprites ) {
	short int radar_mid_x = RADAR_MIDDLE_X + Video::GetWidth() - 129;
	short int radar_mid_y = RADAR_MIDDLE_Y + 5;
	int radarSize;

	const list<Sprite*>& spriteList = sprites.GetSprites();
	for( list<Sprite*>::const_iterator iter = spriteList.begin(); iter != spriteList.end(); iter++)
	{
		Coordinate blip( -(RADAR_HEIGHT / 2.0), (RADAR_WIDTH / 2.0), (RADAR_HEIGHT / 2.0), -(RADAR_WIDTH / 2.0) );
		Sprite *sprite = *iter;
		
		if( sprite->GetDrawOrder() == DRAW_ORDER_PLAYER ) continue;
		
		// Calculate the blip coordinate for this sprite
		Coordinate wpos = sprite->GetWorldPosition();
		WorldToBlip( wpos, blip );
		
		if( blip.ViolatesBoundary() == false ) {
			/* blip is on the radar */
			
			/* Convert to screen coords */
			blip.SetX( blip.GetX() + radar_mid_x );
			blip.SetY( blip.GetY() + radar_mid_y );

			radarSize = int((sprite->GetRadarSize() / float(visibility)) * (RADAR_HEIGHT/4.0));
			
			
			Video::DrawCircle(
				blip,
				(radarSize>=1) ?radarSize: 1,
				1,
				sprite->GetRadarColor() );
		}
	}
}
コード例 #3
0
ファイル: hud.cpp プロジェクト: cthielen/epiar
/**\brief Draws the radar.
 */
void Radar::Draw( Camera* camera, SpriteManager* sprites ) {
	short int radar_mid_x = RADAR_MIDDLE_X + Video::GetWidth() - 129;
	short int radar_mid_y = RADAR_MIDDLE_Y + 5;
	int radarSize;
	Coordinate focus = camera->GetFocusCoordinate();

	/*if(largeMode) {
		if( visibility <= QUADRANTSIZE )
		{
			Map* map = (Map*)UI::Search( "/Map/" );
			assert(map); // large mode should only be on when there is a map.
			if(map) {
				map->SetCenter( focus );
				map->SetScale( 300.0 / (2*visibility) );
			}
		}
		return;
	}*/

	list<Sprite*> *spriteList = sprites->GetSpritesNear(camera->GetFocusCoordinate(), (float)visibility);
	for( list<Sprite*>::const_iterator iter = spriteList->begin(); iter != spriteList->end(); iter++)
	{
		Coordinate blip;
		Sprite *sprite = *iter;

		// Calculate the blip coordinate for this sprite
		Coordinate wpos = sprite->GetWorldPosition();
		WorldToBlip( focus, wpos, blip );

		// Use the OpenGL Crop Rectangle to ensure that the blip is on the radar

		/* Convert to screen coords */
		blip.SetX( blip.GetX() + radar_mid_x );
		blip.SetY( blip.GetY() + radar_mid_y );

		radarSize = int((sprite->GetRadarSize() / float(visibility)) * (RADAR_HEIGHT / 4.0));

		if( radarSize >= 1 ) {
			if(sprite->GetID() == Hud::GetTarget() && Timer::GetTicks() % 1000 < 100)
				Video::DrawCircle( blip, radarSize, 2, WHITE );
			else
				Video::DrawCircle( blip, radarSize, 1, sprite->GetRadarColor() );
		} else {
			if(sprite->GetID() == Hud::GetTarget() && Timer::GetTicks() % 1000 < 100)
				Video::DrawCircle( blip, 1, 2, WHITE );
			else
				Video::DrawPoint( blip, sprite->GetRadarColor() );
		}
	}

	delete spriteList;
}
コード例 #4
0
ファイル: gate.cpp プロジェクト: ebos/Epiar
void Gate::SendToExit(Sprite* ship) {
	Sprite* exit = SpriteManager::Instance()->GetSpriteByID(exitID);
	if(exit==NULL) {
		LogMsg(ERR,"Gate %d cannot send to non-existant exit (%d)",this->GetID(),exitID);
		return;
	}
	float distance = 50.0f;
	float exitAngle = normalizeAngle( exit->GetAngle()+180 );
	// The Ship's Angle and Momentum should make it appear like it is exiting the Gate
	ship->SetWorldPosition( exit->GetWorldPosition() + Coordinate(distance,0).RotateTo( exitAngle ) );
	ship->SetMomentum( ship->GetMomentum().RotateTo( exitAngle ) );
	ship->SetAngle( exitAngle );
}
コード例 #5
0
ファイル: hud.cpp プロジェクト: digital-phoenix/Epiar
/**\brief Draws the target.
 */
void Hud::DrawTarget( void ) {
	Sprite* target = SpriteManager::Instance()->GetSpriteByID( targetID );
	if(target != NULL) {
		int x = target->GetWorldPosition().GetScreenX();
		int y = target->GetWorldPosition().GetScreenY();
		int r = target->GetRadarSize();
		Color c = target->GetRadarColor();

		if( Timer::GetTicks() - timeTargeted < OPTION(Uint32,"options/timing/target-zoom")) {
			r += Video::GetHalfHeight() - Video::GetHalfHeight()*(Timer::GetTicks()-timeTargeted)/OPTION(Uint32,"options/timing/target-zoom");
		}
	
		Video::DrawTarget(x,y,r,r,5,c.r,c.g,c.b);
	}
}
コード例 #6
0
ファイル: spritemanager.cpp プロジェクト: cthielen/epiar
/**\brief Get the min/max planet positions. Useful when generating traffic.
 * \note Returns the values through the pointer arguments.
 */
void SpriteManager::GetBoundaries(float *north, float *south, float *east, float *west)
{
	*north = *south = *east = *west = 0;

	list<Sprite *>::iterator i;

	for( i = spritelist->begin(); i != spritelist->end(); ++i ) {
		Sprite *s = (*i);

		if( s->GetDrawOrder() == DRAW_ORDER_PLANET ) {
			Coordinate c = s->GetWorldPosition();

			if(c.GetY() < *north) *north = c.GetY();
			if(c.GetY() > *south) *south = c.GetY();
			if(c.GetX() < *west) *west = c.GetX();
			if(c.GetX() > *east) *east = c.GetX();
		}
	}
}
コード例 #7
0
ファイル: hud.cpp プロジェクト: digital-phoenix/Epiar
/**\brief Draws the radar.
 */
void Radar::Draw( void ) {
	short int radar_mid_x = RADAR_MIDDLE_X + Video::GetWidth() - 129;
	short int radar_mid_y = RADAR_MIDDLE_Y + 5;
	int radarSize;

	list<Sprite*> *spriteList = SpriteManager::Instance()->GetSpritesNear(Camera::Instance()->GetFocusCoordinate(), (float)visibility);
	for( list<Sprite*>::const_iterator iter = spriteList->begin(); iter != spriteList->end(); iter++)
	{
		Coordinate blip;
		Sprite *sprite = *iter;
		
		//if( sprite->GetDrawOrder() == DRAW_ORDER_PLAYER ) continue;
		
		// Calculate the blip coordinate for this sprite
		Coordinate wpos = sprite->GetWorldPosition();
		WorldToBlip( wpos, blip );
		
		// Use the OpenGL Crop Rectangle to ensure that the blip is on the radar
		
		/* Convert to screen coords */
		blip.SetX( blip.GetX() + radar_mid_x );
		blip.SetY( blip.GetY() + radar_mid_y );
		
		radarSize = int((sprite->GetRadarSize() / float(visibility)) * (RADAR_HEIGHT/4.0));
		
		if( radarSize >= 1 ) {
			if(sprite->GetID() == Hud::GetTarget() && Timer::GetTicks() % 1000 < 100)
				Video::DrawCircle( blip, radarSize, 2, WHITE );
			else
				Video::DrawCircle( blip, radarSize, 1, sprite->GetRadarColor() );
		} else {
			if(sprite->GetID() == Hud::GetTarget() && Timer::GetTicks() % 1000 < 100)
				Video::DrawCircle( blip, 1, 2, WHITE );
			else
				Video::DrawPoint( blip, sprite->GetRadarColor() );
		}
	}
	delete spriteList;
}
コード例 #8
0
ファイル: hud.cpp プロジェクト: akollias/Epiar
/**\brief Draws the radar.
 */
void Radar::Draw( void ) {
	short int radar_mid_x = RADAR_MIDDLE_X + Video::GetWidth() - 129;
	short int radar_mid_y = RADAR_MIDDLE_Y + 5;
	int radarSize;

	list<Sprite*> *spriteList = SpriteManager::Instance()->GetSpritesNear(Camera::Instance()->GetFocusCoordinate(), (float)visibility);
	for( list<Sprite*>::const_iterator iter = spriteList->begin(); iter != spriteList->end(); iter++)
	{
		Coordinate blip;
		Sprite *sprite = *iter;
		
		//if( sprite->GetDrawOrder() == DRAW_ORDER_PLAYER ) continue;
		
		// Calculate the blip coordinate for this sprite
		Coordinate wpos = sprite->GetWorldPosition();
		WorldToBlip( wpos, blip );
		
		if( blip.ViolatesBoundary( -(RADAR_HEIGHT / 2.0), (RADAR_WIDTH / 2.0), (RADAR_HEIGHT / 2.0), -(RADAR_WIDTH / 2.0) ) == false ) {
			/* blip is on the radar */
			
			/* Convert to screen coords */
			blip.SetX( blip.GetX() + radar_mid_x );
			blip.SetY( blip.GetY() + radar_mid_y );

			radarSize = int((sprite->GetRadarSize() / float(visibility)) * (RADAR_HEIGHT/4.0));
			
			
			if( radarSize >= 1 ) {
				Video::DrawCircle( blip, radarSize, 1, sprite->GetRadarColor() );
			} else {
				Video::DrawPoint( blip, sprite->GetRadarColor() );
			}
		}
	}
	delete spriteList;
}